setasign\SetaPDF2\Core\Type

PdfCallback This class acts like a proxy for all available SetaPDF_Core_Type_* classes

File: /SetaPDF v2/Core/Type/PdfCallback.php
Old class name (alias): \SetaPDF_Core_Type_Callback

The class allows a developer to attach callbacks before and/or after any native method of the original type instance.

Class hierarchy

Implements

Summary

Properties

$_callbacks

protected callback PdfCallback::$_callbacks

$_observed

protected bool AbstractType::$_observed = false

Defines if this object is under observation

$_observers

protected array AbstractType::$_observers = array()

The Objects to notify on any change

This will be the PDF document or another value holding this one. Initially this will be an array.

$metadata

public array AbstractType::$metadata = array()

An array for individual metadata.


Static Methods

_ensureType()

protected static AbstractType::_ensureType (
string $type,
mixed $value,
string $errorMessage,
$ensure = true
): mixed

Ensure that a value is an instance of a specific PDF type.

Parameters
$type : string
 
$value : mixed
 
$errorMessage : string
 
$ensure
 
Exceptions

Throws Exception

ensureType()

public static AbstractType::ensureType (
mixed $value
): self

Ensures that the passed value is a AbstractType instance.

Parameters
$value : mixed
 
Exceptions

Throws Exception

ensureWithType()

public static AbstractType::ensureWithType (
string $type,
mixed $value
): \SetaPDF_Core_Type_AbstractType

Ensures that the passed value is an instance of the passed type.

Parameters
$type : string
 
$value : mixed
 
Exceptions

Throws Exception

is()

public static AbstractType::is (
string $type,
mixed $value,
bool $ensure = true
): bool

Checks if the type of a value is the expected one.

Indirect references will be evaluated if $ensure is set to true.

Parameters
$type : string
 
$value : mixed
 
$ensure : bool
 

writePdfString()

public static AbstractType::writePdfString (
\SetaPDF_Core_WriteInterface $writer,
mixed $value
): void

Parses a php value to a pdf string and writes it into a writer.

PHP data type -> PDF data type

Null -> PdfNull

Boolean -> PdfBoolean

Integer/Double -> PdfNumeric

String -> PdfString or PdfName(if the string starts with "/")

Indexed array -> PdfArray

Associative array -> PdfDictionary

Parameters
$writer : \SetaPDF_Core_WriteInterface
 
$value : mixed
 
Exceptions

Throws \InvalidArgumentException


Methods

__construct()

__call()

public PdfCallback::__call (
string $method,
array $arguments
): mixed

Overloads all method calls.

Parameters
$method : string
 
$arguments : array
 
Exceptions

Throws \BadMethodCallException

__sleep()

public AbstractType::__sleep (
void
): array

Implementation of __sleep.

We remove the observers from all elements because they will get read if they are waked up in an observed object.

__wakeup()

public AbstractType::__wakeup (
void
): void

Implementation of __wakeup.

Unset the observed flag.

addCallback()

public PdfCallback::addCallback (
string $method,
callback $callback,
bool $before = true
): void

Add a callback before or after a specific method call.

Parameters
$method : string
 
$callback : callback
 
$before : bool
 
Exceptions

Throws \InvalidArgumentException

attach()

public AbstractType::attach (
\SplObserver $observer
): void

Add an observer to the object.

Implementation of the Observer Pattern.

Parameters
$observer : \SplObserver
 

cleanUp()

public PdfCallback::cleanUp (
void
): void

Release resources/memory.

deepClone()

Clone the object recursively in the context of a document.

Parameters
$document : \SetaPDF_Core_Document
 

detach()

public AbstractType::detach (
\SplObserver $observer
): void

Detach an observer from the object.

Implementation of the Observer Pattern.

Parameters
$observer : \SplObserver
 

detachAll()

public AbstractType::detachAll (
void
): void

Detach all observers from this object.

Be careful with this method!!!

ensure()

public AbstractType::ensure (
?bool $forceObservation = null,
array &$ensuredObjectsList = array ( )
): \SetaPDF_Core_Type_AbstractType

Returns the main value.

This method is used for automatically resolving of indirect references.

Parameters
$forceObservation : ?bool
 
$ensuredObjectsList : array

A list of all ensured indirect objects to prevent recursion

getValue()

public PdfCallback::getValue (
void
): mixed

Gets the PDF value.

isObserved()

public AbstractType::isObserved (
void
): bool

Checks if this object is observed.

notify()

public AbstractType::notify (
void
): void

Notifies all attached observers.

Implementation of the Observer Pattern.

Has to be called by any method that changes a value.

setValue()

public PdfCallback::setValue (
mixed $value
): void

Sets the value of the PDF type.

Parameters
$value : mixed
 

toPdfString()

public PdfCallback::toPdfString (
?\SetaPDF_Core_Document $pdfDocument = null
): string

Returns the type as a formatted PDF string.

Parameters
$pdfDocument : ?\SetaPDF_Core_Document
 

toPhp()

public PdfCallback::toPhp (
void
): mixed

Converts the PDF data type to a PHP data type and returns it.

writeTo()

public PdfCallback::writeTo (
\SetaPDF_Core_Document $pdfDocument
): void

Writes the type as a formatted PDF string to the document.

Parameters
$pdfDocument : \SetaPDF_Core_Document