protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new ConsoleLogger($output);
     try {
         $this->getSecretKey();
         $forest = $this->getContainer()->get('forestadmin.forest');
         if ($forest->postApimap()) {
             $text = 'Success!';
         } else {
             $logger->error('Could not post API map for an unknown reason.');
             $text = 'Failure!';
         }
     } catch (ClientException $exc) {
         $logger->error('Client Failure: ' . $exc->getMessage());
         $text = 'Cannot contact the client.';
     } catch (RequestException $exc) {
         $logger->critical('Request Failure: ' . $exc->getMessage());
         $text = 'Malformed request.';
     } catch (InvalidArgumentException $exc) {
         $logger->debug('Client tried to contact us without secret key');
         $text = "Failure: " . $exc->getMessage() . "\n" . "Configure your secret key with the key you received when you registered your app to Forest.";
     } catch (\Exception $exc) {
         $logger->error('Unexpected exception triggered: ' . $exc->getMessage());
         $text = get_class($exc) . ' Failure: ' . $exc->getMessage();
     }
     $output->writeln($text);
 }
Beispiel #2
0
 public function testHasErrored()
 {
     $logger = new ConsoleLogger(new BufferedOutput());
     $this->assertFalse($logger->hasErrored());
     $logger->warning('foo');
     $this->assertFalse($logger->hasErrored());
     $logger->error('bar');
     $this->assertTrue($logger->hasErrored());
 }
Beispiel #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* Get path and name of the input file */
     $basename = $input->getArgument('input');
     /* Launch Logger module */
     $logger = new ConsoleLogger($output);
     /* Security precaution : if it misses a slash at the end of the $dest_directory variable, add this slash  */
     if (substr($basename, -1) != '/') {
         $basename .= '/';
     }
     /* The file not exists */
     if (!is_file("{$basename}" . "paquito.yaml")) {
         $logger->error($this->getApplication()->translator->trans('parse.exist', array('%basename%' => "{$basename}" . "paquito.yaml")));
         exit(-1);
     } elseif (!is_readable("{$basename}" . "paquito.yaml")) {
         /* If the file is not readable */
         $logger->error($this->getApplication()->translator->trans('parse.right', array('%basename%' => "{$basename}" . "paquito.yaml")));
         exit(-1);
     }
     # Parse the file and return its content like a array (hashmap)
     $this->getApplication()->data = Yaml::parse(file_get_contents("{$basename}" . "paquito.yaml"));
     /* Change the current directory to the project directory */
     chdir($basename);
 }
Beispiel #4
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new ConsoleLogger($output);
     $questionAsker = new QuestionAsker($this->getHelper('question'), $input, $output);
     try {
         $targetDir = call_user_func_array($this->dirValidatorFactory, [$questionAsker, $this->filesystem])->validateValue($input->getArgument('path'));
         $data = call_user_func_array($this->dataProviderFactory, [$questionAsker])->getData();
         $assets = call_user_func_array($this->assetCollectionFactory, [$this->filesystem, $data]);
         $assets->exportToDir($targetDir);
     } catch (\Exception $e) {
         if ($output->isDebug()) {
             throw $e;
         }
         $logger->error($e->getMessage());
         return Application::EXIT_CODE_MAPPING[get_class($e)] ?? Application::EXIT_CODE_UNKOWN_ERROR;
     }
 }
Beispiel #5
0
 /**
  * prepAnnonces
  * 
  * Methode preparing the Annonces by extracting the zip archive and moving the images to the images dir. 
  *  
  *
  * @param string  $sFileName
  * @return boolean|null
  */
 private function prepAnnonces($sFileName)
 {
     $oFilesystem = new Filesystem();
     $this->oLogger->info("ZIP : " . $sFileName);
     if ($oFilesystem->exists($sFileName)) {
         $this->oLogger->info("File Exists true");
         //Upload du Zip
         if ($this->extractionProcess($sFileName)) {
             $this->oLogger->info("Extraction du fichier " . $sFileName . " réussit");
             $this->moveSourceImage();
             $this->bStatusPasserelle = 1;
             $this->putAnnonceInStandBy();
             return true;
         } else {
             $this->oLogger->error("Erreur lors de l'extraction du fichier " . $sFileName);
             $this->bStatusPasserelle = 0;
             return false;
         }
     } else {
         $this->oLogger->error("{$sFileName} does not exists !");
     }
 }
