Beispiel #1
0
 public function execute(Stdio $stdio, array $params = [])
 {
     if (strpos($params['source'], 'data/') !== 0) {
         throw new \DomainException('The source must be in the data directory.');
     }
     if (strpos($params['target'], 'data/') !== 0) {
         throw new \DomainException('The target must be in the data directory.');
     }
     $params['source'] = substr($params['source'], strlen('data/'));
     $params['target'] = substr($params['target'], strlen('data/'));
     $match = preg_match('/^(?:.*?\\/)?([0-9]{4}-[0-9]{2}-[0-9]{2}\\.|[0-9]+\\.|)([^\\/]*)$/', $params['source'], $matches);
     $matches[1] = trim($matches[1], '.');
     if ($params['--date']) {
         $matches[1] = (new \DateTime())->format('Y-m-d');
     }
     if ($params['--title']) {
         $matches[2] = \URLify::filter($params['--title']);
     }
     $file = trim($params['target'], '/') . '/';
     $file .= $params['--date'] ? $matches[1] . '.' : '';
     $file .= $matches[2];
     $this->hooks->call('before.move');
     $this->data->move($params['source'], $file);
     if ($params['--title']) {
         $data = $this->data->read($file);
         $data['title'] = $params['--title'];
         $this->data->write($file, $data);
     }
     $stdio->outln('<<magenta>>' . $params['source'] . ' moved to ' . $file . '<<reset>>');
     $this->hooks->call('after.move');
     return Status::SUCCESS;
 }
 /**
  * Called when this object is called as a function
  *
  * @param Help $help
  * @param HelpableCommandInterface $subCommand
  */
 public function __invoke(Help $help, HelpableCommandInterface $subCommand = null)
 {
     if ($subCommand !== null) {
         $subCommand->configureHelp($help);
     }
     $this->stdio->outln($help->getHelp('shootproof-cli'));
 }
Beispiel #3
0
 /**
  * Run tasks
  *
  * @throw \Exception
  * @return void
  */
 public function runTasks()
 {
     try {
         $this->collectInformation();
         # Renamer
         (new \Aijko\Typo3Helper\Task\Renamer\Typo3\RenameContentTask())->execute(Registry::get('targetPath'));
         $this->cliStdio->outln('');
         $this->cliStdio->outln('Finish');
     } catch (\Exception $e) {
         $this->cliStdio->errln($e->getMessage());
     }
 }
Beispiel #4
0
 /**
  * @return int Status code to exit with
  */
 public function run()
 {
     $queue = $this->context->argv->get(1);
     if (!$queue) {
         $this->stdio->outln('<<red>>No queue specified<<reset>>');
         return Status::USAGE;
     }
     while (call_user_func($this->listener)) {
         $this->consumer->consume($queue);
     }
     return Status::SUCCESS;
 }
