Example #1
0
 /**
  * {@inheritdoc}
  */
 public function slash()
 {
     $app_path = str_replace(config('path.root'), '', config()->path->app);
     $arg_name = studly_case(str_slug($this->input->getArgument('name'), '_'));
     $stub = file_get_contents(__DIR__ . '/stubs/makeRoute.stub');
     $stub = stubify($stub, ['routeName' => $arg_name, 'prefixRouteName' => strtolower($arg_name)]);
     $file_name = $arg_name . 'Routes.php';
     $module = $this->input->getArgument('module');
     $has_dir = is_dir(config()->path->app . $module);
     if ($has_dir === false) {
         $this->error('Module not found `' . $module . '`');
         return;
     }
     $module = $this->input->getArgument('module');
     if ($this->app->has($module) === false) {
         $this->error('Module not found `' . $module . '`');
         return;
     }
     $routes = $module . '/routes/';
     if ($this->app->has($routes) === false) {
         $this->error('Routes folder not found from your module: `' . $module . '`');
         return;
     }
     $stub = stubify($stub, ['namespace' => path_to_namespace($app_path . $routes), 'controllerNamespace' => path_to_namespace($app_path . $module . '/controllers/')]);
     $this->info('Crafting Route...');
     if ($this->app->has($file_name)) {
         $this->error('   Route already exists!');
         return;
     }
     $this->app->put($routes . $file_name, $stub);
     $this->info('   ' . $file_name . ' created!');
     $this->callDumpAutoload();
 }
 /**
  * {@inheritdoc}
  */
 public function slash()
 {
     $arg_name = ucfirst($this->input->getArgument('name'));
     $stub = file_get_contents(__DIR__ . '/stubs/makeConsole.stub');
     $stub = stubify($stub, ['consoleName' => $arg_name]);
     $file_name = $arg_name . '.php';
     chdir(config()->path->console);
     $this->comment('Crafting Console...');
     if (file_exists($file_name)) {
         $this->error('   Console already exists!');
     } else {
         file_put_contents($file_name, $stub);
         $this->info('   Console has been created!');
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function slash()
 {
     # introduction
     $this->block('Welcome to the New Vendor config generator');
     $composer = new Composer();
     $package = '';
     $default = 'root/' . basename(realpath(''));
     $composer->set('name', $package = $this->ask('Package name (<vendor>/<name>) [' . $default . ']: ', $default));
     $composer = $this->otherComposerKeys($composer);
     $composer->set('autoload', ['psr-4' => [path_to_namespace($package) . '\\' => 'src/']]);
     $validation = $composer->validate();
     if ($validation['valid'] === false) {
         $this->error(json_encode($validation['errors']));
         return;
     }
     # get the file/folder writer
     $sandbox = $this->getFlysystem();
     # craft vendor folder
     $generated_path = url_trimmer($this->getSandboxPath() . $package);
     if ($sandbox->has($package) === false) {
         $this->comment("Crafting vendor folder at {$generated_path}");
         $sandbox->createDir($package);
     } else {
         $this->comment("Re-using vendor folder at {$generated_path}");
     }
     # build src folder
     if ($sandbox->has($path = $package . '/src') === false) {
         $this->comment('    - building /src folder');
         $sandbox->createDir($path);
     }
     # build the composer.json file
     if ($sandbox->has($path = url_trimmer($package . '/composer.json')) === false) {
         $this->comment('    - building composer.json file');
         $sandbox->put($path, $composer->render());
     }
     # craft <Package>ServiceProvider.php inside src/ folder
     $content = stubify($this->stubContent(), ['namespace' => path_to_namespace($package), 'serviceFile' => $service_file = path_to_namespace(basename($package)) . 'ServiceProvider']);
     if ($sandbox->has($path = $package . '/src/' . $service_file . '.php') === false) {
         $this->comment('    - building service provider class');
         $sandbox->put($path, $content);
     }
     # rebuild the base composer.json
     $composer->config(file_get_contents(base_path('composer.json')));
     if (isset($composer->toArray()['require'][$package])) {
         $this->error('Vendor already exists');
         return;
     }
     $composer->merge('require', [$package => '*']);
     $repo = str_replace(realpath('') . '/', '', $this->getSandboxPath()) . $package;
     $composer->merge('repositories', [$repo => ['type' => 'path', 'url' => $repo]]);
     $validation = $composer->validate();
     if ($validation['valid'] === false) {
         $this->error(json_encode($validation['errors']));
         return;
     }
     $this->comment('    - updating base composer.json');
     file_put_contents(base_path('composer.json'), $composer->render());
     $this->info('New vendor loaded, please run the following command:');
     $this->info(' - composer update');
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function slash()
 {
     $app_filesystem = flysystem_manager($this->getAppPath());
     $raw_module = $this->getModuleName(false);
     $module = $this->getModuleName();
     # check if module exists, throw error if it doesn't exists
     if ($app_filesystem->has($module) === false) {
         $this->error("Module [{$module}] not found");
         return;
     }
     $this->info('Crafting Route Group...');
     $route = $this->getRouteName();
     # check route file if exists, throw error if exists
     if ($app_filesystem->has($module . '/' . $route)) {
         $this->error("     Route [{$this->input->getArgument('name')}] " . "already exists in your Module [{$this->input->getArgument('module')}]");
         return;
     }
     # get the route stub and stubify the {routeName}
     # based on argument route name
     $buff = stubify($this->getRouteStub(), ['namespace' => path_to_namespace(str_replace($this->getBasePath(), '', $this->getNamespace())), 'routeName' => $this->getRouteName(false), 'routeFunctions' => $this->getRouteFunctions()]);
     # now write the content based on $route path
     $module_filesystem = flysystem_manager($this->getModulePath());
     $module_filesystem->put($route, $buff);
     $this->info('     ' . $route . ' created!');
 }
Example #5
0
 /**
  * Get the content with 'namespace' by stubifying the
  * provided content.
  *
  * @param $stub_content
  * @return string
  */
 private function getContentByStub($stub_content)
 {
     return stubify($stub_content, ['namespace' => path_to_namespace(str_replace($this->getBasePath(), '', $this->getNamespace()))]);
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function slash()
 {
     $app_filesystem = flysystem_manager($this->getAppPath());
     $module = $this->getModuleName();
     # check if module exists, throw error if it doesn't exists
     if ($app_filesystem->has($module) === false) {
         $this->error("Module [{$module}] not found");
         return;
     }
     $this->info('Crafting Controller...');
     $controller = $this->getControllerName();
     # check controller file if exists, throw error if exists
     if ($app_filesystem->has($module . '/' . $controller)) {
         $this->error("     Controller [{$this->input->getArgument('name')}] " . "already exists in your Module [{$this->input->getArgument('module')}]");
         return;
     }
     # get the controller stub and stubify the {controllerName}
     # based on argument controller name
     $buff = stubify($this->getControllerStub(), ['namespace' => path_to_namespace(str_replace($this->getBasePath(), '', $this->getNamespace())), 'controllerName' => $this->getControllerName(false), 'controllerFunctions' => $this->getControllerFunctions()]);
     # now write the content based on $controller path
     $module_filesystem = flysystem_manager($this->getModulePath());
     $module_filesystem->put($controller, $buff);
     $this->info('     ' . $controller . ' created!');
     $this->callDumpAutoload();
 }