Skip to content

Commit

Permalink
Added FileSystem and Database facades
Browse files Browse the repository at this point in the history
  • Loading branch information
RoccoHoward committed Jan 24, 2018
1 parent 424effe commit 8022208
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace HnhDigital\HelperCollection;

class Database
{
private static $static_unit_interval = [
'1d' => [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;
}
}
32 changes: 32 additions & 0 deletions src/DatabaseFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace HnhDigital\HelperCollection;

/*
* This file is part of Laravel Navigation Builder.
*
* (c) Rocco Howard <[email protected]>
*
* 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 <[email protected]>
*/
class DatabaseFacade extends BaseFacade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Database';
}
}
28 changes: 28 additions & 0 deletions src/FileSystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace HnhDigital\HelperCollection;

class FileSystem
{
/**
* Enclose the provided string with slashes.
*
* @param string $path
*
* @return string
*/
public function enclosePath($path)
{
// Add starting slash.
if (substr($path, 0, 1) !== '/') {
$path = '/'.$path;
}

// Add trailing slash.
if (substr($path, -1, 1) !== '/') {
$path .= '/';
}

return $path;
}
}
32 changes: 32 additions & 0 deletions src/FileSystemFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace HnhDigital\HelperCollection;

/*
* This file is part of Laravel Navigation Builder.
*
* (c) Rocco Howard <[email protected]>
*
* 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 <[email protected]>
*/
class FileSystemFacade extends BaseFacade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'FileSystem';
}
}
10 changes: 9 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -58,6 +66,6 @@ public function register()
*/
public function provides()
{
return ['Aws', 'Human', 'SemVer', 'Timezone'];
return ['Aws', 'Database', 'Human', 'SemVer', 'Timezone'];
}
}

0 comments on commit 8022208

Please sign in to comment.