Beispiel #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* Optionnal argument (input file, which will be parsed) */
     $input_file = $input->getArgument('input');
     /* If the optionnal argument is present */
     if ($input_file) {
         /* Get references of the command parse() */
         $command = $this->getApplication()->find('parse');
         /* Declare the arguments in a array (arguments has to gave like this) */
         $arguments = array('command' => 'parse', 'input' => $input_file);
         $array_input = new ArrayInput($arguments);
         /* Run command */
         $command->run($array_input, $output);
     }
     /* Get path and name of the output file */
     $output_file = $input->getArgument('output');
     /* Launch Logger module */
     $logger = new ConsoleLogger($output);
     /* Write content of the structure on the output file */
     if (file_put_contents($output_file, Yaml::dump($this->getApplication()->data)) === false) {
         $logger->error($this->getApplication()->translator->trans('write.save', array('%output_file%' => $output_file)));
         return -1;
     }
 }
Beispiel #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* Get path and name of the input file */
     $input_file = $input->getArgument('input');
     /* Get references of the command parse() */
     $command = $this->getApplication()->find('normalize');
     /* Declare the arguments in a array (arguments has to gave like this) */
     $arguments = array('command' => 'normalize', 'input' => $input_file);
     $array_input = new ArrayInput($arguments);
     /* Run command */
     $command->run($array_input, $output);
     /* Get structure of YaML file (which was parsed and checked) */
     $struct = $this->getApplication()->data;
     /* Launch Logger module */
     $logger = new ConsoleLogger($output);
     /* This array will contain the new structure */
     $new_struct = array();
     /* The file /etc/os-release contains the informations about the distribution (where is executed this program)*/
     /* TODO Sous Archlinux, la fonction parse_ini_files() ne marchera pas si la variable "open_basedir" du fichier /etc/php/php.ini
      * n'inclue pas le chemin /usr/lib/ (qui est la vraie localisation du fichier "os-release" */
     if (is_file('/etc/os-release')) {
         $array_ini = parse_ini_file('/etc/os-release');
         /* Get the name of the distribution */
         $this->getApplication()->dist_name = ucfirst($array_ini['ID']);
         switch ($this->getApplication()->dist_name) {
             case 'Debian':
                 preg_match('/[a-z]+/', $array_ini['VERSION'], $match);
                 $this->getApplication()->dist_version = ucfirst($match[0]);
                 break;
             case 'Arch':
                 /* TODO Install on Archlinux the package "filesystem" */
                 $this->getApplication()->dist_name = 'Archlinux';
                 break;
             case 'Centos':
                 preg_match('/[0-9](\\.[0-9])?/', $array_ini['VERSION'], $match);
                 $this->getApplication()->dist_version = $match[0];
                 if (strlen($this->getApplication()->dist_version) == 1) {
                     $this->getApplication()->dist_version = $this->getApplication()->dist_version . '.0';
                 }
                 break;
             default:
                 $logger->error($this->getApplication()->translator->trans('prune.exist'));
                 exit(-1);
         }
     } else {
         if (is_file('/etc/arch-release')) {
             $this->getApplication()->dist_name = 'Archlinux';
         } else {
             if (is_file('/etc/centos-release')) {
                 $this->getApplication()->dist_name = 'Centos';
                 if (($version = file_get_contents('/etc/centos-release')) === FALSE) {
                     echo "erreur lecture fichier\n";
                     exit(-1);
                 }
                 preg_match('/[0-9](\\.[0-9])?/', $version, $match);
                 $this->getApplication()->dist_version = $match[0];
             }
         }
     }
     /* Get the architecture of the current machine */
     $this->getApplication()->dist_arch = posix_uname();
     $this->getApplication()->dist_arch = $this->getApplication()->dist_arch['machine'];
     /* Copy the initial structure of the configuration file. The new structure will be modified */
     $new_struct = $struct;
     foreach ($struct['Packages'] as $key => $value) {
         $key_dependencies = array('Build', 'Runtime', 'Test');
         /* For each field (in others words 'Build', 'Runtime' and 'Test') */
         for ($i = 0; $i < 3; ++$i) {
             /* If there are dependencies in the field Build/Runtime/Test */
             if (isset($struct['Packages'][$key][$key_dependencies[$i]]['Dependencies'])) {
                 /* To clear the follow code */
                 $depend_struct = $struct['Packages'][$key][$key_dependencies[$i]]['Dependencies'];
                 /* It has to remove the pre-dependencies structure in the new structure, to keep new "dependency" structure */
                 unset($new_struct['Packages'][$key][$key_dependencies[$i]]['Dependencies']);
                 /* For each dependency */
                 foreach ($depend_struct as $d_key => $d_value) {
                     /* If there is a field having the name of the current distribution */
                     if (isset($depend_struct[$d_key][$this->getApplication()->dist_name])) {
                         if ($this->getApplication()->dist_name != 'Archlinux') {
                             /* The version is referenced (by her name, like for example "wheezy" for Debian ; the version number for CentOS) */
                             if (array_key_exists($this->getApplication()->dist_version, $depend_struct[$d_key][$this->getApplication()->dist_name])) {
                                 $src_field = $this->getApplication()->dist_version;
                                 /* La version est référencée (par le nom de branche, comme par exemple "testing") */
                             } elseif (array_key_exists(array_search($this->getApplication()->dist_version, $this->dv_dist[$this->getApplication()->dist_name]), $depend_struct[$d_key][$this->getApplication()->dist_name])) {
                                 $src_field = array_search($this->getApplication()->dist_version, $this->dv_dist[$this->getApplication()->dist_name]);
                             } else {
                                 /* La version de la distribution en cours d'exécution n'est pas spécifiée, le cas général de la distribution ("All") s'applique donc */
                                 $src_field = 'All';
                             }
                         } else {
                             /* The distribution is Archlinux */
                             /* Archlinux doesn't have versions (rolling release), the content of the field "All" always applies */
                             $src_field = 'All';
                         }
                         /* If the source field contains a array (in others words, the field contains several dependencies) */
                         if (is_array($depend_struct[$d_key][$this->getApplication()->dist_name][$src_field])) {
                             foreach ($depend_struct[$d_key][$this->getApplication()->dist_name][$src_field] as $dependency) {
                                 $new_struct['Packages'][$key][$key_dependencies[$i]]['Dependencies'][] = $dependency;
                             }
                         } else {
                             $new_struct['Packages'][$key][$key_dependencies[$i]]['Dependencies'][] = $depend_struct[$d_key][$this->getApplication()->dist_name][$src_field];
                         }
                     }
                 }
             }
             /* Sometimes, the "Build"/"Runtime"/"Test" section can contains only one dependency (any
              * other keyword). This dependency, for a specific distribution, can be erased (<none>
              * keyword) so the section is empty. If the section is empty, we delete this section */
             if (empty($new_struct['Packages'][$key][$key_dependencies[$i]])) {
                 unset($new_struct['Packages'][$key][$key_dependencies[$i]]);
             }
         }
     }
     $this->getApplication()->data = $new_struct;
     /* Optionnal argument (output file, which will be parsed) */
     $output_file = $input->getArgument('output');
     /* If the optionnal argument is present */
     if ($output_file) {
         /* Get references of the command write() */
         $command = $this->getApplication()->find('write');
         /* Declare the arguments in a array (arguments has to gave like this) */
         $arguments = array('command' => 'write', 'output' => $output_file);
         $array_input = new ArrayInput($arguments);
         /* Run command */
         $command->run($array_input, $output);
     }
 }
 /**
  * Execute the tests.
  *
  * @param InputInterface  $input  An InputInterface instance.
  * @param OutputInterface $output An OutputInterface instance.
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($root = $input->getArgument('root-dir')) {
         chdir(realpath($root));
     }
     $rootDir = realpath(getcwd());
     $logger = new ConsoleLogger($output);
     $composerJson = $rootDir . '/composer.json';
     if (!file_exists($composerJson)) {
         $logger->error('<error>File not found, can not analyze: {file}</error> ', array('file' => $composerJson));
         return 1;
     }
     $destinations = array();
     $destinations[] = new PsrLogDestination($logger);
     $report = $this->prepareReport($input, $logger);
     $composer = json_decode(file_get_contents($composerJson), true);
     $ignore = $this->getIgnoredFiles($composer, $input->getOption('ignore-files'));
     $factory = new AutoloadValidatorFactory($rootDir, new ClassMapGenerator($ignore), $report);
     $test = new AutoloadValidator($factory->createFromComposerJson($composer), $report);
     $test->validate();
     if ($report->hasError()) {
         $logger->error('<error>Testing loaders found errors</error> ');
     }
     $enumLoader = new EnumeratingClassLoader();
     $this->prepareLoader($enumLoader, $test);
     $hacker = new HackPreparator($enumLoader, $logger);
     if ($custom = $input->getOption('add-autoloader')) {
         $hacker->prepareHacks($custom, array($rootDir, dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'hacks'));
     }
     $this->prepareComposerFallbackLoader($enumLoader, $rootDir, $composer);
     if (!($input->getOption('disable-legacy-hacks') || $input->getOption('add-autoloader'))) {
         $hacker->prepareLegacyHack();
     }
     $loadCycle = new AllLoadingAutoLoader($enumLoader, $test->getClassMap(), $logger);
     return static::$exitCodes[$loadCycle->run() && !$report->hasError()];
 }