public function testTwo() { $verbosityLevelMap = array(LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL); $formatLevelMap = array(LogLevel::CRITICAL => ConsoleLogger::INFO, LogLevel::DEBUG => ConsoleLogger::ERROR); $logger = new ConsoleLogger(new ConsoleOutput(), $verbosityLevelMap, $formatLevelMap); $logger->alert("On Envoie du looooooooooooog"); }
protected function execute(InputInterface $input, OutputInterface $output) { $methodArg = $input->getArgument('method'); $apiOption = $input->getOption('api'); $params = array(); if ($input->hasOption('params')) { parse_str($input->getOption('params'), $params); } $this->logger = new ConsoleLogger($output); $method = $this->getMethod($methodArg, $apiOption); $this->logger->info("Calling api..."); $this->logger->info("- method: " . $method->name()); $this->logger->info("- url: " . $method->url()); if ($params) { $this->logger->info("- extra params: "); $this->logger->info(var_export($params, true)); } $response = $method->call($params); $this->logger->info('Finished'); if ($input->getOption('show-response') && $response instanceof ResponseInterface) { $this->logger->info('Response:'); $this->logger->info("- status code: " . $response->getStatusCode()); $this->logger->info("- body: " . $response->getBody()->getContents()); } }
public static function clean($file, ConsoleLogger $logger) { if (unlink($file)) { $logger->log(LogLevel::INFO, 'Deleted file: ' . $file); } else { $logger->log(LogLevel::NOTICE, 'Could not delete file "' . $file . '"'); } }
public static function createFilesDir(array $data, $directory, ConsoleLogger $logger) { if (is_dir(self::path($directory, 'sites', 'default', 'files')) && !fileperms(self::path($directory, 'sites', 'default', 'files')) !== 0755) { if (!chmod(self::path($directory, 'sites', 'default', 'files'), 0755)) { throw new Exception('Could not change permissions of files directory in directory "' . $directory . '"!'); } $logger->log(LogLevel::INFO, 'Files dir exist and is writable'); } else { if (!mkdir(self::path($directory, 'sites', 'default', 'files'), 0755)) { throw new Exception('Could not create new files dir with all permissions in directory "' . $directory . '"!'); } $logger->log(LogLevel::INFO, 'Files dir created'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $logger = new ConsoleLogger($output, self::VERBOSITY_LEVEL_MAP); $timestamp = ($timestamp = $input->getArgument('timestamp')) ? intval($timestamp) : null; $users = $this->getContainer()->get('bdn_connector')->updateCommunityUsers($timestamp); if (!empty($users['new'])) { foreach ($users['new'] as $user) { $logger->info('Added new user: '******'updated'])) { foreach ($users['updated'] as $user) { $logger->info('Updated user: ' . $user); } } }
/** * {@inheritdoc} */ public function log($level, $message, array $context = array()) { parent::log($level, $message, $context); if (isset($this->errorLevels[$level])) { $this->errored = true; } }
/** * Instantiate the tasks to process. * * @param ConfigurationValues $config The configuration values. * * @return Filter * * @throws \InvalidArgumentException When an unknown filter type has been configured. */ private function buildFilters($config) { $collections = []; foreach ($config->get('rewrites') as $filterConfig) { $filters = []; foreach ($filterConfig['filter'] as $filter) { $this->logger->info('instantiate filter ' . $filter['type']); switch ($filter['type']) { case 'replace': $filters[] = new Filter\ReplaceStringFilter($filter); break; case 'php-strip': $filters[] = new Filter\PhpStripWhiteSpaceFilter($filter); break; case 'warning-time': $filters[] = new Filter\ReplaceStringWithTimestamp($filter); break; default: throw new \InvalidArgumentException('Unknown filter type: ' . $filter['type']); } } $collections[] = new Filter\Collection($filterConfig['files'], $filters); } return new Filter($collections); }
protected function execute(InputInterface $input, OutputInterface $output) { $logger = new ConsoleLogger($output); $updater = new Updater(null, false, Updater::STRATEGY_GITHUB); /** @var GithubStrategy $strategy */ $strategy = $updater->getStrategy(); $strategy->setPackageName('icehawk/component-template-generator'); $strategy->setPharName('icehawk-ctg.phar'); $strategy->setCurrentLocalVersion('@package_version@'); if ($updater->rollback()) { $logger->info('Roll back successful!'); } else { $logger->alert('Roll back failed.'); } return 0; }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $input->validate(); $logger = new ConsoleLogger($output); $updater = new Updater(null, false, Updater::STRATEGY_GITHUB); /** @var GithubStrategy $strategy */ $strategy = $updater->getStrategy(); $strategy->setPackageName(PharTool::PACKAGE_NAME); $strategy->setPharName(PharTool::PHAR_NAME); $strategy->setCurrentLocalVersion('@package_version@'); if ($updater->rollback()) { $logger->info('Roll back successful!'); } else { $logger->alert('Roll back failed.'); } return 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; } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $logger = new ConsoleLogger($output); $updater = new Updater(null, false, Updater::STRATEGY_GITHUB); /** @var GithubStrategy $strategy */ $strategy = $updater->getStrategy(); $strategy->setPackageName(PharTool::PACKAGE_NAME); $strategy->setPharName(PharTool::PHAR_NAME); $strategy->setCurrentLocalVersion('@package_version@'); $stability = $input->getOption('stability'); $strategy->setStability($stability); try { if ($updater->hasUpdate()) { $newVersion = $updater->getNewVersion(); $logger->info(sprintf('The current stable version available is: %s', $newVersion)); $logger->info('Updating...'); if ($updater->update()) { $logger->info(sprintf('Successful! You now have version %s installed', $newVersion)); } } elseif (false === $updater->getNewVersion()) { $logger->alert('There is no stable version available.'); } else { $logger->info('@package_version@ is the latest stable version.'); } return 0; } catch (HttpRequestException $e) { $logger->alert('Error fetching current version from remote repository.'); return 1; } }
/** * @param ConsoleLogger $logger * @param Config $config */ public function logServerConfig(ConsoleLogger $logger, Config $config) { $logger->info("* config port :" . $config->getPort()); $logger->info("* config log_file :" . $config->getLogFile()); $logger->info("* config pid_file :" . $config->getPidFile()); $logger->info("* config classpaths :" . implode(',', $config->getClasspaths())); $logger->info("* config java_bin :" . $config->getJavaBin()); $logger->info("* config server_jar :" . $config->getServerJar()); }
/** * deleteStandByAnnonce * * This method delete the annonce that a left in standby status by the passerelle's process. * It's mean that they are not present in the XML source anymore. The images associated with the annonce are deleted two. * * @param void */ private function deleteStandByAnnonce() { $this->oLogger->info("Delete Annonce still in standby"); $aAnnonceEntities = $this->oEm->getRepository('JLPCoreBundle:Annonce')->findBy(array('statusAnnonce' => 'standby')); $this->iNbAnnonceSuppr = count($aAnnonceEntities); foreach ($aAnnonceEntities as $oAnnonce) { $aImagesCollection = $oAnnonce->getImages(); $this->deleteImages($aImagesCollection); $this->oEm->remove($oAnnonce); } $this->oEm->flush(); }
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); }
protected function execute(InputInterface $input, OutputInterface $output) { $logger = new ConsoleLogger($output); $updater = new Updater(null, false, Updater::STRATEGY_GITHUB); /** @var GithubStrategy $strategy */ $strategy = $updater->getStrategy(); $strategy->setPackageName('icehawk/component-template-generator'); $strategy->setPharName('icehawk-ctg.phar'); $strategy->setCurrentLocalVersion('@package_version@'); $stability = $input->getOption('stability'); $strategy->setStability($stability); if ($updater->hasUpdate()) { $newVersion = $updater->getNewVersion(); $logger->info(sprintf('The current stable version available is: %s', $newVersion)); $logger->info('Updating...'); if ($updater->update()) { $logger->info(sprintf('Successful! You now have version %s installed', $newVersion)); } } elseif (false === $updater->getNewVersion()) { $logger->alert('There is no stable version available.'); } else { $logger->info('@package_version@ is the latest stable version.'); } return 0; }
public static function installDatabase(array $data, $directory, ConsoleLogger $logger) { // need for wordpress database functionality global $wpdb; if (!isset($data['blog_title'])) { $logger->log(LogLevel::NOTICE, 'Skipping step due to missing blog configuration'); return true; } define('WP_INSTALLING', true); require_once self::path($directory, 'wp-config.php'); // require_once self::path($directory, 'includes', 'wp-db.php'; require_once self::path($directory, 'wp-admin', 'upgrade-functions.php'); if (!function_exists('wp_install')) { $logger->log(LogLevel::WARNING, 'Could not find function "wp_install" in file "' . self::path($directory, 'wp-admin', 'includes', 'upgrade.php"')); } if (isset($data['password'])) { $logger->log(LogLevel::INFO, 'Using password: '******'password']); $result = wp_install($data['blog_title'], $data['admin'], $data['admin_email'], true, '', $data['password']); } else { $result = wp_install($data['blog_title'], $data['admin'], $data['admin_email'], true); } if ($result) { $logger->log(LogLevel::INFO, 'Wordpress successfully installed. Password is ' . $result['password']); } else { $logger->log(LogLevel::WARNING, 'Unexpected error occured during this step'); } return $result; }
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()); }
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; } }
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); }
/** * 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()]; }
/** * @param string $filename * @param int $verbosity */ public function __construct($filename, $verbosity = OutputInterface::VERBOSITY_NORMAL) { $this->filename = $filename; $this->verbosity = $verbosity; parent::__construct($this->createStream($filename, $verbosity)); }
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); } }