示例#1
0
 /**
  * Execute init command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //get projects dir name
     $dirName = $input->getArgument('directory_name');
     $dir = IE_PROJECTS_DIR . $dirName . DIRECTORY_SEPARATOR;
     //validate projects dir name
     $pattern = '/^[a-zA-Z0-9\\-\\_]+$/';
     $allowedChars = 'a-z, A-Z, 0-9, -, _';
     if (!preg_match($pattern, $dirName)) {
         $output->writeln('<fg=red>ERROR: wrong projects directory name "' . $dirName . '". Allowed characters: ' . $allowedChars . '</fg=red>');
         exit(1);
     }
     //check if projects dir exists
     if (file_exists($dir)) {
         $output->writeln('<fg=red>ERROR: projects directory  "' . $dirName . '" already exists</fg=red>');
         exit(1);
     }
     if (!@mkdir($dir)) {
         $output->writeln('<fg=red>ERROR: failed to create directory "' . $dirName . '" (exists/permissions?)</fg=red>');
         exit(1);
     }
     //custom directory init
     if (!FileSystem::copy(IE_SAMPLES_DIR . IE_CUSTOM_DIR_NAME, $dir . IE_CUSTOM_DIR_NAME)) {
         $output->writeln('<fg=red>ERROR: custom config directory initialization failed</fg=red>');
         exit(1);
     }
     if (!@copy(IE_CORE_DIR . 'config.conf', $dir . IE_CUSTOM_DIR_NAME . DIRECTORY_SEPARATOR . 'config.conf')) {
         $output->writeln('<fg=red>ERROR: failed to copy master config file to custom config directory</fg=red>');
         exit(1);
     }
     $output->writeln('Projects directory "' . $dirName . '" created successfully!');
 }
示例#2
0
 /**
  * Execute init command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //get project name
     $projectDest = $input->getArgument('project_dest');
     $projectSrc = $input->getArgument('project_src');
     //validate project name
     $pattern = '/^[a-zA-Z0-9\\-\\_]+$/';
     $allowedChars = 'a-z, A-Z, 0-9, -, _';
     if (!preg_match($pattern, $projectSrc)) {
         $output->writeln('<fg=red>ERROR: wrong base project name "' . $projectSrc . '". Allowed characters: ' . $allowedChars . '</fg=red>');
         exit(1);
     }
     if (!preg_match($pattern, $projectDest)) {
         $output->writeln('<fg=red>ERROR: wrong project name "' . $projectDest . '". Allowed characters: ' . $allowedChars . '</fg=red>');
         exit(1);
     }
     //set src dir
     $projectSrcDir = IE_PROJECTS_DIR . $projectSrc;
     if (!file_exists($projectSrcDir)) {
         $projectSrcDir = IE_SAMPLES_DIR . $projectSrc;
         if (!file_exists($projectSrcDir)) {
             $output->writeln('<fg=red>ERROR: base project "' . $projectSrc . '" not found</fg=red>');
             exit(1);
         }
     }
     //set dest dir
     $projectDestDir = IE_PROJECTS_DIR . $projectDest;
     if (file_exists($projectDestDir)) {
         $output->writeln('<fg=red>ERROR: new project directory "' . $projectDest . '" exists</fg=red>');
         exit(1);
     }
     //start copying
     if (!FileSystem::copy($projectSrcDir, $projectDestDir)) {
         $output->writeln('<fg=red>ERROR: failed to copy source project to destination</fg=red>');
     } else {
         $output->writeln('Project "' . $projectDest . '" initialized successfully!');
     }
 }