예제 #1
0
 /**
  * @param $name
  * @param $type
  * @param $path
  * @throws Exception
  * @throws FileNotFoundException
  */
 public function updateUpIndex($name, $type, $path)
 {
     $indexPath = "{$path}/../index.ts";
     $statement = "export * from './" . $name . "';\n";
     $fileContent = File::get($indexPath);
     // Clean up the new line characters as different operating
     // systems put different characters for line breaks.
     $fileContent = str_replace(["\r", "\n"], '', $fileContent);
     $fileContent = explode(';', $fileContent);
     $fileContent = implode(";\n", $fileContent);
     File::delete($indexPath);
     File::append($indexPath, $fileContent . $statement);
     $this->info("Updated {$this->normalize($path . "./../index.ts")}.");
 }
예제 #2
0
 /**
  * Execute the command.
  */
 public function handle()
 {
     $name = $this->argument('name');
     $domain = $this->argument('domain');
     $webExecution = $this->option('webExecution');
     try {
         $workingPath = base_path('../');
         $outputFolder = strtolower(str_replace(' ', '-', $name . '-api'));
         $this->writeStatus('Installing lumen and dependencies ...', $webExecution);
         // Create project
         (new Composer($workingPath))->createProject('laravel/lumen', '5.1.*', $outputFolder)->setWorkingPath($workingPath . $outputFolder)->requirePackage('dingo/api', '1.0.x@dev');
         $this->writeStatus('Setting up lumen ...', $webExecution);
         // Rename .env file
         File::move($workingPath . $outputFolder . '/.env.example', $workingPath . $outputFolder . '/.env');
         // Dingo config
         File::append($workingPath . $outputFolder . '/.env', 'API_DOMAIN=' . $domain . PHP_EOL . 'API_STANDARDS_TREE=vnd' . PHP_EOL . 'API_SUBTYPE=' . strtolower(str_replace(' ', '', $name)) . PHP_EOL . 'API_VERSION=v1' . PHP_EOL . 'API_NAME="' . $name . '"' . PHP_EOL . 'API_CONDITIONAL_REQUEST=false' . PHP_EOL . 'API_STRICT=false' . PHP_EOL . 'API_DEFAULT_FORMAT=json' . PHP_EOL . 'API_DEBUG=true');
         // Get lumen app file
         $lumenAppFile = File::get($workingPath . $outputFolder . '/bootstrap/app.php');
         // Get .env file
         $lumenEnvFile = File::get($workingPath . $outputFolder . '/.env');
         // Enable Dotenv
         $lumenAppFile = str_replace('// Dotenv::load(__DIR__.\'/../\');', 'Dotenv::load(__DIR__.\'/../\');', $lumenAppFile);
         // Enable Eloquent
         $lumenAppFile = str_replace('// $app->withEloquent();', '$app->withEloquent();', $lumenAppFile);
         // Add Dingo service provider
         $registerServiceProviderPosition = strpos($lumenAppFile, 'Register Service Providers');
         $lumenAppFile = substr($lumenAppFile, 0, $registerServiceProviderPosition + 322) . '$app->register(Dingo\\Api\\Provider\\LumenServiceProvider::class);' . substr($lumenAppFile, $registerServiceProviderPosition + 320);
         // Database config
         $lumenEnvFile = str_replace('DB_DATABASE=homestead', 'DB_DATABASE=' . env('DB_DATABASE', 'homestead'), $lumenEnvFile);
         $lumenEnvFile = str_replace('DB_USERNAME=homestead', 'DB_USERNAME='******'DB_USERNAME', 'homestead'), $lumenEnvFile);
         $lumenEnvFile = str_replace('DB_PASSWORD=secret', 'DB_PASSWORD='******'DB_PASSWORD', 'secret'), $lumenEnvFile);
         File::put($workingPath . $outputFolder . '/.env', $lumenEnvFile);
         File::put($workingPath . $outputFolder . '/bootstrap/app.php', $lumenAppFile);
     } catch (\Exception $exception) {
         $this->writeStatus('Error', $webExecution);
         Log::error($exception->getMessage());
     }
 }
 public function generateAll()
 {
     $resources = APIResource::where('route', true)->get();
     $router = $this->generateRouter($resources);
     $file = app_path() . '/Http/routes.php';
     $delimiter = '/**  GENERATE BY iramgutierrez/laravel-resource-api DO NOT REMOVE **/';
     $contentRoutes = "";
     $contentRoutes .= $delimiter;
     $contentRoutes .= "\n";
     $contentRoutes .= "\n";
     /* NAMESPACES */
     foreach ($router['namespaces'] as $namespace => $ns) {
         $contentRoutes .= "Route::group(['namespace' => '" . $namespace . "'";
         $contentRoutes .= '] , function() {';
         $contentRoutes .= "\n";
         /* NAMESPACES PREFIXES */
         foreach ($ns['prefixes'] as $prefix => $p) {
             $contentRoutes .= "    Route::group(['prefix' => '" . $prefix . "'";
             $contentRoutes .= '] , function() {';
             $contentRoutes .= "\n";
             /* NAMESPACES PREFIXES MIDDLEWARE */
             foreach ($p['middlewares'] as $middleware => $mw) {
                 $middleware = "['" . str_replace(',', "','", $middleware) . "']";
                 $contentRoutes .= "        Route::group(['middleware' => " . $middleware;
                 $contentRoutes .= '] , function() {';
                 $contentRoutes .= "\n";
                 /* NAMESPACES PREFIXES MIDDLEWARE ROUTES */
                 foreach ($mw['routes'] as $r => $route) {
                     $contentRoutes .= "            Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
                     $contentRoutes .= "\n";
                 }
                 /* NAMESPACES PREFIXES MIDDLEWARE ROUTES */
                 $contentRoutes .= '        });';
                 $contentRoutes .= "\n";
             }
             /* NAMESPACES PREFIXES MIDDLEWARE */
             /* NAMESPACES PREFIXES ROUTES */
             foreach ($p['routes'] as $r => $route) {
                 $contentRoutes .= "        Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
                 $contentRoutes .= "\n";
             }
             /* NAMESPACES PREFIXES ROUTES */
             $contentRoutes .= '    });';
             $contentRoutes .= "\n";
         }
         /* NAMESPACES PREFIXES */
         /* NAMESPACES MIDDLEWARES */
         foreach ($ns['middlewares'] as $middleware => $mw) {
             $middleware = "['" . str_replace(',', "','", $middleware) . "']";
             $contentRoutes .= "    Route::group(['middleware' => " . $middleware;
             $contentRoutes .= '] , function() {';
             $contentRoutes .= "\n";
             /* NAMESPACES MIDDLEWARES ROUTES */
             foreach ($mw['routes'] as $r => $route) {
                 $contentRoutes .= "        Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
                 $contentRoutes .= "\n";
             }
             /* NAMESPACES MIDDLEWARES ROUTES */
             $contentRoutes .= '    });';
             $contentRoutes .= "\n";
         }
         /* NAMESPACES MIDDLEWARES */
         /* NAMESPACES ROUTES */
         foreach ($ns['routes'] as $r => $route) {
             $contentRoutes .= "    Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
             $contentRoutes .= "\n";
         }
         /* NAMESPACES ROUTES */
         $contentRoutes .= '});';
         $contentRoutes .= "\n";
     }
     /* NAMESPACES */
     /* PREFIXES */
     foreach ($router['prefixes'] as $prefix => $p) {
         $contentRoutes .= "Route::group(['prefix' => '" . $prefix . "'";
         $contentRoutes .= '] , function() {';
         $contentRoutes .= "\n";
         /* PREFIXES MIDDLEWARES */
         foreach ($p['middlewares'] as $middleware => $mw) {
             $middleware = "['" . str_replace(',', "','", $middleware) . "']";
             $contentRoutes .= "    Route::group(['middleware' => " . $middleware;
             $contentRoutes .= '] , function() {';
             $contentRoutes .= "\n";
             /* PREFIXES MIDDLEWARES ROUTES */
             foreach ($mw['routes'] as $r => $route) {
                 $contentRoutes .= "        Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
                 $contentRoutes .= "\n";
             }
             /* PREFIXES MIDDLEWARES ROUTES */
             $contentRoutes .= '    });';
             $contentRoutes .= "\n";
         }
         /* PREFIXES MIDDLEWARES */
         /* PREFIXES ROUTES */
         foreach ($p['routes'] as $r => $route) {
             $contentRoutes .= "    Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
             $contentRoutes .= "\n";
         }
         /* PREFIXES ROUTES */
         $contentRoutes .= '});';
         $contentRoutes .= "\n";
     }
     /* PREFIXES */
     /* MIDDLEWARES */
     foreach ($router['middlewares'] as $middleware => $mw) {
         $middleware = "['" . str_replace(',', "','", $middleware) . "']";
         $contentRoutes .= "Route::group(['middleware' => " . $middleware;
         $contentRoutes .= '] , function() {';
         $contentRoutes .= "\n";
         /* MIDDLEWARES ROUTES */
         foreach ($mw['routes'] as $r => $route) {
             $contentRoutes .= "    Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
             $contentRoutes .= "\n";
         }
         /* MIDDLEWARES ROUTES */
         $contentRoutes .= '});';
         $contentRoutes .= "\n";
     }
     /* MIDDLEWARES */
     /* ROUTES */
     foreach ($router['routes'] as $r => $route) {
         $contentRoutes .= "Route::resource('" . $route['path'] . "' , '" . $route['controller'] . "');";
         $contentRoutes .= "\n";
     }
     /* ROUTES */
     $contentRoutes .= "\n";
     $contentRoutes .= $delimiter;
     $contentRoutes .= "\n";
     $lines = file($file);
     $init = false;
     $preInit = false;
     $end = false;
     $content = "";
     foreach ($lines as $l => $line) {
         if ($preInit) {
             $init = true;
         }
         if (strpos($line, $delimiter) !== false) {
             $preInit = true;
         }
         if (($init || $preInit) && !$end) {
             $content .= $line;
         }
         if (strpos($line, $delimiter) !== false && $init) {
             $end = true;
         }
     }
     if ($init && $end) {
         return File::put($file, str_replace($content, $contentRoutes, file_get_contents($file)));
     } else {
         return File::append($file, $contentRoutes);
     }
 }
