Beispiel #1
0
 /**
  * Execute a basic terminal object
  *
  * @param \League\CLImate\TerminalObject\Basic\BasicTerminalObject $obj
  * @return void
  */
 public function execute($obj)
 {
     $results = Helper::toArray($obj->result());
     $this->output->persist();
     foreach ($results as $result) {
         if ($obj->sameLine()) {
             $this->output->sameLine();
         }
         $this->output->write($obj->getParser()->apply($result));
     }
     $this->output->persist(false);
 }
Beispiel #2
0
 /**
  * Magic method for anything called that doesn't exist
  *
  * @param string $requested_method
  * @param array  $arguments
  *
  * @return \League\CLImate\CLImate|\League\CLImate\TerminalObject\Dynamic\DynamicTerminalObject
  *
  * List of many of the possible method being called here
  * documented at the top of this class.
  */
 public function __call($requested_method, $arguments)
 {
     // Apply any style methods that we can find first
     $name = $this->applyStyleMethods(Helper::snakeCase($requested_method));
     // The first argument is the string|array|object we want to echo out
     $output = reset($arguments);
     if (strlen($name)) {
         // If we have something left, let's try and route it to the appropriate place
         if ($result = $this->routeRemainingMethod($name, $arguments)) {
             return $result;
         }
     } elseif ($this->hasOutput($output)) {
         // If we have fulfilled all of the requested methods and we have output, output it
         $this->out($output);
     }
     return $this;
 }
 /**
  * Determine the extension key based on the class
  *
  * @param string|null $key
  * @param string|object $class
  *
  * @return string
  */
 protected function getKey($key, $class)
 {
     if ($key === null || !is_string($key)) {
         $class_path = is_string($class) ? $class : get_class($class);
         $key = explode('\\', $class_path);
         $key = end($key);
     }
     return Helper::snakeCase($key);
 }
Beispiel #4
0
 /**
  * Get the writers based on their keys
  *
  * @param string|array $keys
  *
  * @return array
  */
 protected function getWriters($keys)
 {
     $writers = array_flip(Helper::toArray($keys));
     return Helper::flatten(array_intersect_key($this->writers, $writers));
 }
Beispiel #5
0
 /**
  * Stringify the codes
  *
  * @param  mixed  $codes
  *
  * @return string
  */
 protected function codeStr($codes)
 {
     // If we get something that is already a code string, just pass it back
     if (!is_array($codes) && strstr($codes, ';')) {
         return $codes;
     }
     $codes = Helper::toArray($codes);
     // Sort for the sake of consistency and testability
     sort($codes);
     return implode(';', $codes);
 }
Beispiel #6
0
 /**
  * Compile an array of the current codes
  *
  * @return array
  */
 public function current()
 {
     $full_current = [];
     foreach ($this->style as $style) {
         $full_current = array_merge($full_current, Helper::toArray($style->current()));
     }
     $full_current = array_filter($full_current);
     return array_values($full_current);
 }