From 8022208ae429b559b0aaa5ab83c717c30653d0d4 Mon Sep 17 00:00:00 2001 From: Rocco Howard Date: Wed, 24 Jan 2018 03:26:27 +0000 Subject: [PATCH] Added FileSystem and Database facades --- src/Database.php | 81 ++++++++++++++++++++++++++++++++++++++++ src/DatabaseFacade.php | 32 ++++++++++++++++ src/FileSystem.php | 28 ++++++++++++++ src/FileSystemFacade.php | 32 ++++++++++++++++ src/ServiceProvider.php | 10 ++++- 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100755 src/Database.php create mode 100755 src/DatabaseFacade.php create mode 100755 src/FileSystem.php create mode 100755 src/FileSystemFacade.php diff --git a/src/Database.php b/src/Database.php new file mode 100755 index 0000000..36f28dc --- /dev/null +++ b/src/Database.php @@ -0,0 +1,81 @@ + [1, 'DAY'], + '7d' => [7, 'DAY'], + '1m' => [1, 'MONTH'], + '1y' => [1, 'YEAR'] + ]; + + /** + * Converts a unit/interval string to the correct INTERVAL constant. + * + * eg 1y = [1, YEAR] + * + * @return array|null + */ + public function parseUnitInterval($unit_interval) + { + if (array_has(self::$static_unit_interval, $unit_interval)) { + return array_get(self::$static_unit_interval, $unit_interval); + } + + $unit = preg_replace("/([A-Za-z]*?)/", '', $unit_interval); + $interval = preg_replace("/([0-9]*?)/", '', $unit_interval); + + $interval = $this->convertInterval($interval); + + if ($unit > 0 && $interval !== false) { + return [$unit, $interval]; + } + + return [null, null]; + } + + /** + * Convert the interval string to the mysql constant. + * + * @param string $interval + * + * @return string + */ + public function convertInterval($interval) + { + switch (strtolower($interval)) { + case 'y': + case 'year': + $interval = 'YEAR'; + break; + case 'm': + case 'month': + $interval = 'MONTH'; + break; + case 'd': + case 'day': + $interval = 'DAY'; + break; + case 'h': + case 'hour': + $interval = 'HOUR'; + break; + case 'i': + case 'min': + case 'minute': + $iterval = 'MINUTE'; + break; + case 's': + case 'sec': + case 'second': + $interval = 'SECOND'; + break; + default: + $interval = false; + } + + return $interval; + } +} diff --git a/src/DatabaseFacade.php b/src/DatabaseFacade.php new file mode 100755 index 0000000..63ea17c --- /dev/null +++ b/src/DatabaseFacade.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Support\Facades\Facade as BaseFacade; + +/** + * This is the facade class. + * + * @author Rocco Howard + */ +class DatabaseFacade extends BaseFacade +{ + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return 'Database'; + } +} diff --git a/src/FileSystem.php b/src/FileSystem.php new file mode 100755 index 0000000..d56a7a5 --- /dev/null +++ b/src/FileSystem.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Support\Facades\Facade as BaseFacade; + +/** + * This is the facade class. + * + * @author Rocco Howard + */ +class FileSystemFacade extends BaseFacade +{ + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return 'FileSystem'; + } +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index b00f5e6..cb57067 100755 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -38,6 +38,14 @@ public function register() return new Aws(); }); + $this->app->singleton('Database', function () { + return new Database(); + }); + + $this->app->singleton('FileSystem', function () { + return new FileSystem(); + }); + $this->app->singleton('Human', function () { return new Human(); }); @@ -58,6 +66,6 @@ public function register() */ public function provides() { - return ['Aws', 'Human', 'SemVer', 'Timezone']; + return ['Aws', 'Database', 'Human', 'SemVer', 'Timezone']; } }