Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Callback Class Reference
Inheritance diagram for Callback:
OptionInterface

Public Member Functions

 __construct ($callable, $arguments=null, $createInstance=false)
 
 setArguments ($arguments=null)
 
 getValue ()
 

Protected Attributes

 $_callable
 
 $_arguments
 
 $_createInstance
 

Detailed Description

Definition at line 10 of file Callback.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $callable,
  $arguments = null,
  $createInstance = false 
)

Create callback

Parameters
callable$callable
mixed$arguments
bool$createInstanceIf true than $callable[0] will be evaluated to new instance of class when get value

Definition at line 34 of file Callback.php.

35  {
36  $this->_callable = $callable;
37  $this->setArguments($arguments);
38  $this->_createInstance = $createInstance;
39  }
$arguments

Member Function Documentation

◆ getValue()

getValue ( )

Get callback value

Returns
mixed
Exceptions

Implements OptionInterface.

Definition at line 64 of file Callback.php.

65  {
66  $callable = $this->_callable;
67 
68  if (is_array($callable) && isset($callable[0]) && is_string($callable[0])) {
69  if (!class_exists($callable[0])) {
70  throw new \InvalidArgumentException(sprintf('Class "%s" was not found', $callable[0]));
71  }
72  if ($this->_createInstance) {
73  $callable[0] = new $callable[0]();
74  }
75  } elseif ($this->_createInstance) {
76  throw new \InvalidArgumentException('Callable expected to be an array with class name as first element');
77  }
78 
79  if (!is_callable($callable)) {
80  throw new \InvalidArgumentException('Callback does not callable');
81  }
82 
83  if ($this->_arguments) {
84  return call_user_func_array($callable, $this->_arguments);
85  } else {
86  return call_user_func($callable);
87  }
88  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ setArguments()

setArguments (   $arguments = null)

Set callback arguments

Parameters
mixed$arguments
Returns
void

Definition at line 47 of file Callback.php.

48  {
49  if (is_array($arguments)) {
50  $this->_arguments = $arguments;
51  } elseif (null !== $arguments) {
52  $this->_arguments = [$arguments];
53  } else {
54  $this->_arguments = null;
55  }
56  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$arguments

Field Documentation

◆ $_arguments

$_arguments
protected

Definition at line 20 of file Callback.php.

◆ $_callable

$_callable
protected

Definition at line 15 of file Callback.php.

◆ $_createInstance

$_createInstance
protected

Definition at line 25 of file Callback.php.


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