Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Reference.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Pdf/Element/Null.php';
25 
26 
28 #require_once 'Zend/Pdf/Element.php';
29 
39 {
46  private $_ref;
47 
53  private $_objNum;
54 
60  private $_genNum;
61 
67  private $_context;
68 
69 
80  private $_factory;
81 
91  public function __construct($objNum, $genNum = 0, Zend_Pdf_Element_Reference_Context $context, Zend_Pdf_ElementFactory $factory)
92  {
93  if ( !(is_integer($objNum) && $objNum > 0) ) {
94  #require_once 'Zend/Pdf/Exception.php';
95  throw new Zend_Pdf_Exception('Object number must be positive integer');
96  }
97  if ( !(is_integer($genNum) && $genNum >= 0) ) {
98  #require_once 'Zend/Pdf/Exception.php';
99  throw new Zend_Pdf_Exception('Generation number must be non-negative integer');
100  }
101 
102  $this->_objNum = $objNum;
103  $this->_genNum = $genNum;
104  $this->_ref = null;
105  $this->_context = $context;
106  $this->_factory = $factory;
107  }
108 
114  public function getFactory()
115  {
116  return $this->_factory;
117  }
118 
119 
125  public function getType()
126  {
127  if ($this->_ref === null) {
128  $this->_dereference();
129  }
130 
131  return $this->_ref->getType();
132  }
133 
134 
141  public function toString($factory = null)
142  {
143  if ($factory === null) {
144  $shift = 0;
145  } else {
146  $shift = $factory->getEnumerationShift($this->_factory);
147  }
148 
149  return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
150  }
151 
152 
162  private function _dereference()
163  {
164  if (($obj = $this->_factory->fetchObject($this->_objNum . ' ' . $this->_genNum)) === null) {
165  $obj = $this->_context->getParser()->getObject(
166  $this->_context->getRefTable()->getOffset($this->_objNum . ' ' . $this->_genNum . ' R'),
167  $this->_context
168  );
169  }
170 
171  if ($obj === null ) {
172  $this->_ref = new Zend_Pdf_Element_Null();
173  return;
174  }
175 
176  if ($obj->toString() != $this->_objNum . ' ' . $this->_genNum . ' R') {
177  #require_once 'Zend/Pdf/Exception.php';
178  throw new Zend_Pdf_Exception('Incorrect reference to the object');
179  }
180 
181  $this->_ref = $obj;
182  }
183 
192  public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
193  {
194  if ($this->_ref === null) {
195  $this->_dereference();
196  }
197 
198  // This code duplicates code in Zend_Pdf_Element_Object class,
199  // but allows to avoid unnecessary method call in most cases
200  $id = spl_object_hash($this->_ref);
201  if (isset($processed[$id])) {
202  // Do nothing if object is already processed
203  // return it
204  return $processed[$id];
205  }
206 
207  return $this->_ref->makeClone($factory, $processed, $mode);
208  }
209 
213  public function touch()
214  {
215  if ($this->_ref === null) {
216  $this->_dereference();
217  }
218 
219  $this->_ref->touch();
220  }
221 
227  public function getObject()
228  {
229  if ($this->_ref === null) {
230  $this->_dereference();
231  }
232 
233  return $this->_ref;
234  }
235 
242  public function __get($property)
243  {
244  if ($this->_ref === null) {
245  $this->_dereference();
246  }
247 
248  return $this->_ref->$property;
249  }
250 
257  public function __set($property, $value)
258  {
259  if ($this->_ref === null) {
260  $this->_dereference();
261  }
262 
263  $this->_ref->$property = $value;
264  }
265 
273  public function __call($method, $args)
274  {
275  if ($this->_ref === null) {
276  $this->_dereference();
277  }
278 
279  return call_user_func_array(array($this->_ref, $method), $args);
280  }
281 
285  public function cleanUp()
286  {
287  $this->_ref = null;
288  }
289 
295  public function toPhp()
296  {
297  if ($this->_ref === null) {
298  $this->_dereference();
299  }
300 
301  return $this->_ref->toPhp();
302  }
303 }
__call($method, $args)
Definition: Reference.php:273
$id
Definition: fieldset.phtml:14
makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
Definition: Reference.php:192
__set($property, $value)
Definition: Reference.php:257
__construct($objNum, $genNum=0, Zend_Pdf_Element_Reference_Context $context, Zend_Pdf_ElementFactory $factory)
Definition: Reference.php:91
$value
Definition: gender.phtml:16
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
$method
Definition: info.phtml:13
toString($factory=null)
Definition: Reference.php:141