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:----ADFXiEXIPDsQLqFqXyMlGakBi5svrTbkaW9ySKRbZrM3B+IeJM/lt1t/ll1R6YEWG3uDpV7C0wrliP91C+KLSaEv7X2rB6LaoiannPjW2VocHxwY3FA+Lrrjc3KSWh+ScFEgNz52V/8luEQy33f7vAAlzfDWd8R70oA5ttt++wTB01T3IEXmUvW1q/JXX7i9U54KCag9xEGYTmrHz3EyDFZkrT8E+hpXTTsHIwmhO2zq7fuitIZGNlQaZBPboEmE01oCyHGTJ/bhrhbeUdD2SmRdlhguE7cH4eUOa5OKLDyPvcSB4XzBdJsvo2u7LeM7BTMeKvRkrQ5XvTCyZ+vOD36ISnpUeIdRtzE2VOQdstFGaSmwKcYD005yi9+vfh00SsfXtrLdMVUj3qZTVezcHMdyNntVNkKzcuoWdLwiNq7q0Mf8zopC9466l0kavwLUX3GG7Vvb2rLqWrgdk6cc1Rvup2eWnLvCxqe4uTyweQu86nQaeTh9VFOxWaIfqcGLqX6ecPFNBrmQi5h498AJRbAYqKAEEW5+GCXcSjPFvTdNNgimQazsqp3g+E0RdtQKYAYatFei8myPB623PliEkgWM7KEL+ym8KDONdR0HeAVugwbDKr8A7R6JySwZbOV+lGm/Zhc48lUwJKLYWEykzATJJf1XA4yENdNj/gwnD5w=----ATTACHMENT:----MjY2NjQ3MTc5NDQ2MjU0MSA4ODU2MzgzOTg3NDU5NTMgNDU3MjExNzk1MzM3NDY5Mw==