new pisilinux web sites

This commit is contained in:
Erkan IŞIK
2026-07-01 16:44:17 +03:00
commit b58488b586
21740 changed files with 2066209 additions and 0 deletions
@@ -0,0 +1,30 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Singleton;
class DatabaseDefinitions
{
/**
* Keeps database classes
*/
protected $db, $tool, $forge;
/**
* Magic Constructor
*/
public function __construct()
{
$this->db = Singleton::class('ZN\Database\DB');
$this->tool = Singleton::class('ZN\Database\DBTool');
$this->forge = Singleton::class('ZN\Database\DBForge');
}
}
+389
View File
@@ -0,0 +1,389 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Base;
use ZN\Config;
use ZN\Filesystem;
use ZN\DataTypes\Arrays;
/**
* @codeCoverageIgnore
*/
class Databases extends DatabaseDefinitions
{
/**
* Actives Path
*
* @var string
*/
protected $activesPath = DATABASES_DIR . 'Actives/';
/**
* Archives Path
*
* @var string
*/
protected $archivesPath = DATABASES_DIR . 'Archives/';
/**
* Info
*
* @var array
*/
protected $info;
/**
* Process databases
*/
public function generate()
{
$this->active(); $this->archive();
}
/**
* Info
*
* @return array
*/
public function info()
{
return $this->info;
}
/**
* Protected get active database list
*/
protected function getActiveDatabaseList()
{
return Filesystem::getFiles($this->activesPath, 'dir');
}
/**
* Protected get archive database list
*/
protected function getArchiveDatabaseList()
{
return Filesystem::getFiles($this->archivesPath, 'dir');
}
/**
* Protected set active database encoding
*/
protected function setActiveDatabaseEncoding(&$encoding)
{
if( stristr('pdo:mysql|mysqli', Config::get('Database', 'database')['driver']) )
{
$encoding = $this->db->encoding();
}
else
{
$encoding = NULL;
}
}
/**
* Protected get table key column design data
*/
protected function getTableKeyColumnDesignData()
{
return [$this->db->varchar(1), $this->db->null()];
}
/**
* Protected get active database directory
*/
protected function getActiveDatabaseDirectory($database)
{
return $this->activesPath . $database . '/';
}
/**
* Protected get table list by active database
*/
protected function getTableListByActiveDatabase($database)
{
return Filesystem::getFiles($this->getActiveDatabaseDirectory($database), 'php');
}
/**
* Protected get db forge different connection by database name
*/
protected function getDBForgeDifferentConnectionByDatabaseName($database)
{
return $this->forge->differentConnection(['database' => $database]);
}
/**
* Protected get db tool different connection by database name
*/
protected function getDBToolDifferentConnectionByDatabaseName($database)
{
return $this->tool->differentConnection(['database' => $database]);
}
/**
* Protected get db different connection by database name
*/
protected function getDBDifferentConnectionByDatabaseName($database)
{
return $this->db->differentConnection(['database' => $database]);
}
/**
* Protected get active table column schema
*/
protected function getActiveTableColumnSchema($database, $table)
{
return Base::import($this->getActiveDatabaseDirectory($database) . $table);
}
/**
* Protected get table name without extension
*/
protected function getTableNameWithoutExtension($table)
{
return Filesystem::removeExtension($table);
}
/**
* Protected get active table columns
*/
protected function getActiveTableColumns($table, $db)
{
return $db->get($table)->columns();
}
/**
* Protected active table key and columns
*/
protected function getActiveTableKeyAndColumns($columns, &$tableKey, &$tableColumns)
{
$pregGrepArray = preg_grep('/_000/', $columns);
$tableKey = strtolower(current($pregGrepArray));
$tableColumns = Arrays\RemoveElement::element($columns, $pregGrepArray);
}
/**
* Protected get current table key
*/
protected function getCurrentTableKey($table, $schema)
{
return strtolower($table.'_000' . md5(json_encode($schema)));
}
/**
* Protected drop column from active table
*/
protected function dropColumnFromActiveTable($table, $key, $dbForge, &$status)
{
$dbForge->dropColumn($table, $key);
$status = true;
}
/**
* Protected modify column from active table
*/
protected function modifyColumnFromActiveTable($table, $key, $val, $dbForge, &$status, $active, $current)
{
if( $active !== $current )
{
$dbForge->modifyColumn($table, [$key => $val]);
$status = true;
}
else
{
$status = false;
}
}
/**
* Protected add column from active table
*/
protected function addColumnFromActiveTable($table, $key, $val, $dbForge, &$status)
{
$dbForge->addColumn($table, [$key => $val]);
$status = true;
}
/**
* Protected Actives Databases
*/
protected function active()
{
if( empty($activeDatabaseList = $this->getActiveDatabaseList()) )
{
return false;
}
$this->setActiveDatabaseEncoding($encoding);
$status = false;
$tableKeyColumnDesignData = $this->getTableKeyColumnDesignData();
foreach( $activeDatabaseList as $database )
{
$this->forge->createDatabase($database, $encoding);
if( ! empty($activeTableList = $this->getTableListByActiveDatabase($database)) )
{
$dbForge = $this->getDBForgeDifferentConnectionByDatabaseName($database);
$db = $this->getDBDifferentConnectionByDatabaseName($database);
foreach( $activeTableList as $table )
{
$activeTableColumnSchema = $this->getActiveTableColumnSchema($database, $table);
$activeTableColumns = $this->getActiveTableColumns($table = $this->getTableNameWithoutExtension($table), $db);
$this->getActiveTableKeyAndColumns($activeTableColumns, $activeTableKey, $activeTableColumns);
$currentTableKey = $this->getCurrentTableKey($table, $activeTableColumnSchema);
if( ! empty($activeTableColumns) )
{
$columnsMerge = array_merge(array_flip($activeTableColumns), $activeTableColumnSchema);
foreach( $columnsMerge as $key => $val )
{
if( is_numeric($val) )
{
$this->dropColumnFromActiveTable($table, $key, $dbForge, $status);
}
elseif( in_array($key, $activeTableColumns) )
{
$this->modifyColumnFromActiveTable($table, $key, $val, $dbForge, $status, $activeTableKey, $currentTableKey);
}
else
{
$this->addColumnFromActiveTable($table, $key, $val, $dbForge, $status);
}
$this->addInfo($dbForge, __FUNCTION__);
}
if( $status === true )
{
$this->addTableToArchive($database, $table);
}
}
else
{
$activeTableColumnSchema[$currentTableKey] = $tableKeyColumnDesignData;
$dbForge->createTable($table, $activeTableColumnSchema);
$this->addInfo($dbForge, __FUNCTION__);
}
}
}
}
}
/**
* protected add info
*/
protected function addInfo($dbForge, $type)
{
$this->info[$type][$dbForge->stringQuery()] = $dbForge->error() ?: 'success';
}
/**
* Protected add table to archive
*/
protected function addTableToArchive($database, $table)
{
$this->createArchiveDatabaseDirectoryIfNotExists($database);
file_put_contents
(
$this->getArchiveTableFilePath($path = $database . '/' . $table),
$this->getActiveTableFileContent($path)
);
}
/**
* Protected get active table file content
*/
protected function getActiveTableFileContent($table)
{
return file_get_contents($this->activesPath . $table . '.php');
}
/**
* Protected get archive table file path
*/
protected function getArchiveTableFilePath($table)
{
return $this->archivesPath . $table . '_' . date('YmdHis') . '.php';
}
/**
* Protected create archive database directory if not exists
*/
protected function createArchiveDatabaseDirectoryIfNotExists($database)
{
$path = $this->archivesPath . $database . '/';
if( ! is_dir($path) )
{
Filesystem::createFolder($path);
}
}
/**
* Protected get archive database table list
*/
protected function getArchiveDatabaseTableList($database)
{
$databasePath = $this->archivesPath . $database . '/';
$tables = Filesystem::getFiles($databasePath, 'php');
$pregGrep = preg_grep("/\_[0-9]*\.php/", $tables);
return Arrays\RemoveElement::element($tables, $pregGrep);
}
/**
* Protected Archives Database
*/
protected function archive()
{
if( $archiveDatabaseList = $this->getArchiveDatabaseList() )
{
foreach( $archiveDatabaseList as $database )
{
if( ! empty($tables = $this->getArchiveDatabaseTableList($database)) )
{
$dbForge = $this->getDBForgeDifferentConnectionByDatabaseName($database);
foreach( $tables as $table )
{
$dbForge->dropTable($this->getTableNameWithoutExtension($table));
$this->addInfo($dbForge, __FUNCTION__);
}
}
$tool = $this->getDBToolDifferentConnectionByDatabaseName($database);
if( empty($tool->listTables()) )
{
$this->forge->dropDatabase($database);
}
}
return true;
}
return false;
}
}
@@ -0,0 +1,21 @@
<?php namespace ZN\Generator\Exception;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Exception;
class InvalidTypeException extends Exception
{
const lang =
[
'tr' => 'Geçersiz tür tanımlaması! Kullanılabilir seçenekler: %',
'en' => 'Invalid type definition! Available options: %'
];
}
+452
View File
@@ -0,0 +1,452 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Base;
use ZN\Datatype;
use ZN\ErrorHandling\Errors;
class File
{
/**
* Keeps Settings
*
* @var array
*/
protected $settings = [];
/**
* Settings
*
* @param array $settings
*
* @return Generate
*/
public function settings(array $settings) : Generate
{
$this->settings = $settings;
return $this;
}
/**
* Delete Structure
*
* @param string $name
* @param string $type = 'controller'
* @param string $app = NULL
*
* @return bool
*/
public function delete(string $name, string $type = 'controller', ?string $app = NULL) : bool
{
if( ! empty($app) )
{
$this->settings['application'] = $app; // @codeCoverageIgnore
}
$file = $this->path($name, $type);
if( is_file($file) )
{
return unlink($file);
}
return false; // @codeCoverageIgnore
}
/**
* Generate Object
*
* @param string $type
* @param string $name
* @param array $settings
*
* @return bool
*/
public function object(string $type, string $name, array $settings) : bool
{
if( ! empty($settings) )
{
$this->settings = $settings;
}
if( empty($name) )
{
$this->error = Errors::message('Error', 'emptyParameter', '1.(name)'); // @codeCoverageIgnore
}
# Start Generate
$controller = "<?php".EOL;
# Object Data
$this->settings['object'] = $this->settings['object'] ?? 'class';
# Namespace Data
$this->namespace($controller, $namespace);
# Uses Data
$this->uses($controller);
# Class Name
if( ! empty($this->settings['name']) )
{
$name = $this->settings['name']; // @codeCoverageIgnore
}
$controller .= $this->settings['object']." ".$name;
# Extends Data
$this->extends($controller);
# Implements Data
$this->implements($controller);
# Start Body
$controller .= EOL . "{" . EOL;
# Traits Data
$this->traits($controller);
# Constants Data
$this->constants($controller);
# Vars Data
$this->vars($controller);
# Functions Data
$this->functions($controller);
# Finish Class
$controller = rtrim($controller, EOL) . EOL . "}";
# Alias Data
$this->alias($controller, $namespace);
# File Write
return $this->write($name, $type, $controller);
}
/**
* Protected Path
*/
protected function path($name, $type)
{
if( empty($this->settings['application']) )
{
$this->settings['application'] = Datatype::divide(rtrim(PROJECT_DIR, '/'), '/', -1);
}
return PROJECTS_DIR.Base::suffix($this->settings['application']).$this->type($type).Base::suffix($name, '.php');
}
/**
* Protected Write
*
* @param string $name
* @param string $type
* @param string $controller
*
* @return bool
*/
protected function write($name, $type, $controller) : bool
{
if( ! empty($name) )
{
if( ! empty($this->settings['path']) )
{
$filePath = Base::suffix($this->settings['path'], '/') . $name;
}
else
{
$filePath = $name;
}
$file = $this->path($filePath, $type);
if( ! is_file($file) )
{
if( file_put_contents($file, $controller) )
{
return true;
}
}
}
return false; // @codeCoverageIgnore
}
/**
* Protected Functions
*
* @param string & $controller
* @param string $namespace = NULL
*/
protected function alias(string & $controller, ?string $namespace = NULL)
{
if( ! empty($this->settings['alias']) )
{
$controller .= EOL.EOL.'class_alias("'.Base::suffix($namespace, '\\').$name.'", "'.$this->settings['alias'].'");'; // @codeCoverageIgnore
}
}
/**
* Protected Functions
*
* @param string & $controller
*/
protected function functions(string & $controller)
{
$parameters = '';
$functions = (array) ($this->settings['functions'] ?? []);
if( ! empty($functions) ) foreach( $functions as $isKey => $function )
{
if( ! empty($function) )
{
if( ! is_numeric($isKey) )
{
if( is_array($function) )
{
foreach( $function as $key => $val )
{
$subvalue = '';
if( ! is_numeric($key) )
{
$subvalue = $val;
$val = $key;
}
$vartype = '';
if( strstr($val, ' ') )
{
$varEx = explode(' ', $val);
$val = $varEx[1];
$vartype = $varEx[0] . ' ';
}
if( strpos($val, '...') === 0 )
{
$varprefix = str_replace('...', '...$', $val ?? '');
$subvalue = '';
}
else
{
$varprefix = '$'.$val;
}
$parameters .= $vartype . $varprefix.( ! empty($subvalue) ? ' = '.$subvalue : '').', ';
}
$parameters = rtrim($parameters, ', ');
}
$function = $isKey;
}
$function = $this->vartype($function);
$controller .= HT.$function->priority." function {$function->var}({$parameters})".EOL;
$controller .= HT."{".EOL;
$controller .= HT.HT."// Your codes...".EOL;
$controller .= HT."}".EOL.EOL;
}
}
}
/**
* Protected Uses
*
* @param string & $controller
* @param string & $namespace = NULL
*/
protected function namespace(string & $controller, string & $namespace = NULL)
{
if( ! empty($this->settings['namespace']) )
{
$namespace = $this->settings['namespace'];
$controller .= "namespace ".$namespace.";".EOL.EOL;
}
}
/**
* Protected Uses
*
* @param string & $controller
*/
protected function uses(string & $controller)
{
if( ! empty($this->settings['use']) )
{
foreach( $this->settings['use'] as $key => $use )
{
if( is_numeric($key) )
{
$controller .= "use {$use};".EOL;
}
else
{
$controller .= "use {$key} as {$use};".EOL;
}
}
$controller .= EOL;
}
}
/**
* Protected Extends
*
* @param string & $controller
*/
protected function extends(string & $controller)
{
if( ! empty($this->settings['extends']) )
{
$controller .= " extends ".$this->settings['extends'];
}
}
/**
* Protected Implements
*
* @param string & $controller
*/
protected function implements(string & $controller)
{
if( ! empty($this->settings['implements']) )
{
$controller .= " implements ".( is_array($this->settings['implements'])
? implode(', ', $this->settings['implements']) // @codeCoverageIgnore
: $this->settings['implements']
);
}
}
/**
* Protected Traits
*
* @param string & $controller
*/
protected function traits(string & $controller)
{
if( ! empty($this->settings['traits']) )
{
if( is_array($this->settings['traits']) ) foreach( $this->settings['traits'] as $trait )
{
$controller .= HT."use {$trait};".EOL;
}
else
{
$controller .= HT."use ".$this->settings['traits'].";".EOL; // @codeCoverageIgnore
}
$controller .= EOL;
}
}
/**
* Protected Contants
*
* @param string & $controller
*/
protected function constants(string & $controller)
{
if( ! empty($this->settings['constants']) )
{
foreach( $this->settings['constants'] as $key => $val )
{
$controller .= HT."const {$key} = {$val};".EOL;
}
$controller .= EOL;
}
}
/**
* Protected Vars
*
* @param string & $controller
*/
protected function vars(string & $controller)
{
if( ! empty($this->settings['vars']) )
{
$var = '';
foreach( $this->settings['vars'] as $isKey => $var )
{
if( ! is_numeric($isKey) )
{
$value = $var;
$var = $isKey;
}
$vars = $this->vartype($var);
$controller .= HT.$vars->priority.' $'.$vars->var.( ! empty($value) ? " = ".$value : '' ).";".EOL;
}
$controller .= EOL;
}
}
/**
* Protected Variable Type
*/
protected function vartype($variable)
{
$this->getEncapsulationType($variable, $priority, $static);
return (object)
[
'priority' => $priority . $static,
'var' => $variable
];
}
/**
* Protected get encapsulation type
*/
protected function getEncapsulationType(&$variable, &$priority, &$static)
{
$static = NULL;
if( preg_match('/^((?<type>public|protected|private)(?<access>\sstatic)*\:)/', $variable ?? '', $match) )
{
$priority = $match['type'];
$static = $match['access'] ?? $static;
$variable = str_ireplace($match[1], '', $variable ?? '');
}
else
{
$priority = 'public';
}
}
/**
* Protected type
*/
protected function type($type)
{
switch( $type )
{
case 'model' : $return = MODELS_DIR; break;
case 'controller': $return = CONTROLLERS_DIR; break;
case 'library' : $return = LIBRARIES_DIR; break;
case 'command' : $return = COMMANDS_DIR; break;
}
$path = PROJECT_TYPE === 'EIP' ? Datatype::divide(rtrim($return ?? '', '/'), '/', -1) : $return;
return Base::suffix($path);
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Generate extends File implements GenerateInterface
{
/**
* Generate Types
*
* @var array
*/
protected $types =
[
'controller',
'library',
'command',
'model'
];
/**
* Magic Call
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
if( in_array($method, $this->types) )
{
$name = $parameters[0];
return $this->object($method, $name, $parameters[1] ?? []);
}
throw new Exception\InvalidTypeException(NULL, implode(', ', $this->types));
}
/**
* Select project name
*
* @param string $name
*
* @return bool
*/
public function project(string $name) : bool
{
return Project::generate($name);
}
/**
* Process databases
*
* @return array
*/
public function databases()
{
$databases = new Databases;
$databases->generate();
return $databases->info();
}
/**
* Generate Grand Vision
*
* @param mixed ...$database
*/
public function grandVision(...$database)
{
(new GrandVision)->generate(...$database);
}
/**
* Delete Grand Vision
*
* @param string $databaes = '*'
* @param array $tables = NULL
*/
public function deleteVision(string $database = '*', ?array $tables = NULL)
{
(new GrandVision)->delete($database, $tables);
}
}
@@ -0,0 +1,62 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface GenerateInterface
{
/**
* Select project name
*
* @param string $name
*
* @return bool
*/
public function project(string $name) : bool;
/**
* Process databases
*/
public function databases();
/**
* Grand Vision
*
* @param mixed ...$database
*/
public function grandVision(...$database);
/**
* Delete Vision
*
* @param string $database = '*'
* @param array $tables = NULL
*/
public function deleteVision(string $database = '*', ?array $tables = NULL);
/**
* Settings
*
* @param array $settings
*
* @return Generate
*/
public function settings(array $settings) : Generate;
/**
* Delete Structure
*
* @param string $name
* @param string $type = 'controller'
* @param string $app = NULL
*
* @return bool
*/
public function delete(string $name, string $type = 'controller', ?string $app = NULL) : bool;
}
+264
View File
@@ -0,0 +1,264 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Base;
use ZN\Config;
use ZN\Filesystem;
class GrandVision extends DatabaseDefinitions
{
/**
* Vision Directory
*
* @var string
*/
protected $visionDirectory = 'Visions/';
/**
* Keeps default database name
*/
protected $defaultDatabaseName;
/**
* Magic Constructor
*/
public function __construct()
{
parent::__construct();
$config = Config::default('ZN\Database\DatabaseDefaultConfiguration')::get('Database', 'database');
$this->defaultDatabaseName = $config['database'];
}
/**
* Generate Grand Vision
*
* @param mixed ...$database
*/
public function generate(...$database)
{
$databases = $this->getDatabaseList($database);
foreach( $databases as $connection => $database )
{
$this->setDatabaseConfiguration($connection, $database, $configs);
$this->createVisionDirectoryByDatabaseName($database);
$this->createVisionModelFile($database, $configs);
}
}
/**
* Delete Grand Vision
*
* @param string $databaes = '*'
* @param array $tables = NULL
*/
public function delete(string $database = '*', ?array $tables = NULL)
{
if( $database === '*' )
{
$this->deleteVisionsDirectory();
}
else
{
if( $tables === NULL )
{
$this->deleteVisionDirectory($database);
}
else
{
$this->deleteVisionFile($database, $tables);
}
}
}
/**
* Protected set database configuration
*/
protected function setDatabaseConfiguration($connection, &$database, &$configs)
{
$configs = [];
if( is_array($database) )
{
$configs = $database; // @codeCoverageIgnore
$database = $connection; // @codeCoverageIgnore
}
$configs['database'] = $database ?: $this->defaultDatabaseName;
}
/**
* Protected get database vision directory
*/
protected function getDatabaseVisionDirectory($database)
{
return $this->visionDirectory . $this->getDatabaseName($database);
}
/**
* Protected get database name
*/
protected function getDatabaseName($database)
{
return ucfirst($database ?: $this->defaultDatabaseName);
}
/**
* Protected create vision model file
*/
protected function createVisionModelFile($database, $configs)
{
$tables = $this->getTableList($database);
$database = ucfirst($database);
foreach( $tables as $table )
{
(new File)->object
(
'model',
$this->getDatabaseVisionClassName($database, $table),
[
'path' => $this->getDatabaseVisionDirectory($database),
'namespace' => $this->getDatabaseVisionNamespace($database),
'use' => ['GrandModel'],
'extends' => 'GrandModel',
'constants' =>
[
'table' => "'".ucfirst($table)."'",
'connection' => $this->stringArray($configs)
]
]
);
}
}
/**
* Protected get table list
*/
protected function getTableList($database)
{
return $this->tool->differentConnection(['database' => $database])->listTables();
}
/**
* Protected get database list
*/
protected function getDatabaseList($database)
{
$databases = $database;
if( is_array(($database[0] ?? NULL)) )
{
$databases = $database[0]; // @codeCoverageIgnore
}
if( empty($database) )
{
$databases = $this->tool->listDatabases();
}
return $databases;
}
/**
* Protected create vision diretory by database name
*/
protected function createVisionDirectoryByDatabaseName($file)
{
Filesystem::createFolder(MODELS_DIR . $this->getDatabaseVisionDirectory(ucfirst($file)));
}
/**
* Protected delete vision
*/
protected function deleteVisionDirectory($vision)
{
Filesystem::deleteFolder($this->getVisionDirectory() . $this->getDatabaseName($vision));
}
/**
* Protected delete visions
*/
protected function deleteVisionsDirectory()
{
Filesystem::deleteFolder($this->getVisionDirectory());
}
/**
* Protected delete vision file
*/
protected function deleteVisionFile($database, $tables)
{
foreach( $tables as $table )
{
unlink($this->getVisionFilePath($database, $table));
}
}
/**
* Protected get visison directory
*/
protected function getVisionDirectory()
{
return MODELS_DIR . $this->visionDirectory;
}
/**
* Protected get database vision class name
*/
protected function getDatabaseVisionClassName($database, $table)
{
return INTERNAL_ACCESS . ( strtolower($database) === strtolower($this->defaultDatabaseName) ? NULL : ucfirst($database) ) . ucfirst($table) . 'Vision';
}
/**
* Protected get vision file path
*/
protected function getVisionFilePath($database, $table)
{
return $this->getVisionDirectory() . Base::suffix(ucfirst($database)) . $this->getDatabaseVisionClassName($database, $table) . '.php';
}
/**
* Protected get database vision namespace
*/
protected function getDatabaseVisionNamespace($database)
{
return 'Visions\\' . $this->getDatabaseName($database);
}
/**
* Protected String Array
*
* @param array $data
*
* @return string
*/
protected function stringArray(array $data)
{
$str = EOL . HT . '[' . EOL;
foreach( $data as $key => $val )
{
$str .= HT . HT . "'" . $key . "' => '" . $val . "'," . EOL;
}
$str = Base::removeSuffix($str, ',' . EOL);
$str .= EOL . HT . ']';
return $str;
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php namespace ZN\Generator;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Filesystem\Forge;
class Project
{
/**
* Select project name
*
* @param string $name
*
* @return bool
*/
public static function generate(string $name) : bool
{
if( ctype_alnum($name) )
{
$source = EXTERNAL_FILES_DIR . 'DefaultProject.zip';
$target = PROJECTS_DIR . $name;
Forge::zipExtract($source, $target);
return true;
}
return false;
}
}