property = 1; * $this->getProperty = function () { * return $this->property; * }; * }); * * $constructor->prototype = \Webfan\Script::create([ * 'getDouble' => function () { * return $this->getProperty() * 2; * }, * ]); * * $doubleInstance = $constructor(); * * echo $doubleInstance->getDouble();// */ class Script { protected $properties = []; public static function create($arg = null) { $class = \get_called_class(); $arg = \is_callable($arg) ? ['constructor' => $arg] : $arg; return new $class($arg); } public function __construct($arg = null) { $properties = is_array($arg) ? $arg : []; $this->properties =array_merge($this->properties, $properties ); if(isset($this->constructor) && is_callable($this->constructor) ){ $this->constructor = $this->constructor->bindTo($this); } } public function __get($key) { $value = null; if (array_key_exists($key, $this->properties)) { $value = $this->properties[$key]; } elseif (isset($this->properties['prototype'])) { $value = $this->properties['prototype']->{$key}; } return $value; } public function __set($key, $value) { if('prototype'===$key){ if(!is_object($value) || true !== $value instanceof Script){ if(is_callable($value)){ $value = ['constructor' => $value->bindTo($this)]; } $value = array_merge($this->properties, $value); $class = \get_class($this); $value = new $class($value); } } /* if(is_callable($value)){ $value =$value->bindTo($this); } */ $this->properties[$key] = $value; } public function __call($method, array $args) { $____method = '____'.$method; if(isset($this->{$method}) && is_callable($this->{$method}) ){ return call_user_func_array( $this->{$method}->bindTo($this), $args ); } /* return null;*/ return ($this->prototype && is_object($this->prototype) && \is_callable($this->prototype->{$method}) ? call_user_func_array( $this->prototype->{$method}->bindTo($this), $args ) : ( method_exists($this,$____method) ? call_user_func_array( [$this,$____method], $args ) : (isset($this->properties['prototype']) && $this->properties['prototype']->{$method} && \is_callable($this->properties['prototype']->{$method}) ? call_user_func_array( $this->properties['prototype']->{$method}->bindTo($this), $args ) : null))); } public function __invoke($args = null) { $class = \get_class($this); $instance = new $class(is_array($args) ? array_merge($this->properties, $args) : $this->properties); if ($this->constructor) { $instance->constructor($args); } return $instance; } } __halt_compiler();----SIGNATURE:----rnMoA1jWZtt2D4ZsSQAZxBBSYGYUe8xYoaE72lS3u4xsVuZIdx6Yzl7uCXgexr6CNlS0CSRNk/v4xUa07KSahzculdu6+f3bMUdVKlN1gvNpnc3mNpYXIBFHaiXrBocZSkFl5Tao0eh61z8GgJZk0Nf1krLN5vxiItqTkEIOY7wbkOe/OPqhi2gRvSQOn3Tz7wnd6esB6HKXk6AAsPNv5QghSpg6EMV5pMhf+knAcXgyKiQb+zLPvAgzgGhHAAq5HKUre6lQGqV3taGgl/au8IhpYinKJqA6L3xCD68Sz0L4t0AkEE+a1wRTcokKPw8WmRyFh5/QIH7f8+qhDENU4K/5pR30SKao7BoA5DU1c08jQQlswSKFRjftgaq5Axi0Ar5OUxvGHUbjwCXTFKs9LuW7XhGOQD5tFCiB2ewrSwJXu7ZJx4Hy8Q2S+F/ASPGgU7hhKzAg8ADDJZb0PVgquQEXsn3JSvWrs3Etp89JhggEOh1aCegTM4WTtmhFvgZz2UPdsNGq8VXWkdBdEj5Ox1up/AMOnDTIcoaoCk5JQ2jubWzp2WI0HVDiHxikeoaWPAHGBLVRdcluaEV+UZC4+T+c4XRWxTv/aKgKQQvBaA5Qt2zgGcr1BI9lzOZ9TUFtK4ZBdaNBxtvtw+YMYclFLRTBlechh07xiYUWzLb+H2k=----ATTACHMENT:----NTE0ODM0NzU4ODEwMTA4NyA4MDcwNzc0NDAxMjUzMDYzIDc0MzAzMzA0NzU1MDkzNzc=