Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions
Zend_Pdf_ElementFactory Class Reference
Inheritance diagram for Zend_Pdf_ElementFactory:
Zend_Pdf_ElementFactory_Interface

Public Member Functions

 __construct ($objCount)
 
 getFactory ()
 
 close ()
 
 resolve ()
 
 getId ()
 
 setObjectCount ($objCount)
 
 getObjectCount ()
 
 attach (Zend_Pdf_ElementFactory_Interface $factory)
 
 calculateShift (Zend_Pdf_ElementFactory_Interface $factory)
 
 cleanEnumerationShiftCache ()
 
 getEnumerationShift (Zend_Pdf_ElementFactory_Interface $factory)
 
 markAsModified (Zend_Pdf_Element_Object $obj)
 
 remove (Zend_Pdf_Element_Object $obj)
 
 newObject (Zend_Pdf_Element $objectValue)
 
 newStreamObject ($streamValue)
 
 listModifiedObjects ($rootFactory=null)
 
 registerObject (Zend_Pdf_Element_Object $obj, $refString)
 
 fetchObject ($refString)
 
 isModified ()
 

Static Public Member Functions

static createFactory ($objCount)
 

Detailed Description

Definition at line 34 of file ElementFactory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $objCount)

Object constructor

Parameters
integer$objCount

Definition at line 111 of file ElementFactory.php.

112  {
113  $this->_objectCount = (int)$objCount;
114  $this->_factoryId = self::$_identity++;
115  $this->_removedObjects = new SplObjectStorage();
116  }

Member Function Documentation

◆ attach()

attach ( Zend_Pdf_ElementFactory_Interface  $factory)

Attach factory to the current;

Parameters
Zend_Pdf_ElementFactory_Interface$factory

Don't attach factory twice. We do not check recusively because of nature of attach operation (Pages are always attached to the Documents, Fonts are always attached to the pages even if pages already use Document level object factory and so on)

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 210 of file ElementFactory.php.

211  {
212  if ( $factory === $this || isset($this->_attachedFactories[$factory->getId()])) {
219  return;
220  }
221 
222  $this->_attachedFactories[$factory->getId()] = $factory;
223  }

◆ calculateShift()

calculateShift ( Zend_Pdf_ElementFactory_Interface  $factory)

Calculate object enumeration shift.

Parameters
Zend_Pdf_ElementFactory_Interface$factory
Returns
integer

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 232 of file ElementFactory.php.

233  {
234  if ($factory === $this) {
235  return 0;
236  }
237 
238  if (isset($this->_shiftCalculationCache[$factory->_factoryId])) {
239  return $this->_shiftCalculationCache[$factory->_factoryId];
240  }
241 
242  $shift = $this->_objectCount - 1;
243 
244  foreach ($this->_attachedFactories as $subFactory) {
245  $subFactoryShift = $subFactory->calculateShift($factory);
246 
247  if ($subFactoryShift != -1) {
248  // context found
249  $this->_shiftCalculationCache[$factory->_factoryId] = $shift + $subFactoryShift;
250  return $shift + $subFactoryShift;
251  } else {
252  $shift += $subFactory->getObjectCount()-1;
253  }
254  }
255 
256  $this->_shiftCalculationCache[$factory->_factoryId] = -1;
257  return -1;
258  }

◆ cleanEnumerationShiftCache()

cleanEnumerationShiftCache ( )

Clean enumeration shift cache. Has to be used after PDF render operation to let followed updates be correct.

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 264 of file ElementFactory.php.

265  {
266  $this->_shiftCalculationCache = array();
267 
268  foreach ($this->_attachedFactories as $attached) {
269  $attached->cleanEnumerationShiftCache();
270  }
271  }

◆ close()

close ( )

Close factory and clean-up resources

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 146 of file ElementFactory.php.

147  {
148  $this->_modifiedObjects = null;
149  $this->_removedObjects = null;
150  $this->_attachedFactories = null;
151 
152  foreach ($this->_registeredObjects as $obj) {
153  $obj->cleanUp();
154  }
155  $this->_registeredObjects = null;
156  }

◆ createFactory()

static createFactory (   $objCount)
static

Factory generator

Parameters
integer$objCount
Returns
Zend_Pdf_ElementFactory_Interface

Definition at line 135 of file ElementFactory.php.

136  {
137  #require_once 'Zend/Pdf/ElementFactory/Proxy.php';
138  return new Zend_Pdf_ElementFactory_Proxy(new Zend_Pdf_ElementFactory($objCount));
139  }

◆ fetchObject()

fetchObject (   $refString)

Fetch object specified by reference

Parameters
string$refString
Returns
Zend_Pdf_Element_Object|null

Definition at line 417 of file ElementFactory.php.

418  {
419  if (!isset($this->_registeredObjects[$refString])) {
420  return null;
421  }
422  return $this->_registeredObjects[$refString];
423  }

◆ getEnumerationShift()

getEnumerationShift ( Zend_Pdf_ElementFactory_Interface  $factory)

Retrive object enumeration shift.

Parameters
Zend_Pdf_ElementFactory_Interface$factory
Returns
integer
Exceptions
Zend_Pdf_Exception

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 280 of file ElementFactory.php.

281  {
282  if (($shift = $this->calculateShift($factory)) == -1) {
283  #require_once 'Zend/Pdf/Exception.php';
284  throw new Zend_Pdf_Exception('Wrong object context');
285  }
286 
287  return $shift;
288  }
calculateShift(Zend_Pdf_ElementFactory_Interface $factory)

◆ getFactory()

getFactory ( )

Get factory

Returns
Zend_Pdf_ElementFactory_Interface

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 124 of file ElementFactory.php.

125  {
126  return $this;
127  }

