Exemplo n.º 1
0
 /**
  * Creates a new command name.
  *
  * @param string   $string  The command name.
  * @param string[] $aliases The alias names.
  */
 public function __construct($string, array $aliases = array())
 {
     Assert::string($string, 'The command name must be a string. Got: %s');
     Assert::notEmpty($string, 'The command name must not be empty.');
     Assert::regex($string, '~^[a-zA-Z0-9\\-]+$~', 'The command name must contain letters, digits and hyphens only. Got: "%s"');
     Assert::allString($aliases, 'The command aliases must be strings. Got: %s');
     Assert::allNotEmpty($aliases, 'The command aliases must not be empty.');
     Assert::allRegex($aliases, '~^[a-zA-Z0-9\\-]+$~', 'The command aliases must contain letters, digits and hyphens only. Got: "%s"');
     $this->string = $string;
     $this->aliases = $aliases;
 }
Exemplo n.º 2
0
 /**
  * Joins two or more path strings.
  *
  * The result is a canonical path.
  *
  * @param string[]|string $paths Path parts as parameters or array.
  *
  * @return string The joint path.
  *
  * @since 2.0 Added method.
  */
 public static function join($paths)
 {
     if (!is_array($paths)) {
         $paths = func_get_args();
     }
     Assert::allString($paths, 'The paths must be strings. Got: %s');
     $finalPath = null;
     $wasScheme = false;
     foreach ($paths as $path) {
         $path = (string) $path;
         if ('' === $path) {
             continue;
         }
         if (null === $finalPath) {
             // For first part we keep slashes, like '/top', 'C:\' or 'phar://'
             $finalPath = $path;
             $wasScheme = strpos($path, '://') !== false;
             continue;
         }
         // Only add slash if previous part didn't end with '/' or '\'
         if (!in_array(substr($finalPath, -1), array('/', '\\'))) {
             $finalPath .= '/';
         }
         // If first part included a scheme like 'phar://' we allow current part to start with '/', otherwise trim
         $finalPath .= $wasScheme ? $path : ltrim($path, '/');
         $wasScheme = false;
     }
     if (null === $finalPath) {
         return '';
     }
     return self::canonicalize($finalPath);
 }