This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from natanfelles/Filter
Add Make:Filter
- Loading branch information
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
namespace Vulcan\Commands; | ||
|
||
use CodeIgniter\CLI\BaseCommand; | ||
use CodeIgniter\CLI\CLI; | ||
use Vulcan\Libraries\GeneratorTrait; | ||
|
||
/** | ||
* Creates a skeleton Filter. | ||
* | ||
* @package Vulcan\Commands | ||
*/ | ||
class MakeFilter extends BaseCommand | ||
{ | ||
use GeneratorTrait; | ||
|
||
protected $group = 'Vulcan'; | ||
|
||
/** | ||
* The Command's name | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:filter'; | ||
|
||
/** | ||
* the Command's short description | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Creates a skeleton Filter class.'; | ||
|
||
/** | ||
* Creates a skeleton command file. | ||
*/ | ||
public function run(array $params=[]) | ||
{ | ||
/* | ||
* Name | ||
*/ | ||
$name = array_shift($params); | ||
|
||
if (empty($name)) | ||
{ | ||
$name = CLI::prompt('Filter name'); | ||
} | ||
|
||
// Format to CI standards | ||
$name = ucfirst($name); | ||
$view = 'Filter/Filter'; | ||
|
||
$data = [ | ||
'namespace' => 'App\Filters', | ||
'name' => $name, | ||
'today' => date('Y-m-d H:i:a'), | ||
]; | ||
|
||
$destination = $this->determineOutputPath('Filters').$name.'.php'; | ||
|
||
$overwrite = (bool)CLI::getOption('f'); | ||
|
||
try { | ||
$this->copyTemplate($view, $destination, $data, $overwrite); | ||
} | ||
catch (\Exception $e) | ||
{ | ||
$this->showError($e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@php namespace {namespace}; | ||
|
||
use CodeIgniter\Filters\FilterInterface; | ||
use CodeIgniter\HTTP\RequestInterface; | ||
use CodeIgniter\HTTP\ResponseInterface; | ||
use Config\Services; | ||
|
||
/** | ||
* {! name !} Filter | ||
* | ||
* Generated by Vulcan at {! today !} | ||
*/ | ||
class {! name !} implements FilterInterface | ||
{ | ||
|
||
/** | ||
* | ||
* | ||
* @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function before(RequestInterface $request) | ||
{ | ||
// | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* | ||
* | ||
* @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request | ||
* @param ResponseInterface|\CodeIgniter\HTTP\Response $response | ||
* | ||
* @return mixed | ||
*/ | ||
public function after(RequestInterface $request, ResponseInterface $response) | ||
{ | ||
// | ||
} | ||
|
||
} |