예제 #4
0
 /**
  * Packing files
  *
  */
 private function _pack()
 {
     //Get package
     $packages = Config::get('minify::minify.css.packages');
     //If we don't have packages to scan
     if (empty($packages)) {
         $this->error('No CSS packages to create');
         return false;
     }
     foreach ($packages as $package => $files) {
         $package = $this->_assetsDirectory . '/' . $package;
         //
         $this->info("Packing " . $package);
         // Delete file first
         File::delete($package);
         foreach ($files as $file) {
             $file = $this->_assetsDirectory . '/' . $file;
             $this->line("\tAppending " . $file . "...");
             File::append($package, File::get($file));
         }
     }
     return true;
 }
예제 #5
0
 /**
  * Store the compiled stub.
  *
  * @param $modelName
  * @param \stdClass $scaffolderConfig
  * @param $compiled
  * @param \Scaffolder\Support\FileToCompile $fileToCompile
  *
  * @return mixed|void
  */
 protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
 {
     File::append(PathParser::parse($scaffolderConfig->paths->routes), PHP_EOL . $compiled);
 }
예제 #6
0
 /**
  * @param $content
  *
  * stores content to cache based on cache key
  */
 public function storeToCache($content)
 {
     if ($content === null) {
         $content = 'null';
     }
     if ($this->cache && $this->cacheKey) {
         if ($this->cacheTime > 0) {
             Cache::put($this->cacheKey, $content, $this->cacheTime);
         } else {
             Cache::forever($this->cacheKey, $content);
         }
         if (!File::exists($this->keyStorePath)) {
             File::put($this->keyStorePath, $this->cacheKey . "\n");
         } else {
             File::append($this->keyStorePath, $this->cacheKey . "\n");
         }
     }
 }
