<?php
namespace Moto; class AbstractClass { protected $_options = array(); public function __construct($options = array()) { $this->setOptions($options); $this->init(); } public function init() { } public function setOptions($options) { if (!is_array($options) && !$options instanceof \Traversable) { return $this; } foreach ($options as $name => $value) { $this->setOption($name, $value); } return $this; } public function getOptions() { return $this->_options; } public function getOption($name, $default = null) { return (array_key_exists($name, $this->_options) ? $this->_options[$name] : $default); } public function setOption($name, $value) { $setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name))); if (method_exists($this, $setter)) { $this->{$setter}($value); } else { $this->_options[$name] = $value; } return $this; } }