コード例 #1
0
ファイル: ContainerAware.php プロジェクト: junior0577/crud
 /**
  * @param       $name
  * @param array $parameters
  *
  * @return mixed
  */
 protected function render($name, array $parameters = array())
 {
     $path = CamelCaseHelper::decode(str_replace(array(__NAMESPACE__, '\\', 'Controller'), array(), get_class($this)));
     if ('sis' === substr($path, 0, 3)) {
         $path = 'sis/' . substr($path, 3);
     }
     return $this->get('twig')->render(sprintf('%s/%s', $path, $name), $parameters);
 }
コード例 #2
0
ファイル: GeneratorCommand.php プロジェクト: junior0577/crud
 /**
  * Adicionar rotas no arquivo de rotas
  *
  * @param  string          $table_name
  * @param  array           $data
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  */
 public function createRoutes($table_name, array $data, InputInterface $input, OutputInterface $output)
 {
     $fs = new Filesystem();
     $file_routes = __DIR__ . '/../routes.php';
     if ($fs->exists($file_routes)) {
         $file_contents = array_map(function ($line) {
             return preg_replace('/\\n/', '', $line);
         }, file($file_routes));
         $table_routes = array();
         $exists = array('index' => false, 'list' => false, 'create' => false, 'edit' => false, 'delete' => false);
         $table_lower = strtolower($table_name);
         $table_camel = CamelCaseHelper::encode($table_name, true);
         foreach (array_keys($exists) as $route) {
             $lines_found = array_keys(preg_grep(sprintf('/\'%s::%s\'/i', $table_camel, $route), $file_contents));
             $exists[$route] = count($lines_found) === 1;
         }
         if ($exists['index'] === false) {
             $table_routes[] = "\$route->get(sprintf('/%s/{$table_lower}', \$app['security_path']), '{$table_camel}::index')->bind('{$table_lower}');";
         }
         if ($exists['list'] === false) {
             $table_routes[] = "\$route->get(sprintf('/%s/{$table_lower}/list', \$app['security_path']), '{$table_camel}::list')->bind('{$table_lower}_list');";
         }
         if ($exists['create'] === false) {
             $table_routes[] = "\$route->match(sprintf('/%s/{$table_lower}/create', \$app['security_path']), '{$table_camel}::create')->method('GET|POST')->bind('{$table_lower}_create');";
         }
         if ($exists['edit'] === false) {
             $table_routes[] = "\$route->match(sprintf('/%s/{$table_lower}/edit/{id}', \$app['security_path']), '{$table_camel}::edit')->method('GET|POST')->bind('{$table_lower}_edit');";
         }
         if ($exists['delete'] === false) {
             $table_routes[] = "\$route->get(sprintf('/%s/{$table_lower}/delete/{id}', \$app['security_path']), '{$table_camel}::delete')->bind('{$table_lower}_delete');";
         }
         $last_line = array_keys(preg_grep('/return/', $file_contents))[0];
         // Rewriting
         $rewriting = array();
         $line_blank = 0;
         foreach ($file_contents as $line => $value) {
             // Add routes
             if (count($table_routes) > 0 && $last_line == $line) {
                 $rewriting[] = '// ' . $table_camel;
                 foreach ($table_routes as $route_value) {
                     $rewriting[] = $route_value;
                 }
                 $rewriting[] = '';
             }
             if (strlen(trim($value)) === 0) {
                 $line_blank++;
             } else {
                 $line_blank = 0;
             }
             if ($line_blank <= 1) {
                 $rewriting[] = $value;
             }
         }
         $fs->dumpFile($file_routes, implode("\n", $rewriting));
     }
 }