Exemplo n.º 1
0
 /**
  * Display info & available tasks
  */
 public function info()
 {
     echo Console::color("Run some CLI task\n", 'cyan', Console::INVERSE);
     echo "\tphp index.php " . Console::color('--module=', null, Console::BOLD_BRIGHT) . Console::color($this->router->getDefaultModule(), 'red') . ' ' . Console::color('--handler=', null, Console::BOLD_BRIGHT) . Console::color($this->router->getDefaultHandler(), 'blue') . ' ' . Console::color('--action=', null, Console::BOLD_BRIGHT) . Console::color($this->router->getDefaultAction(), 'green') . ' ' . Console::color('--id=', null, Console::BOLD_BRIGHT) . Console::color('1', 'yellow') . ' ' . Console::color('--param=', null, Console::BOLD_BRIGHT) . Console::color('"some value"', 'yellow') . PHP_EOL;
     echo PHP_EOL . Console::color("Available tasks:", null, Console::UNDERLINE) . PHP_EOL;
     foreach ($this->console->getModules() as $name => $module) {
         (new Loader())->addNamespace($module['namespace'] . '\\Tasks', $module['path'] . '/tasks/')->register();
         // Module name
         echo '-' . $name . PHP_EOL;
         foreach (new \DirectoryIterator($module['path'] . 'tasks/') as $file) {
             if ($file->isDot()) {
                 continue;
             }
             $task = $file->getBasename('.php');
             $class = $module['namespace'] . '\\Tasks\\' . $task;
             // Handler name
             echo '  -' . strtolower(strstr($task, 'Task', true)) . PHP_EOL;
             $f = new \ReflectionClass($class);
             foreach ($f->getMethods() as $m) {
                 if ($m->class == $class && strpos($m->name, 'Action') !== false) {
                     // Action name
                     echo '    -' . strstr($m->name, 'Action', true) . PHP_EOL;
                 }
             }
         }
     }
     echo PHP_EOL;
 }
Exemplo n.º 2
0
 /**
  * Help to find untranslated messages
  * Parameters:
  *  0: lang, eg. pl
  */
 public function langAction()
 {
     $lang = $this->dispatcher->getParam(0, null, 'en', true);
     $dir = '/app/';
     $scan = [];
     foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__ROOT__ . $dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
         if (!$item->isDir() && in_array($item->getExtension(), ['php', 'sleet'])) {
             $content = file_get_contents(__ROOT__ . $dir . $iterator->getSubPathName());
             preg_match_all('/(?:field\\s=\\s|_t\\()[\'"]([^\'"]+)/i', $content, $matches);
             if (count($matches[1])) {
                 foreach ($matches[1] as $value) {
                     $scan[$value] = "";
                 }
             }
         }
     }
     $path = $this->config->i18n->dir . $lang . '.php';
     $file = file_exists($path) ? include_once $path : [];
     $merge = array_merge($scan, $file);
     ksort($merge);
     foreach ($merge as $key => $value) {
         if (isset($file[$key]) && isset($scan[$key])) {
             $color = null;
         } elseif (!isset($file[$key]) && isset($scan[$key])) {
             $color = 'green';
         } elseif (isset($file[$key]) && !isset($scan[$key])) {
             $color = 'yellow';
         } else {
             $color = 'red';
         }
         echo Console::color("    '" . $key . "' => '" . $value . "'," . PHP_EOL, $color);
     }
 }