/** * @param string|null $event_name * @return $this */ public function triggerEvent($event_name = null) { if (is_null($event_name)) { $event_name = CodeHelper::getPropertyName(get_class($this)); } $event = new Event($this, $event_name); foreach ($this->_observers_storage as $observer) { if ($event->isPropagationStopped()) { break; } /* @var EventObserverProxy $observer */ $observer->handleEvent($event); } return $this; }
/** * Magic unsetter * * Magic method called when `unsetProp()` or `unset($this->prop)` are invoked. * * @see <http://www.php.net/manual/en/language.oop5.overloading.php> * @see Patterns\Commons\Registry::_invokeUnset() * * @param string $name The name of the property to get * @return self Returns `$this` for method chaining */ public function __unset($name) { $this->_data->setEntry(CodeHelper::getPropertyName($name), null); return $this; }
/** * Magic method to allow usage of `$factory->propertyInCamelCase()` for each class property * * @param string $name * @param array $arguments * @return self */ public function __call($name, array $arguments) { $property_name = CodeHelper::getPropertyName($name); if (property_exists($this, $property_name)) { $param = array_shift($arguments); $this->setOptions(array($property_name => is_array($this->{$property_name}) ? is_array($param) ? $param : array($param) : $param)); } return $this; }
/** * Magic handler when calling a non-eixsting method statically on an object * * Magic static handling of `getProp(default)`, `setProp(value)`, `unsetProp()`, `issetProp()` or `resetProp()`. * * @see <http://www.php.net/manual/en/language.oop5.overloading.php> * * @param string $name The non-existing method name called on the object * @param array $arguments The arguments array passed calling the method * @return mixed This will return the result of a magic method, or nothing if nothing can be done */ public static function __callStatic($name, array $arguments) { $return = null; // unset, isset, reset if (in_array(substr($name, 0, 5), array('isset', 'reset', 'unset'))) { $property = CodeHelper::getPropertyName(substr($name, 5)); } // get, set if (in_array(substr($name, 0, 3), array('set', 'get'))) { $property = CodeHelper::getPropertyName(substr($name, 3)); } if (!empty($property) && self::__isInvokableStatic($property)) { $classname = get_called_class(); try { $object = new $classname(); $return = call_user_func_array(array($object, '__call'), array($name, $arguments)); } catch (\Exception $e) { } } return $return; }