Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from natanfelles/Filter
Browse files Browse the repository at this point in the history
Add Make:Filter
  • Loading branch information
lonnieezell committed Jul 12, 2018
2 parents d766b2d + 8d8b950 commit fc43880
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Commands/MakeFilter.php
@@ -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);
}
}

}
43 changes: 43 additions & 0 deletions Views/Filter/Filter.php
@@ -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)
{
//
}

}

0 comments on commit fc43880

Please sign in to comment.