Beispiel #5
0
 /**
  * @return int Status code to exit with
  */
 public function run()
 {
     $env = $this->context->env;
     $tube = $env->get('BEANSTALKD_TUBE') ?: 'default';
     $class = $env->get('BEANSTALKD_CONSUMER');
     if (!$class) {
         $this->stdio->outln('<<red>>BEANSTALKD_CONSUMER environmental variable is not set<<reset>>');
         return Status::USAGE;
     }
     if (!class_exists($class)) {
         $this->stdio->outln(sprintf('<<red>>BEANSTALKD_CONSUMER does not reference a locatable class: %s<<reset>>', $class));
         return Status::DATAERR;
     }
     if (!in_array(ConsumerInterface::class, class_implements($class))) {
         $this->stdio->outln(sprintf('<<red>>BEANSTALKD_CONSUMER references a class that does not implement ConsumerInterface: %s<<reset>>', $class));
         return Status::DATAERR;
     }
     $this->pheanstalk->watchOnly($tube);
     $consumer = call_user_func($this->resolver, $class);
     while (call_user_func($this->listener)) {
         $reserved = $this->pheanstalk->reserve();
         if (!$reserved) {
             continue;
         }
         $job = new Job($reserved->getId(), $reserved->getData());
         try {
             $result = $consumer->consume($job);
             if ($result === false) {
                 $this->pheanstalk->release($job);
                 continue;
             }
         } catch (\Exception $e) {
             $this->pheanstalk->release($job);
             throw $e;
         }
         $this->pheanstalk->delete($job);
     }
     return Status::SUCCESS;
 }
 public function execute(Stdio $stdio, array $params = [])
 {
     $this->hooks->call('before.publish');
     foreach ($this->source_filesystem->listContents('/base/', true) as $file) {
         $path = substr(trim($file['path'], '/'), 5);
         if ($file['type'] == 'file') {
             if (!$this->site_filesystem->has(dirname($path))) {
                 $this->site_filesystem->createDir(dirname($path));
             }
             $this->site_filesystem->put($path, $this->source_filesystem->read($file['path']));
         }
     }
     $defaults = $this->settings->read('defaults');
     $site = new SiteModel($this->schema->getConnection());
     if ($site) {
         foreach ($site->pages() as $page_model) {
             $permalink = $page_model->permalink;
             $pages = [$permalink => $defaults + ['page' => $page_model]];
             if ($page_model->middleware) {
                 $page_model->middleware = json_decode($page_model->middleware);
                 foreach ($page_model->middleware as $name => $arguments) {
                     $arguments = $arguments ? $arguments : [];
                     $pages = $this->middleware->call($name, $pages, $arguments);
                 }
             }
             foreach ($pages as $permalink => $page) {
                 if (substr($permalink, -1) == '/') {
                     $permalink .= 'index.html';
                 }
                 $response = $this->view->render($page_model->template, $page);
                 $this->site_filesystem->put($permalink, $response);
             }
         }
     }
     $stdio->outln('<<magenta>>Site published on ' . (new \DateTime())->format('Y-m-d') . '<<reset>>');
     $this->hooks->call('after.publish');
     return Status::SUCCESS;
 }
Beispiel #7
0
 public function execute(Stdio $stdio, array $params = [])
 {
     if (strpos($params['target'], 'data/') !== 0) {
         throw new \DomainException('The target must be in the data directory.');
     }
     $params['target'] = substr($params['target'], strlen('data/'));
     if (!empty($params['--related'])) {
         foreach ($params['--related'] as $key => $related) {
             if (strpos($related, 'data/') !== 0) {
                 throw new \DomainException('Each --related must be in the data directory.');
             }
             $params['--related'][$key] = substr(dirname($related), strlen('data/')) . '/' . pathinfo($related, PATHINFO_FILENAME);
         }
     }
     $data = [];
     foreach (['title', 'summary', '--related'] as $param_key) {
         if (!empty($params[$param_key])) {
             $data[trim($param_key, '-')] = $params[$param_key];
         }
     }
     $file = '';
     if ($params['target']) {
         $file = trim($params['target'], '/') . '/';
     }
     if ($params['--date']) {
         $file .= (new \DateTime())->format('Y-m-d') . '.';
     }
     $file .= \URLify::filter($data['title']);
     $file .= $params['--ext'] ? $params['--ext'] : '.md';
     $file = trim($file, '/');
     $this->hooks->call('before.make');
     $this->data->write($file, $data);
     $stdio->outln('<<magenta>>' . $file . ' published on ' . (new \DateTime())->format('Y-m-d') . '<<reset>>');
     $this->hooks->call('after.make');
     return Status::SUCCESS;
 }
Beispiel #8
0
 /**
  * Gets user input from the command line and trims the end-of-line.
  *
  * @return string
  */
 public function in()
 {
     $this->out(' <<yellow>>><<reset>> ');
     return parent::in();
 }
Beispiel #9
0
 /**
  * @param string $string
  */
 public function errln($string)
 {
     $this->stdio->errln("<<red>>{$string}<<reset>>");
 }