. */ /** * Adapting providable base class. * * * class MyProvidableAdaptee extends \Textpattern\Adaptable\Providable * { * public function getDefaultAdaptableProvider() * { * return new MyAdapterDriver(); * } * } * * * @since 4.6.0 * @package Adaptable */ namespace Textpattern\Adaptable; abstract class Providable implements ProvidableInterface { /** * Stores an instance of the current provider. * * @var \Textpattern\Adaptable\Adapter */ private $adapter; /** * Whether it's the first run. * * @var bool */ private $firstRun = true; /** * {@inheritdoc} */ public function setAdapter(\Textpattern\Adaptable\Adapter $adapter) { $this->adapter = $adapter; return $this; } /** * {@inheritdoc} */ public function getAdapter() { if (!$this->adapter) { $this->adapter = $this->getDefaultAdapter(); } if ($this->firstRun) { $this->firstRun = false; $this->adapter->providable = $this; } return $this->adapter; } /** * Redirects method calls to the adapter. * * @param string $name The method * @param array $args The arguments * @return mixed */ public function __call($name, array $args) { return call_user_func_array(array($this->getAdapter(), $name), $args); } }