Ejemplo n.º 1
0
 /**
  * Retrieve arguments from global to prepare them for further use.
  *
  * @param CommandEvent $event The Composer event fired to retrieve arguments from
  *
  * @author Benjamin Carl <*****@*****.**>
  * @return boolean|null TRUE on success, otherwise FALSE
  * @access protected
  * @static
  */
 protected static function initArguments(CommandEvent $event = null)
 {
     // Check for retrieving arguments from Composer event ...
     if ($event !== null) {
         $arguments = $event->getArguments();
     } else {
         $arguments = $_SERVER['argv'];
     }
     // Check for strict mode
     $strict = in_array('--strict', $arguments);
     $arguments = new \cli\Arguments(compact('strict'), $arguments);
     $arguments->addFlag(array('verbose', 'v'), 'Turn on verbose output');
     $arguments->addFlag(array('version', 'V'), 'Display the version');
     $arguments->addFlag(array('quiet', 'q'), 'Disable all output');
     $arguments->addFlag(array('help', 'h'), 'Show this help screen');
     // Parse the arguments
     $arguments->parse();
     // Store arguments ...
     self::$arguments = $arguments;
     if (isset(self::$arguments['help']) === true) {
         self::showHelp();
     }
 }
Ejemplo n.º 2
0
 /**
  * Validates a path for installation.
  *
  * @param string $path The path to validation
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return string TRUE if path is valid, otherwise FALSE
  *
  * @throws Exception
  */
 protected static function validatePath($path)
 {
     // Validate path by default logic
     $path = parent::validatePath($path);
     // Collection of existing folders for error message
     $existingFolders = [];
     // Check now if any of the target directories exists
     foreach (self::getFolders() as $folder) {
         if (file_exists($path . $folder)) {
             $existingFolders[] = $folder . '/';
         }
     }
     // Any folder found? => Exception
     if (count($existingFolders) > 0) {
         throw new Exception('The target directory contains the following files/folders already: ' . implode(' & ', $existingFolders) . '.' . PHP_EOL . 'Remove those files/folders first and try again.' . PHP_EOL);
     }
     return $path;
 }