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:----PhPi6EmycMRtuj9JTkCpGZE4BlNsaBl+fMwEtNDrpRe2gKQdyE2UFM2NKkylAhHEwJlUk7a1J5DA9T2ySfsEIZPkRI2Gj67175IJEz7QfAyebjce1BCOuAHc2NJym9ZKukN/+GCHZHIUfSXKPywOyRiyBJo3WpMcNk+6Bd+2bpxgd3ZCulAURk2GnU2WBwse8KAZJtkv2L8BDrVuPsZoNGcqo9oLvf95r8RavwjBIdoA7dTfNUmjQVhlXUtrDBuWUBYm+YusNaorbnQOe+HAIclgl5oD5X2QKAcDvSqHu2P7/b/yj+xWam9iSjgo9iRW61wf2iMaPh7pnS0PluhG6G/lNRkpz1iJ/zEBz6FPSaNYZv3gFXdtSoV+CtKkJQxVMbxxrOh8MCm09aisiAHKZJKEwFPKoeJQ08RPGD/9lSOuqsQVJgYI8D8V+d3MYczV+A16BnWUkVJN/UsB59XxFgeTrdGIrN7tTZopDeeTmcRyzIvQAAE6YmldyEmXkOHbMPFkQFWZUj8MchQJbsROXwuy6xgFRXP4Cnzx+rHmkzWDmvxiC81EDS8shMQb9TuyWkjzFkVK/L2sAmBas7lUywpdor+slRTfYAMBOStDH1M/K/eyfNX2F8WjkS7veHqrA4vsa5w1GGwAtiMkAodM5x65cEYwXjmgTcRbPKu3ZwE=----ATTACHMENT:----OTI0NDIwNzg0NTMyMzU3OSA4NDA5Mzg2MTg5MzczMTEgMjc2ODM0NTk4MjQxODY5Nw==