Esempio n. 1
0
 /**
  * Execute a terminal object using given arguments
  *
  * @param string $name
  * @param mixed  $arguments
  *
  * @return null|\League\CLImate\TerminalObject\Basic\BasicTerminalObjectInterface
  */
 public function execute($name, $arguments)
 {
     $router = $this->getRouter($name);
     $router->output($this->output);
     $obj = $this->getObject($router, $name, $arguments);
     $obj->parser($this->parser);
     $obj->util($this->util);
     // 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);
         }
     }
     return $router->execute($obj);
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Execute a terminal object using given arguments
  *
  * @param string $name
  * @param mixed  $arguments
  * @return null|\League\CLImate\TerminalObject\Basic\BasicTerminalObjectInterface
  */
 public function execute($name, $arguments)
 {
     $router = $this->getRouter($name);
     $router->output($this->output);
     $reflection = new \ReflectionClass($router->path($name));
     $obj = $reflection->newInstanceArgs($arguments);
     $obj->parser($this->parser);
     $obj->util($this->util);
     // 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);
         }
     }
     return $router->execute($obj);
 }
Esempio n. 4
0
 /**
  * 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);
     }
 }
Esempio n. 5
0
 /**
  * Route anything leftover after styles were applied
  *
  * @param string $name
  * @param array $arguments
  *
  * @return object|null
  */
 protected function routeRemainingMethod($name, array $arguments)
 {
     // If we still have something left, let's figure out what it is
     if ($this->router->exists($name)) {
         $obj = $this->buildTerminalObject($name, $arguments);
         // If something was returned, return it
         if (is_object($obj)) {
             return $obj;
         }
     } elseif ($this->settings->exists($name)) {
         $this->settings->add($name, reset($arguments));
         // Handle passthroughs to the arguments manager.
     } else {
         // If we can't find it at this point, let's fail gracefully
         $this->out(reset($arguments));
     }
 }