-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: DBfun, command make:dbfun , setting config and add class Config
- Loading branch information
1 parent
8ce7cb6
commit 190e5e4
Showing
10 changed files
with
261 additions
and
32 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,22 @@ | ||
<?php | ||
/** | ||
* REIKO FRAMEWORK | ||
* | ||
* @package ReiKo Framework | ||
* | ||
* @author alinko <[email protected]> | ||
* @author ReiYan <[email protected]> | ||
* @copyright (c) 2021 | ||
* | ||
* @license MIT | ||
* | ||
*/ | ||
|
||
|
||
|
||
|
||
/** load functions */ | ||
$config['load_functions'] = array('common' , 'form'); | ||
|
||
/** default language */ | ||
$config['default_lang'] = 'en'; |
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
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
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
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
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
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,54 @@ | ||
<?php | ||
|
||
/** | ||
* REIKO FRAMEWORK | ||
* | ||
* @package ReiKo Framework | ||
* | ||
* @author alinko <[email protected]> | ||
* @author ReiYan <[email protected]> | ||
* @copyright (c) 2021 | ||
* | ||
* @license MIT | ||
* | ||
*/ | ||
|
||
namespace Reiko\Libraries; | ||
|
||
class Config | ||
{ | ||
public $config; | ||
private $config_list; | ||
|
||
public function register_config() | ||
{ | ||
/** | ||
* You can call the config files in 'app/config/' | ||
* This addtional config besides of .env files. | ||
*/ | ||
$this->config_list = [ | ||
'config', | ||
'routes' | ||
]; | ||
} | ||
|
||
public function init() | ||
{ | ||
$this->register_config(); | ||
foreach ($this->config_list as $config_file) { | ||
/** check config file exist */ | ||
if (file_exists(CONFIG_PATH . $config_file . '.php')) { | ||
/** include registered config file */ | ||
require_once(CONFIG_PATH . $config_file . '.php'); | ||
} else { | ||
exit('ERROR : Config ' . $config_file . ' not exist !'); | ||
} | ||
} | ||
|
||
/** declare $config to constant */ | ||
define('CONFIG' , $config); | ||
|
||
/** declare $config to $this->config */ | ||
$this->config = $config; | ||
} | ||
} |
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
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,118 @@ | ||
<?php | ||
namespace Dev\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class MakeDbfun extends Command | ||
{ | ||
// the name of the command (the part after "bin/console") | ||
protected static $defaultName = 'make:dbfun'; | ||
protected static $defaultDescription = 'Automation command for make DB classes'; | ||
protected function configure(): void | ||
{ | ||
|
||
$this->addArgument('funName' , InputArgument::REQUIRED , "Name of db class"); | ||
$this->addOption('methods' , null, InputOption::VALUE_OPTIONAL , 'Generate methods in db class'); | ||
$this->addOption('table' ,null , InputOption::VALUE_OPTIONAL , 'Use the table instead , default table is name of fundb'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$name = $input->getArgument('funName'); | ||
$output->writeln("<comment>Generating $name please wait ... </comment>"); | ||
$this->templateFun($name , $input->getOption('methods') , $input->getOption('table')); | ||
$output->write("<info>Successfully !</info>"); | ||
return Command::SUCCESS; | ||
} | ||
protected function templateFun($filename,$methods,$table){ | ||
|
||
if($table == null) | ||
{ | ||
$table = strtolower($filename); | ||
} | ||
$tmpl = "<?php | ||
namespace Reiko; | ||
/** | ||
* REIKO FRAMEWORK | ||
* | ||
* @package ReiKo Framework | ||
* | ||
* @author alinko <[email protected]> | ||
* @author ReiYan <[email protected]> | ||
* @copyright (c) 2021 | ||
* | ||
* @license MIT | ||
* | ||
*/ | ||
use Reiko\Libraries\DB; | ||
class ".ucfirst($filename)." extends DB | ||
{ | ||
protected \$table = \"{$table}\"; | ||
protected \$id = \"id_{$table}\"; | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
\$this->table(\$this->table); | ||
} | ||
/** | ||
* The reiko framework generated basic function for CRUD | ||
* @method create | ||
* @method readAll | ||
* @method readById | ||
* @method update | ||
* @method delete | ||
* | ||
**/ | ||
public function create(\$data = []) | ||
{ | ||
return \$this->save(\$data); | ||
} | ||
public function readAll() | ||
{ | ||
return \$this->select('*')->get(); | ||
} | ||
public function delete(\$id) | ||
{ | ||
return \$this->where([\$this->id => \$id])->delete(); | ||
} | ||
public function readById(\$id) | ||
{ | ||
return \$this->where([\$this->id => \$id])->fetchArray(); | ||
} | ||
public function update(\$data= [] , \$id) | ||
{ | ||
return \$this->set(\$data)->where([\$this->id => \$id])->update(); | ||
} | ||
/** | ||
* You can add your method bellow | ||
*/ | ||
"; | ||
if($methods != null) | ||
{ | ||
foreach(explode("," , $methods) as $method){ | ||
$tmpl.= " | ||
public function $method() | ||
{ | ||
// some code here for method : $method | ||
} | ||
"; | ||
} | ||
} | ||
$tmpl.= " | ||
}"; | ||
|
||
file_put_contents( 'app/'.ucfirst($filename) . '.dbfun.php' , $tmpl); | ||
} | ||
} |
Oops, something went wrong.