◆ getId()

getId ( )

Get factory ID

Returns
integer

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 173 of file ElementFactory.php.

174  {
175  return $this->_factoryId;
176  }

◆ getObjectCount()

getObjectCount ( )

Get object counter

Returns
integer

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 193 of file ElementFactory.php.

194  {
195  $count = $this->_objectCount;
196 
197  foreach ($this->_attachedFactories as $attached) {
198  $count += $attached->getObjectCount() - 1; // -1 as "0" object is a special case and shared between factories
199  }
200 
201  return $count;
202  }
$count
Definition: recent.phtml:13

◆ isModified()

isModified ( )

Check if PDF file was modified

Returns
boolean

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 431 of file ElementFactory.php.

432  {
433  if (count($this->_modifiedObjects) != 0) {
434  return true;
435  }
436 
437  foreach ($this->_attachedFactories as $subFactory) {
438  if ($subFactory->isModified()) {
439  return true;
440  }
441  }
442 
443  return false;
444  }

◆ listModifiedObjects()

listModifiedObjects (   $rootFactory = null)

Enumerate modified objects. Returns array of Zend_Pdf_UpdateInfoContainer

Parameters
Zend_Pdf_ElementFactory_Interface$rootFactory
Returns
array

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 365 of file ElementFactory.php.

366  {
367  if ($rootFactory == null) {
368  $rootFactory = $this;
369  $shift = 0;
370  } else {
371  $shift = $rootFactory->getEnumerationShift($this);
372  }
373 
374  ksort($this->_modifiedObjects);
375 
376  $result = array();
377  #require_once 'Zend/Pdf/UpdateInfoContainer.php';
378  foreach ($this->_modifiedObjects as $objNum => $obj) {
379  if ($this->_removedObjects->contains($obj)) {
380  $result[$objNum+$shift] = new Zend_Pdf_UpdateInfoContainer($objNum + $shift,
381  $obj->getGenNum()+1,
382  true);
383  } else {
384  $result[$objNum+$shift] = new Zend_Pdf_UpdateInfoContainer($objNum + $shift,
385  $obj->getGenNum(),
386  false,
387  $obj->dump($rootFactory));
388  }
389  }
390 
391  foreach ($this->_attachedFactories as $factory) {
392  $result += $factory->listModifiedObjects($rootFactory);
393  }
394 
395  return $result;
396  }

◆ markAsModified()

markAsModified ( Zend_Pdf_Element_Object  $obj)

Mark object as modified in context of current factory.

Parameters
Zend_Pdf_Element_Object$obj
Exceptions
Zend_Pdf_Exception

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 296 of file ElementFactory.php.

297  {
298  if ($obj->getFactory() !== $this) {
299  #require_once 'Zend/Pdf/Exception.php';
300  throw new Zend_Pdf_Exception('Object is not generated by this factory');
301  }
302 
303  $this->_modifiedObjects[$obj->getObjNum()] = $obj;
304  }

◆ newObject()

newObject ( Zend_Pdf_Element  $objectValue)

Generate new Zend_Pdf_Element_Object

Todo:
Reusage of the freed object. It's not a support of new feature, but only improvement.
Parameters
Zend_Pdf_Element$objectValue
Returns
Zend_Pdf_Element_Object

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 333 of file ElementFactory.php.

334  {
335  #require_once 'Zend/Pdf/Element/Object.php';
336  $obj = new Zend_Pdf_Element_Object($objectValue, $this->_objectCount++, 0, $this);
337  $this->_modifiedObjects[$obj->getObjNum()] = $obj;
338  return $obj;
339  }

◆ newStreamObject()

newStreamObject (   $streamValue)

Generate new Zend_Pdf_Element_Object_Stream

Todo:
Reusage of the freed object. It's not a support of new feature, but only improvement.
Parameters
mixed$objectValue
Returns
Zend_Pdf_Element_Object_Stream

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 349 of file ElementFactory.php.

350  {
351  #require_once 'Zend/Pdf/Element/Object/Stream.php';
352  $obj = new Zend_Pdf_Element_Object_Stream($streamValue, $this->_objectCount++, 0, $this);
353  $this->_modifiedObjects[$obj->getObjNum()] = $obj;
354  return $obj;
355  }

◆ registerObject()

registerObject ( Zend_Pdf_Element_Object  $obj,
  $refString 
)

Register object in the factory

It's used to clear "parent object" referencies when factory is closed and clean up resources

Parameters
string$refString
Zend_Pdf_Element_Object$obj

Definition at line 406 of file ElementFactory.php.

407  {
408  $this->_registeredObjects[$refString] = $obj;
409  }

◆ remove()

remove ( Zend_Pdf_Element_Object  $obj)

Remove object in context of current factory.

Parameters
Zend_Pdf_Element_Object$obj
Exceptions
Zend_Pdf_Exception

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 313 of file ElementFactory.php.

314  {
315  if (!$obj->compareFactory($this)) {
316  #require_once 'Zend/Pdf/Exception.php';
317  throw new Zend_Pdf_Exception('Object is not generated by this factory');
318  }
319 
320  $this->_modifiedObjects[$obj->getObjNum()] = $obj;
321  $this->_removedObjects->attach($obj);
322  }

◆ resolve()

resolve ( )

Get source factory object

Returns
Zend_Pdf_ElementFactory

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 163 of file ElementFactory.php.

164  {
165  return $this;
166  }

◆ setObjectCount()

setObjectCount (   $objCount)

Set object counter

Parameters
integer$objCount

Implements Zend_Pdf_ElementFactory_Interface.

Definition at line 183 of file ElementFactory.php.

184  {
185  $this->_objectCount = (int)$objCount;
186  }

The documentation for this class was generated from the following file: