Overview

Namespaces

  • Charcoal
    • App
      • Action
      • Config
      • Handler
      • Middleware
      • Module
      • Route
      • Script
      • ServiceProvider
      • Template

Classes

  • Charcoal\App\Action\AbstractAction
  • Charcoal\App\App
  • Charcoal\App\AppConfig
  • Charcoal\App\AppContainer
  • Charcoal\App\Config\CacheConfig
  • Charcoal\App\Config\DatabaseConfig
  • Charcoal\App\Config\FilesystemConfig
  • Charcoal\App\Config\LoggerConfig
  • Charcoal\App\Config\MemcacheCacheConfig
  • Charcoal\App\Config\MemcacheCacheServerConfig
  • Charcoal\App\Handler\AbstractHandler
  • Charcoal\App\Handler\Error
  • Charcoal\App\Handler\HandlerConfig
  • Charcoal\App\Handler\NotAllowed
  • Charcoal\App\Handler\NotFound
  • Charcoal\App\Handler\PhpError
  • Charcoal\App\Handler\Shutdown
  • Charcoal\App\Middleware\CacheMiddleware
  • Charcoal\App\Module\AbstractModule
  • Charcoal\App\Module\ModuleConfig
  • Charcoal\App\Module\ModuleManager
  • Charcoal\App\Route\ActionRoute
  • Charcoal\App\Route\ActionRouteConfig
  • Charcoal\App\Route\RouteConfig
  • Charcoal\App\Route\RouteManager
  • Charcoal\App\Route\ScriptRoute
  • Charcoal\App\Route\ScriptRouteConfig
  • Charcoal\App\Route\TemplateRoute
  • Charcoal\App\Route\TemplateRouteConfig
  • Charcoal\App\Script\AbstractScript
  • Charcoal\App\ServiceProvider\AppServiceProvider
  • Charcoal\App\ServiceProvider\CacheServiceProvider
  • Charcoal\App\ServiceProvider\DatabaseServiceProvider
  • Charcoal\App\ServiceProvider\FilesystemServiceProvider
  • Charcoal\App\ServiceProvider\LoggerServiceProvider
  • Charcoal\App\ServiceProvider\ViewServiceProvider
  • Charcoal\App\Template\AbstractTemplate
  • Charcoal\App\Template\AbstractWidget
  • Charcoal\App\Template\WidgetBuilder

Interfaces

  • Charcoal\App\Action\ActionInterface
  • Charcoal\App\AppAwareInterface
  • Charcoal\App\Handler\HandlerInterface
  • Charcoal\App\Module\ModuleInterface
  • Charcoal\App\Route\RouteInterface
  • Charcoal\App\Script\CronScriptInterface
  • Charcoal\App\Script\ScriptInterface
  • Charcoal\App\Template\TemplateInterface
  • Charcoal\App\Template\WidgetInterface

Traits

  • Charcoal\App\AppAwareTrait
  • Charcoal\App\CallableResolverAwareTrait
  • Charcoal\App\Script\ArgScriptTrait
  • Charcoal\App\Script\CronScriptTrait
  • Charcoal\App\Script\PathScriptTrait
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: namespace Charcoal\App\Script;
 4: 
 5: use \Traversable;
 6: use \RuntimeException;
 7: use \InvalidArgumentException;
 8: 
 9: /**
10:  * Additional utilities for handling arguments and inputs.
11:  */
12: trait ArgScriptTrait
13: {
14:     /**
15:      * Resolve the given value as a collection of values.
16:      *
17:      * If the given value is a string, it will be split.
18:      *
19:      * @param  mixed  $var       An argument to split.
20:      * @param  string $delimiter The boundary string.
21:      * @throws InvalidArgumentException If the value cannot be parsed into an array.
22:      * @return array|Traversable
23:      */
24:     protected function parseAsArray($var, $delimiter = '[\s,]+')
25:     {
26:         if (is_string($var)) {
27:             if (!is_string($delimiter)) {
28:                 throw new InvalidArgumentException('The delimiter must be a string.');
29:             }
30: 
31:             $var = preg_split('#(?<!\\\\)'.$delimiter.'#', $var);
32:         }
33: 
34:         if (is_array($var) || $var instanceof Traversable) {
35:             return $var;
36:         }
37: 
38:         throw new InvalidArgumentException('The value cannot be split.');
39:     }
40: 
41:     /**
42:      * Parse command line arguments into script properties.
43:      *
44:      * @throws RuntimeException If a checkbox/radio argument has no options.
45:      * @return self
46:      */
47:     protected function parseArguments()
48:     {
49:         $cli  = $this->climate();
50:         $args = $cli->arguments;
51: 
52:         $ask    = $args->defined('interactive');
53:         $params = $this->arguments();
54:         foreach ($params as $key => $param) {
55:             $setter = $this->setter($key);
56: 
57:             if (!is_callable([ $this, $setter ])) {
58:                 continue;
59:             }
60: 
61:             $value = $args->get($key);
62:             if (!empty($value) || is_numeric($value)) {
63:                 $this->{$setter}($value);
64:             }
65: 
66:             if ($ask) {
67:                 if (isset($param['prompt'])) {
68:                     $label = $param['prompt'];
69:                 } else {
70:                     continue;
71:                 }
72: 
73:                 $value = $this->input($key);
74:                 if (!empty($value) || is_numeric($value)) {
75:                     $this->{$setter}($value);
76:                 }
77:             }
78:         }
79: 
80:         return $this;
81:     }
82: }
83: 
API documentation generated by ApiGen