-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FileSystem and Database facades
- Loading branch information
1 parent
424effe
commit 8022208
Showing
5 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters