/** * Executes the command. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return object|\Symfony\Component\Console\Output\OutputInterface */ protected function execute(InputInterface $input, OutputInterface $output) { $config = Configuration::get(); $templates = str_replace('Commands', 'Templates', __DIR__); $contents = []; $generator = new ViewGenerator($this->describe); $data = ['{name}' => $input->getArgument('name'), '{pluralTitle}' => Inflector::ucwords(str_replace('_', ' ', Inflector::pluralize($input->getArgument('name')))), '{plural}' => Inflector::pluralize($input->getArgument('name')), '{singular}' => Inflector::singularize($input->getArgument('name'))]; $contents['create'] = $generator->generate($data, $templates, 'create'); $contents['edit'] = $generator->generate($data, $templates, 'edit'); $contents['index'] = $generator->generate($data, $templates, 'index'); $contents['show'] = $generator->generate($data, $templates, 'show'); $fileName = $config->folders->views . '/' . $data['{plural}'] . '/'; $layout = $config->folders->views . '/layouts/master.twig'; if (!$this->filesystem->has($layout)) { $template = file_get_contents($templates . '/Views/layout.twig'); $keywords = ['{application}' => $config->application->name]; $template = str_replace(array_keys($keywords), array_values($keywords), $template); $this->filesystem->write($layout, $template); } foreach ($contents as $type => $content) { $view = $fileName . $type . '.twig'; if ($this->filesystem->has($view)) { if (!$input->getOption('overwrite')) { return $output->writeln('<error>View already exists.</error>'); } else { $this->filesystem->delete($view); } } $this->filesystem->write($view, $content); } return $output->writeln('<info>View created successfully.</info>'); }
/** * Test ucwords functionality with custom delimeters. * * @return void */ public function testUcwordsWithCustomDelimeters() { $this->assertSame('Top-O-The-Morning To All_Of_You!', Inflector::ucwords('top-o-the-morning to all_of_you!', '-_ ')); }
public function ucwords($delimiters = " \n\t\r\v-") { return new static(Inflector::ucwords($this->var, $delimiters)); }
/** * Generates route contents. * * @param string $routeContents * @param string $tableName */ public function generateRoute(&$routeContents, $tableName) { $config = Configuration::get(); $lines = preg_split("/\\r\\n|\\r|\\n/", $routeContents); $endBracket = $lines[count($lines) - 2]; if ($endBracket != '];') { $endBracket = $lines[count($lines) - 1]; } $template = $this->routesTemplate . $endBracket; $routeContents = str_replace($endBracket, $template, $routeContents); $keywords = []; $keywords['{pluralTitle}'] = Inflector::classify(Inflector::pluralize($tableName)); $keywords['{pluralTitleDescription}'] = Inflector::ucwords(str_replace('_', ' ', Inflector::pluralize($tableName))); $keywords['{plural}'] = Inflector::pluralize($tableName); $keywords['{application}'] = $config->application->name; $keywords['{namespace}'] = $config->namespaces->controllers; $routeContents = str_replace(array_keys($keywords), array_values($keywords), $routeContents); }