Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Stream.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Log/Writer/Abstract.php';
25 
27 #require_once 'Zend/Log/Formatter/Simple.php';
28 
38 {
44  protected $_stream = null;
45 
54  public function __construct($streamOrUrl, $mode = null)
55  {
56  // Setting the default
57  if (null === $mode) {
58  $mode = 'a';
59  }
60 
61  if (is_resource($streamOrUrl)) {
62  if (get_resource_type($streamOrUrl) != 'stream') {
63  #require_once 'Zend/Log/Exception.php';
64  throw new Zend_Log_Exception('Resource is not a stream');
65  }
66 
67  if ($mode != 'a') {
68  #require_once 'Zend/Log/Exception.php';
69  throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
70  }
71 
72  $this->_stream = $streamOrUrl;
73  } else {
74  if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) {
75  $streamOrUrl = $streamOrUrl['stream'];
76  }
77 
78  if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
79  #require_once 'Zend/Log/Exception.php';
80  $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
81  throw new Zend_Log_Exception($msg);
82  }
83  }
84 
85  $this->_formatter = new Zend_Log_Formatter_Simple();
86  }
87 
94  static public function factory($config)
95  {
97  $config = array_merge(array(
98  'stream' => null,
99  'mode' => null,
100  ), $config);
101 
102  $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream'];
103 
104  return new self(
105  $streamOrUrl,
106  $config['mode']
107  );
108  }
109 
115  public function shutdown()
116  {
117  if (is_resource($this->_stream)) {
118  fclose($this->_stream);
119  }
120  }
121 
129  protected function _write($event)
130  {
131  $line = $this->_formatter->format($event);
132 
133  if (false === @fwrite($this->_stream, $line)) {
134  #require_once 'Zend/Log/Exception.php';
135  throw new Zend_Log_Exception("Unable to write to stream");
136  }
137  }
138 }
$config
Definition: fraud_order.php:17
__construct($streamOrUrl, $mode=null)
Definition: Stream.php:54
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
static _parseConfig($config)
Definition: Abstract.php:126
static factory($config)
Definition: Stream.php:94