Skip to content

Commit

Permalink
template added
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Nov 25, 2020
1 parent c6b4b07 commit 8106452
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 130 deletions.
4 changes: 1 addition & 3 deletions src/Commands/Controller/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public function run(array $params = [])
$date = date("d F, Y h:i:s A");

//Basic Controller Template
$basicTemplate = <<<EOD
EOD;
$basicTemplate = '';

//REST Controller Template
$restTemplate = <<<EOD
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MakeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function run(array $params = [])
$validationRules = '[]';

if (isset($attributes)) {
if (strpos($attributes, 'deleted_at') !== false) {
if (stripos($attributes, 'deleted_at') !== false) {
$softDelete = 'true';
$deleteField = "protected \$deletedField = 'deleted_at';";
}
Expand Down
18 changes: 6 additions & 12 deletions src/Templates/bcont.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
<?php namespace {namespace}

{basespace}

/**
* Short description of this class usages
Expand All @@ -10,25 +12,17 @@
* @created_at {created_at}
*/

class
{
name
}

extends {
parent}
class {name} extends {parent}
{
/**
* {name} constructor
*/
public
function __construct()
public function __construct()
{

}

public
function index()
public function index()
{
echo 'Hello World!';
}
Expand Down
16 changes: 6 additions & 10 deletions src/Templates/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php /**
<?php namespace {namespace};

use CodeIgniter\Config\BaseConfig;

/**
* Short description of this class usages
*
* @class {name}
Expand All @@ -8,15 +12,7 @@
* @created_at {created_at}
*/

class
{
name
}


namespace {

namespace} extends BaseConfig
class {name} extends BaseConfig
{
//
}
38 changes: 10 additions & 28 deletions src/Templates/entity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php /**
<?php namespace {namespace}\Entities;

use CodeIgniter\Entity;

/**
* Short description of this class usages
*
* @class {name}
Expand All @@ -8,48 +12,26 @@
* @created_at {created_at}
*/

class
{
name
}

Entities;

namespace {

namespace} extends Entity
class {name} extends Entity
{
/**
* Database Table Column names
* index = column
* value = default
* Eg: ['balance' => 0.00, 'name' => null]
*/
protected
$attributes = [{
attributes}]
protected $attributes = [{attributes}];

/**
* Database Table Column To Property
* Mapper
* index = property
* value = column
* Eg: ['balance' => 'saving', 'phone' => 'mobile']
* Database Table Column To Property Mapper
*/
protected $datamap = [];

/**
* Property That will use timestamp
*/
protected $dates = [{
dates}]
protected $dates = [{dates}];

/**
* Property Types Casted
* Eg: ['is_banned' => 'boolean',
* 'is_banned_nullable' => '?boolean']
*/
protected $casts = [{
casts}]
protected $casts = [{casts}];

}
42 changes: 12 additions & 30 deletions src/Templates/filter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php /**
<?php namespace {namespace}\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\Services;

/**
* Short description of this class usages
*
* @class {name}
Expand All @@ -8,43 +15,19 @@
* @created_at {created_at}
*/

class
{
name
}

Filters;

use CodeIgniter\HTTP\RequestInterface;use CodeIgniter\HTTP\ResponseInterface;use CodeIgniter\Services;

namespace {

namespace} implements FilterInterface
class {name} implements FilterInterface
{
/**
* Do whatever processing this filter needs to do.
* By default it should not return anything during
* normal execution. However, when an abnormal state
* is found, it should return an instance of
* CodeIgniter\HTTP\Response. If it does, script
* execution will end and that Response will be
* sent back to the client, allowing for error pages,
* redirects, etc.
*
* @param RequestInterface $request
*
* @param null $arguments
*
* @return mixed
*/
public
function before(RequestInterface $request, $arguments = null)
public function before(RequestInterface $request, $arguments = null)
{
//Validator Instants
$validator = Services::validation();

//Session Instants
$session = Services::session();

}

//--------------------------------------------------------------------
Expand All @@ -61,8 +44,7 @@ function before(RequestInterface $request, $arguments = null)
*
* @return mixed
*/
public
function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
//
}
Expand Down
36 changes: 12 additions & 24 deletions src/Templates/model.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php /**
<?php namespace {namespace}\Models;

use CodeIgniter\Model;

/**
* Short description of this class usages
*
* @class {name}
Expand All @@ -8,46 +12,30 @@
* @created_at {created_at}
*/

class
{
name
}

Models;

namespace {

namespace} extends Model
class {name} extends Model
{
/**
* Table Configuration
*/
protected
$table = '{table}';
protected
$primaryKey = '{primary_id}';
protected $table = '{table}';
protected $primaryKey = '{primary_id}';

/**
* Model & Table Column Customization
*/
protected
$allowedFields = [{
attributes}]
protected $allowedFields = [{attributes}];
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
{
delete_field}
{delete_field}

/**
* Return Configuration
*/
protected $returnType = 'object';
protected $useSoftDeletes = {
soft_delete}
protected $validationRules = {
rules}
protected $useSoftDeletes = {soft_delete};
protected $validationRules = {rules};
protected $validationMessages = [];
protected $skipValidation = true;

Expand Down
32 changes: 10 additions & 22 deletions src/Templates/seed.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
<?php namespace {namespace}\Database\Seeds;

use const Database\Seeds;
use CodeIgniter\Database\Seeder;
use Exception;
use ReflectionException;

/**
* Short description of this class usages
Expand All @@ -12,27 +14,14 @@
* @created_at {created_at}
*/

class
class {name} extends Seeder
{
name
}

Seeds;

namespace {

namespace} extends Seeder
{
public
function run()
public function run()
{
$data = [
{
seeder}
]
$data = [{seeder}];

// Using Model
/*$model = new $nameModel();
/*$model = new {name}Model();
foreach ($data as $datum) {
try {
$model->save($datum);
Expand All @@ -42,11 +31,10 @@ function run()
}*/

//Using Query Builder Class
try {
try
$this->db->table('{table}')->insertBatch($data);

} catch (ReflectionException $e) {
catch (ReflectionException $e)
throw new Exception($e->getMessage());
}
}
}

0 comments on commit 8106452

Please sign in to comment.