예제 #7
0
 public function query($id)
 {
     if (!empty($id)) {
         $users = $this->entry->select('*')->join('projects', 'projects.id', '=', 'entries.project_id')->join('entry_free', 'entries.id', '=', 'entry_free.entry_id')->join('frees', 'entry_free.free_id', '=', 'frees.id')->where('projects.id', $id)->get();
         if ($users->count() > 0) {
             $entry = $this->entry->find($id);
             $protocol = $entry->project->protocol->protocol_number;
             $file = 'export_frees/01757321000106_' . $protocol . '_' . date('dmY') . '_001.txt';
             foreach ($users as $user) {
                 $contents = $user->nome . ';' . $user->nis . ';' . $user->datadenascimento . ';' . $user->sexo . ';' . $user->num_identid_rg . ';' . $user->dt_identid_rg . ';' . $user->sg_em_identid_rg . ';' . $user->cpf . ';' . $user->nomedamae . ";\r\n";
                 $bytes_written = File::append($file, $contents);
                 if ($bytes_written === false) {
                     die("Error writing to file");
                 }
             }
             return $file;
         }
     }
 }
예제 #8
0
 /**
  * Store the compiled stub.
  *
  * @param $modelName
  * @param \stdClass $scaffolderConfig
  * @param $compiled
  * @param \Scaffolder\Support\FileToCompile $fileToCompile
  *
  * @return mixed|void
  */
 protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
 {
     File::append(base_path('../' . strtolower(str_replace(' ', '-', $scaffolderConfig->name . '-api'))) . '/app/Http/routes.php', PHP_EOL . $compiled);
 }
예제 #9
0
 /**
  *
  * Logging operation - to a file (upload_log.txt) and to the stdout
  * @param string $str - the logging string
  */
 function _log($str)
 {
     $log_str = date('d.m.Y') . ": {$str}\r\n";
     File::append($this->tempDirectory . 'upload_log.txt', $log_str);
 }