Cml\Console\IO\Output::writeln PHP Method

writeln() public static method

输出内容并换行
public static writeln ( string $text = '', mixed $pipe = STDOUT )
$text string
$pipe mixed
    public static function writeln($text = '', $pipe = STDOUT)
    {
        self::write("{$text}\n", $pipe);
    }

Usage Example

Example #1
0
 /**
  * 创建控制器
  *
  * @param array $args 参数
  * @param array $options 选项
  */
 public function execute(array $args, array $options = [])
 {
     $template = isset($options['template']) ? $options['template'] : false;
     $template || ($template = __DIR__ . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'Controller.php.dist');
     $name = $args[0];
     $name = explode('-', $name);
     if (count($name) < 2) {
         throw new \InvalidArgumentException(sprintf('The arg name "%s" is invalid. eg: adminbase-Blog/Category', $name));
     }
     $namespace = trim(trim($name[0], '\\/'));
     $path = Cml::getApplicationDir('apps_path') . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . Cml::getApplicationDir('app_controller_path_name') . DIRECTORY_SEPARATOR;
     $component = explode('/', trim(trim($name[1], '/')));
     if (count($component) > 1) {
         $className = ucfirst(array_pop($component)) . Config::get('controller_suffix');
         $component = implode(DIRECTORY_SEPARATOR, $component);
         $path .= $component . DIRECTORY_SEPARATOR;
         $component = '\\' . $component;
     } else {
         $className = ucfirst($component[0]) . Config::get('controller_suffix');
         $component = '';
     }
     if (!is_dir($path) && false == mkdir($path, 0700, true)) {
         throw new \RuntimeException(sprintf('The path "%s" could not be create', $path));
     }
     $contents = strtr(file_get_contents($template), ['$namespace' => $namespace, '$component' => $component, '$className' => $className]);
     if (false === file_put_contents($path . $className . '.php', $contents)) {
         throw new \RuntimeException(sprintf('The file "%s" could not be written to', $path));
     }
     Output::writeln(Colour::colour('Controller created successfully. ', Colour::GREEN));
 }
All Usage Examples Of Cml\Console\IO\Output::writeln