/** * Magic method for anything called that doesn't exist * * @param string $requested_method * @param array $arguments * * List of many of the possible method being called here * documented at the top of this class. */ public function __call($requested_method, $arguments) { // Convert to snake case $name = strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $requested_method)); // The first argument is the string|array|object we want to echo out $output = reset($arguments); $name = $this->applyStyleMethods($name); // If we have fulfilled all of the requested methods and we have output, output it if (!strlen($name) && $this->hasOutput($output)) { return $this->out($output); } // If we still have something left, let's see if it's a terminal object if (strlen($name)) { if ($this->terminal_object->exists($name)) { // Retrieve the parser for the current set of styles $parser = $this->style->parser(); // Reset the styles $this->style->reset(); // Execute the terminal object $obj = $this->terminal_object->settings($this->settings)->parser($parser)->execute($name, $arguments); // If something was returned, return it if ($obj) { return $obj; } } elseif ($this->settings->exists($name)) { $this->settings->add($name, $output); } else { // If we can't find it at this point, let's fail gracefully return $this->out($output); } } return $this; }
/** * Execute a terminal object using given arguments * * @param string $name * @param mixed $arguments */ public function execute($name, $arguments) { $class = $this->getClass($name); $reflection = new \ReflectionClass($class); $obj = $reflection->newInstanceArgs($arguments); $obj->parser($this->parser); // If the object needs any settings, import them foreach ($obj->settings() as $obj_setting) { $setting = $this->settings->get($obj_setting); if ($setting) { $obj->importSetting($setting); } } if ($this->isBasic($name)) { $this->executeBasic($obj); } else { return $this->executeDynamic($obj); } }