From 3524da1b7e73a0f77ba1fcccf2110de4e761a7e0 Mon Sep 17 00:00:00 2001 From: Fredrick Peter Date: Sun, 8 Oct 2023 04:06:35 +0100 Subject: [PATCH] Crucial update, Same usage --- .env.example | 45 +++++++++++++++++++ README.md | 3 +- src/AutoLoader.php | 4 +- src/Connectors/Connector.php | 15 +++---- src/Connectors/SQLiteConnector.php | 2 +- src/DatabaseConnector.php | 18 ++++---- src/DatabaseManager.php | 16 +++---- src/Dummy/dummyGitIgnore.dum | 1 + src/Migrations/Blueprint.php | 4 +- src/Migrations/Migration.php | 4 +- src/Migrations/Schema.php | 8 ++-- src/Migrations/Traits/FilePathTrait.php | 4 +- src/Migrations/Traits/MigrationTrait.php | 15 ++++--- .../Traits/SchemaConfigurationTrait.php | 20 ++++----- .../Traits/SchemeCollectionTrait.php | 14 +++--- src/Migrations/Traits/TableStructureTrait.php | 4 +- src/Model.php | 3 +- src/Schema/Builder.php | 2 +- src/Traits/DBImportTrait.php | 4 +- src/Traits/DBSetupTrait.php | 4 +- src/helpers.php | 8 ++-- 21 files changed, 122 insertions(+), 76 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7925165 --- /dev/null +++ b/.env.example @@ -0,0 +1,45 @@ +APP_NAME="ORM Database" +APP_ENV=local +APP_KEY=base64:gLf20f1FOUlfG/l5-BccCrdZBXy6iEsVZA7nEBtS84zU= +APP_DEBUG=true +SITE_EMAIL= + +DB_CONNECTION=mysql +DB_HOST="127.0.0.1" +DB_PORT=3306 +DB_USERNAME="root" +DB_PASSWORD= +DB_DATABASE= + +DB_CHARSET=utf8mb4 +DB_COLLATION=utf8mb4_general_ci + +MAIL_MAILER=smtp +MAIL_HOST= +MAIL_PORT=465 +MAIL_USERNAME= +MAIL_PASSWORD= +MAIL_ENCRYPTION=tls +MAIL_FROM_ADDRESS="${MAIL_USERNAME}" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_URL= +AWS_USE_PATH_STYLE_ENDPOINT=false + +CLOUDINARY_SECRET_KEY= +CLOUDINARY_KEY= +CLOUDINARY_NAME= +CLOUDINARY_URL= +CLOUDINARY_SECURE=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_HOST= +PUSHER_PORT=443 +PUSHER_SCHEME=https +PUSHER_APP_CLUSTER=mt1 diff --git a/README.md b/README.md index 97fffb3..746c5a0 100644 --- a/README.md +++ b/README.md @@ -1205,7 +1205,6 @@ class Post extends Model{ ## Useful Links - @author Fredrick Peterson (Tame Developers) +- If you love this PHP Library, you can [Buy Tame Developers a coffee](https://www.buymeacoffee.com/tamedevelopers) - [Lightweight - PHP ORM Database](https://github.com/tamedevelopers/database) - [Support - Library](https://github.com/tamedevelopers/support) -- If you love this PHP Library, you can [Buy Tame Developers a coffee](https://www.buymeacoffee.com/tamedevelopers) -- Udemy Course on Usage [Coming Soon]() \ No newline at end of file diff --git a/src/AutoLoader.php b/src/AutoLoader.php index 7cb0209..f144759 100644 --- a/src/AutoLoader.php +++ b/src/AutoLoader.php @@ -17,13 +17,13 @@ class AutoLoader{ /** * Star env configuration * - * @param string $custom_path + * @param string|null $custom_path * path \Path to .env file * - [optional] path \By default we use project root path * * @return void */ - public static function start(?string $custom_path = null) + public static function start($custom_path = null) { /* |-------------------------------------------------------------------------- diff --git a/src/Connectors/Connector.php b/src/Connectors/Connector.php index c6b854e..8238385 100644 --- a/src/Connectors/Connector.php +++ b/src/Connectors/Connector.php @@ -38,7 +38,7 @@ class Connector { * @param mixed $connection \Connection instance * */ - public function __construct(?string $name = null, mixed $connection = null) + public function __construct($name = null, mixed $connection = null) { $this->setConnectionName($name); $this->setConnection($connection); @@ -62,11 +62,11 @@ public function table(string $table) /** * Check if table exists * - * @param string $table + * @param string|null $table * * @return bool */ - public function tableExists(?string $table) + public function tableExists($table) { return $this->table('')->tableExists($table); } @@ -204,7 +204,6 @@ public function getConfig() * Get Table Name * @param string $table * @param array $data - * * @return string */ private static function compileTableWithPrefix($table = null, ?array $data = null) @@ -222,11 +221,10 @@ private static function compileTableWithPrefix($table = null, ?array $data = nul /** * Get currently selected driver data * - * @param string $mode - * + * @param string|null $mode * @return mixed */ - private function getDataByMode(?string $mode = null) + private function getDataByMode($mode = null) { return $this->getConfig()[$mode] ?? null; } @@ -247,9 +245,10 @@ private function setConnection($connection = null) /** * Set connection connection name * + * @param string|null $name * @return void */ - private function setConnectionName(?string $name = null) + private function setConnectionName($name = null) { $this->name = empty($name) ? 'default' : $name; } diff --git a/src/Connectors/SQLiteConnector.php b/src/Connectors/SQLiteConnector.php index 4000c00..5babb01 100644 --- a/src/Connectors/SQLiteConnector.php +++ b/src/Connectors/SQLiteConnector.php @@ -23,7 +23,7 @@ class SQLiteConnector * @var array */ protected $options = [ - PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, diff --git a/src/DatabaseConnector.php b/src/DatabaseConnector.php index b1cd1f0..71e169a 100644 --- a/src/DatabaseConnector.php +++ b/src/DatabaseConnector.php @@ -30,10 +30,10 @@ protected static function getDriverData($data = null) /** * Find Database Driver Name - * @param string $name + * @param string|null $name * @return string */ - protected static function getDriverName(?string $name = null) + protected static function getDriverName($name = null) { // try to get driver config data $config = config( @@ -74,11 +74,11 @@ protected static function createDriverData(?array $options = []) /** * Get supported database Driver - * @param string $driver + * @param string|null $driver * * @return string|null */ - public static function findDriver(?string $driver = null) + public static function findDriver($driver = null) { // collation get $driver = Str::lower($driver); @@ -91,11 +91,11 @@ public static function findDriver(?string $driver = null) /** * Get supported database Collation - * @param string $collation + * @param string|null $collation * * @return string|null */ - public static function findCollation(?string $collation = null) + public static function findCollation($collation = null) { // collation get $collation = Str::lower($collation); @@ -108,11 +108,11 @@ public static function findCollation(?string $collation = null) /** * Get supported database Charset - * @param string $charset + * @param string|null $charset * * @return string|null */ - public static function findCharset(?string $charset = null) + public static function findCharset($charset = null) { // charset get $charset = Str::lower($charset); @@ -150,7 +150,7 @@ private static function supportedCharsets() */ private static function supportedCollations() { - return ['utf8mb4_unicode_ci', 'utf8mb4_general_ci', 'utf8mb4_bin', 'utf8_general_ci', 'utf8_bin', 'latin1_general_ci', 'latin1_bin',]; + return ['utf8mb4_unicode_ci', 'utf8mb4_general_ci', 'utf8mb4_bin', 'utf8_general_ci', 'utf8_bin', 'latin1_general_ci', 'latin1_bin']; } } diff --git a/src/DatabaseManager.php b/src/DatabaseManager.php index 61a8a85..d0efcd5 100644 --- a/src/DatabaseManager.php +++ b/src/DatabaseManager.php @@ -21,7 +21,7 @@ class DatabaseManager extends DatabaseConnector { /** * Connect to a Database * - * @param string $name + * @param string|null $name * - [name] of connections in [config/database.php] file * * @param array $default @@ -29,7 +29,7 @@ class DatabaseManager extends DatabaseConnector { * * @return $this */ - public static function connection(?string $name = null, ?array $default = []) + public static function connection($name = null, ?array $default = []) { $config = self::driverValidator($name); if (!FileCache::has($config['key'])) { @@ -54,12 +54,12 @@ public static function connection(?string $name = null, ?array $default = []) /** * Get Connection data * - * @param string $name + * @param string|null $name * - [name] of connections\Default name is `default` * * @return mixed */ - public static function getConnection(?string $name = null) + public static function getConnection($name = null) { $key = self::getCacheKey($name); if (FileCache::has($key)) { @@ -75,7 +75,7 @@ public static function getConnection(?string $name = null) * @param string|null $name * @return void */ - public static function disconnect(?string $name = null) + public static function disconnect($name = null) { $name = empty($name) ? 'default' : $name; $key = self::getCacheKey($name); @@ -94,7 +94,7 @@ public static function disconnect(?string $name = null) * * @return object */ - public static function reconnect(?string $name = null, mixed $default = null) + public static function reconnect($name = null, mixed $default = null) { return self::connection($name, $default); } @@ -113,10 +113,10 @@ public static function getCacheKey($name = null) /** * get Cache Key name * - * @param string $name + * @param string|null $name * @return array */ - private static function driverValidator(?string $name = null) + private static function driverValidator($name = null) { $name = self::getDriverName($name); return [ diff --git a/src/Dummy/dummyGitIgnore.dum b/src/Dummy/dummyGitIgnore.dum index de05418..abe1654 100644 --- a/src/Dummy/dummyGitIgnore.dum +++ b/src/Dummy/dummyGitIgnore.dum @@ -4,4 +4,5 @@ /.vscode /.github .gitignore +.env composer.lock \ No newline at end of file diff --git a/src/Migrations/Blueprint.php b/src/Migrations/Blueprint.php index 27c4005..09675ac 100644 --- a/src/Migrations/Blueprint.php +++ b/src/Migrations/Blueprint.php @@ -27,9 +27,9 @@ class Blueprint{ /** * Creating Managers * - * @param string $tableName + * @param string|null $tableName */ - public function __construct(?string $tableName = null) + public function __construct($tableName = null) { $this->db = DB::connection(); $this->tableName = $tableName; diff --git a/src/Migrations/Migration.php b/src/Migrations/Migration.php index 7b436c7..26cd016 100644 --- a/src/Migrations/Migration.php +++ b/src/Migrations/Migration.php @@ -30,12 +30,12 @@ public static function getSession() /** * Create migration name * @param string $table_name - * @param string $type + * @param string|null $type * - optional $jobs\To create dummy Jobs table Data * * @return void */ - public static function create(?string $table_name, ?string $type = null) + public static function create($table_name, $type = null) { self::initStatic(); diff --git a/src/Migrations/Schema.php b/src/Migrations/Schema.php index 61d7f61..41bb904 100644 --- a/src/Migrations/Schema.php +++ b/src/Migrations/Schema.php @@ -72,7 +72,7 @@ public static function defaultStringLength($length = 255) * * @return \Tamedevelopers\Database\Migrations\Blueprint */ - public static function create(?string $tableName, callable $callback) + public static function create($tableName, callable $callback) { $callback(new Blueprint($tableName)); } @@ -91,7 +91,7 @@ public static function create(?string $tableName, callable $callback) * * @return array */ - public static function updateColumnDefaultValue(?string $table, ?string $column, mixed $value = null) + public static function updateColumnDefaultValue($table, $column, mixed $value = null) { self::initSchemaDatabase(); @@ -158,7 +158,7 @@ public static function updateColumnDefaultValue(?string $table, ?string $column, * * @return array */ - public static function dropTable(?string $tableName, $force = false) + public static function dropTable($tableName, $force = false) { self::initSchemaDatabase(); @@ -204,7 +204,7 @@ public static function dropTable(?string $tableName, $force = false) * * @return array */ - public static function dropColumn(?string $tableName, ?string $columnName) + public static function dropColumn($tableName, $columnName) { self::initSchemaDatabase(); diff --git a/src/Migrations/Traits/FilePathTrait.php b/src/Migrations/Traits/FilePathTrait.php index 235bf1f..3257f54 100644 --- a/src/Migrations/Traits/FilePathTrait.php +++ b/src/Migrations/Traits/FilePathTrait.php @@ -13,11 +13,11 @@ trait FilePathTrait{ /** * Get Traceable File name - * @param string $name + * @param string|null $name * * @return string|null\traceable */ - public function traceableTableFileName(?string $table = null) + public function traceableTableFileName($table = null) { // exception trace $exception = (new Exception)->getTrace(); diff --git a/src/Migrations/Traits/MigrationTrait.php b/src/Migrations/Traits/MigrationTrait.php index a031add..9b81d37 100644 --- a/src/Migrations/Traits/MigrationTrait.php +++ b/src/Migrations/Traits/MigrationTrait.php @@ -4,7 +4,7 @@ namespace Tamedevelopers\Database\Migrations\Traits; -use Tamedevelopers\Database\Env; +use Tamedevelopers\Support\Env; /** * @@ -16,12 +16,15 @@ trait MigrationTrait{ private static $migrations; private static $seeders; + /** * Run Migrations - * - * @return mixed + * + * @param string $table_name + * @param string|null $type + * @return void */ - private static function runMigration(?string $table_name, ?string $type = null) + private static function runMigration($table_name, $type = null) { // table name $case_table = self::toSnakeCase($table_name); @@ -159,7 +162,7 @@ private static function initStatic() * @return string * - String toSnakeCase */ - private static function toSnakeCase(?string $input) + private static function toSnakeCase($input) { $output = preg_replace_callback( '/[A-Z]/', @@ -178,7 +181,7 @@ function ($match) { * * @return array|string */ - private static function directoryfiles(?string $directory) + private static function directoryfiles($directory) { // read file inside folders $readDir = scandir($directory); diff --git a/src/Migrations/Traits/SchemaConfigurationTrait.php b/src/Migrations/Traits/SchemaConfigurationTrait.php index fece80c..0fc69b5 100644 --- a/src/Migrations/Traits/SchemaConfigurationTrait.php +++ b/src/Migrations/Traits/SchemaConfigurationTrait.php @@ -158,11 +158,11 @@ protected function queryForType_and_Length(?array $options = []) /** * Creating Query String for Collate - * @param string $getType + * @param string|null $getType * * @return string */ - protected function queryForCollate(?string $getType = null) + protected function queryForCollate($getType = null) { $columnDef = ""; if(in_array($getType, $this->collateTypes)){ @@ -177,12 +177,12 @@ protected function queryForCollate(?string $getType = null) /** * Creating Query String for Unsigned * @param array $options - * @param string $getType - * @param string $unsigned + * @param string|null $getType + * @param string|null $unsigned * * @return string */ - protected function queryForUnsigned(?array $options = [], ?string $getType = null, ?string $unsigned = null) + protected function queryForUnsigned(?array $options = [], $getType = null, $unsigned = null) { $columnDef = ""; if(isset($options['unsigned'])){ @@ -247,7 +247,7 @@ protected function queryForDefault(?array $options = []) * * @return string */ - protected function getColumnLength(?string $type, ?int $length = null) + protected function getColumnLength($type, ?int $length = null) { // if global length is defined if( defined('ORM_MAX_STRING_LENGTH') ){ @@ -308,7 +308,7 @@ protected function getColumnLength(?string $type, ?int $length = null) * * @return string */ - protected function getColumnType(?string $type) + protected function getColumnType($type) { $typeMap = [ 'increments' => 'int', @@ -354,7 +354,7 @@ protected function getColumnType(?string $type) * * @return string */ - protected function getUnsigned(?string $type) + protected function getUnsigned($type) { $typeUnassigned = [ 'increments' => 'UNSIGNED', @@ -372,11 +372,11 @@ protected function getUnsigned(?string $type) /** * Create generix identifier name - * @param string $name + * @param string|null $name * * @return string */ - protected function generix_name(?string $name = null) + protected function generix_name($name = null) { $column = $this->columns[count($this->columns) - 1]; $unique = (new Exception)->getTrace()[1]['function'] ?? '__'; diff --git a/src/Migrations/Traits/SchemeCollectionTrait.php b/src/Migrations/Traits/SchemeCollectionTrait.php index 80b2a82..2587b01 100644 --- a/src/Migrations/Traits/SchemeCollectionTrait.php +++ b/src/Migrations/Traits/SchemeCollectionTrait.php @@ -64,7 +64,7 @@ public function id($name = 'id') * * @return $this */ - public function primary(?string $name, $autoIncrement = true, $unsigned = true) + public function primary($name, ?bool $autoIncrement = true, ?bool $unsigned = true) { return $this->addColumn($name, 'bigInteger', [ 'primary' => "PRIMARY", @@ -75,11 +75,11 @@ public function primary(?string $name, $autoIncrement = true, $unsigned = true) /** * Creating Indexs - * @param string $name + * @param string|null $name * * @return $this */ - public function index(?string $name = null) + public function index($name = null) { $this->columns[count($this->columns) - 1]['index'] = $this->generix_name($name); @@ -88,11 +88,11 @@ public function index(?string $name = null) /** * Creating Indexs - * @param string $name + * @param string|null $name * * @return $this */ - public function unique(?string $name = null) + public function unique($name = null) { $this->columns[count($this->columns) - 1]['unique'] = $this->generix_name($name); @@ -128,13 +128,13 @@ public function foreignId($column) /** * Create a foreign key constraint on this column referencing the "id" column of the conventionally related table. * - * @param string $table + * @param string|null $table * @param string $column * - [optional] Default is `id` * * @return $this */ - public function constrained(?string $table = null, $column = 'id') + public function constrained($table = null, $column = 'id') { // we try to use defined table name, if no name is given to the method $tableName = explode('_', $this->tableName); diff --git a/src/Migrations/Traits/TableStructureTrait.php b/src/Migrations/Traits/TableStructureTrait.php index 2104283..2f90a0b 100644 --- a/src/Migrations/Traits/TableStructureTrait.php +++ b/src/Migrations/Traits/TableStructureTrait.php @@ -323,11 +323,11 @@ private function createTriggers() /** * Regixify the query. * - * @param string $query The query to be regixified. + * @param string|null $formatted The query to be regixified. * * @return string The regixified query. */ - private function regixifyQuery(?string $formatted) + private function regixifyQuery($formatted = null) { // clean string from begining and ending $formatted = preg_replace("/^[ \t]+|[ \t]+$/m", "", $formatted); diff --git a/src/Model.php b/src/Model.php index 3bf8d96..52e02fb 100644 --- a/src/Model.php +++ b/src/Model.php @@ -20,7 +20,6 @@ /** * @property string $table - * */ abstract class Model extends DB{ @@ -93,7 +92,7 @@ private static function initTableWithConnector() * * @return mixed */ - public static function modelException(?string $method = null, $args = null, $class = null) + public static function modelException($method = null, $args = null, $class = null) { // instance of DB Class $instance = !$class ? new self() : $class; diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 92a3d58..e23fc0e 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -1258,7 +1258,7 @@ public function orHavingRaw($sql, array $bindings = []) * * @return bool */ - public function tableExists(?string $table) + public function tableExists($table) { try{ $pdo = $this->connection->pdo; diff --git a/src/Traits/DBImportTrait.php b/src/Traits/DBImportTrait.php index 08e2237..eb56446 100644 --- a/src/Traits/DBImportTrait.php +++ b/src/Traits/DBImportTrait.php @@ -27,7 +27,7 @@ protected function isReadable(?array $readFile = null) * @param string|null $string * @return boolean */ - protected function isComment(?string $string = null) + protected function isComment($string = null) { // if first two is -- // or it's empty @@ -43,7 +43,7 @@ protected function isComment(?string $string = null) * @param string|null $string * @return boolean */ - protected function isQuery(?string $string = null) + protected function isQuery($string = null) { // check is last char is `;` if(substr(trim($string), -1, 1) == ';'){ diff --git a/src/Traits/DBSetupTrait.php b/src/Traits/DBSetupTrait.php index 2f4ef4a..1ec5602 100644 --- a/src/Traits/DBSetupTrait.php +++ b/src/Traits/DBSetupTrait.php @@ -20,7 +20,7 @@ trait DBSetupTrait{ * * @return \Tamedevelopers\Database\Schema\Builder */ - public static function table(string $table) + public static function table($table) { return (new Connector)->table($table); } @@ -32,7 +32,7 @@ public static function table(string $table) * * @return bool */ - public static function tableExists(?string $table) + public static function tableExists($table) { return (new Connector)->table('')->tableExists($table); } diff --git a/src/helpers.php b/src/helpers.php index 2fe1f88..adfb57d 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -11,13 +11,13 @@ /** * Configure Instance of AutoLoader `Environment` * - * @param string $custom_path + * @param string|null $custom_path * path \Path to .env file * - [optional] path \By default we use project root path * * @return void */ - function autoloader_start(?string $custom_path = null) + function autoloader_start($custom_path = null) { (new AutoLoader)->start($custom_path); } @@ -43,12 +43,12 @@ function db(?string $key = 'default') /** * Get Database Connection * - * @param string $type + * @param string|null $type * - [optional] reponse|message|driver * * @return mixed */ - function db_connection(?string $type = null) + function db_connection($type = null) { return db()->dbConnection($type); }