Skip to content

Commit

Permalink
Crucial update, Same usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrick Peter committed Oct 8, 2023
1 parent 6d6b3e3 commit 3524da1
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 76 deletions.
45 changes: 45 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
4 changes: 2 additions & 2 deletions src/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
/*
|--------------------------------------------------------------------------
Expand Down
15 changes: 7 additions & 8 deletions src/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connectors/SQLiteConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions src/DatabaseConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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'];
}

}
16 changes: 8 additions & 8 deletions src/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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
* [optional] The default value to return if the configuration option is not found
*
* @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'])) {
Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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 [
Expand Down
1 change: 1 addition & 0 deletions src/Dummy/dummyGitIgnore.dum
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.vscode
/.github
.gitignore
.env
composer.lock
4 changes: 2 additions & 2 deletions src/Migrations/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Migrations/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions src/Migrations/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/Migrations/Traits/FilePathTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 9 additions & 6 deletions src/Migrations/Traits/MigrationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Tamedevelopers\Database\Migrations\Traits;

use Tamedevelopers\Database\Env;
use Tamedevelopers\Support\Env;

/**
*
Expand All @@ -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);
Expand Down Expand Up @@ -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]/',
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 3524da1

Please sign in to comment.