-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from kylekatarnls/laravel-provider
Laravel provider
- Loading branch information
Showing
11 changed files
with
1,453 additions
and
13 deletions.
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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/tests export-ignore | ||
/.codeclimate.yml export-ignore | ||
/.editorconfig export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.styleci.yml export-ignore | ||
/.travis.yml export-ignore | ||
/*.md export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore | ||
/.codeclimate.yml export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.multi-tester.yml export-ignore | ||
/.travis.yml export-ignore | ||
/*.md export-ignore | ||
/types.php export-ignore | ||
/prepare-names-files.php export-ignore | ||
/phpmd.xml export-ignore | ||
/phpunit.xml.dist export-ignore |
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
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,41 @@ | ||
<?php | ||
|
||
namespace Cmixin\BusinessDay\Laravel; | ||
|
||
use Closure; | ||
use Cmixin\BusinessDay; | ||
|
||
class ServiceProvider extends \Illuminate\Support\ServiceProvider | ||
{ | ||
public function boot() | ||
{ | ||
$config = $this->app->get('config')->get('carbon.holidays'); | ||
|
||
if ($config instanceof Closure) { | ||
$config = $config($this->app); | ||
} | ||
|
||
if (is_array($config) && isset($config['region'])) { | ||
$classes = array_filter(array( | ||
'Carbon\Carbon', | ||
'Carbon\CarbonImmutable', | ||
'Illuminate\Support\Carbon', | ||
), 'class_exists'); | ||
|
||
// @codeCoverageIgnoreStart | ||
if (class_exists('Illuminate\Support\Facades\Date') && | ||
(($now = \Illuminate\Support\Facades\Date::now()) instanceof \DateTimeInterface) && | ||
!in_array($class = get_class($now), $classes)) { | ||
$classes[] = $class; | ||
} | ||
// @codeCoverageIgnoreEnd | ||
|
||
BusinessDay::enable($classes, $config['region'], isset($config['with']) ? $config['with'] : null); | ||
} | ||
} | ||
|
||
public function register() | ||
{ | ||
// Needed for Laravel < 5.3 compatibility | ||
} | ||
} |
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
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,18 @@ | ||
<?php | ||
|
||
class App | ||
{ | ||
public $region = 'us'; | ||
|
||
public function get($name) | ||
{ | ||
return $name === 'config' ? $this : function ($app) { | ||
return array( | ||
'region' => $app->region, | ||
'with' => array( | ||
'foo' => '09-07', | ||
), | ||
); | ||
}; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Illuminate\Support; | ||
|
||
class ServiceProvider | ||
{ | ||
/** | ||
* @var \App | ||
*/ | ||
public $app; | ||
|
||
public function __construct() | ||
{ | ||
include_once __DIR__.'/App.php'; | ||
$this->app = new \App(); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Tests\Carbon\Laravel; | ||
|
||
use Carbon\Carbon; | ||
use Cmixin\BusinessDay\Laravel\ServiceProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ServiceProviderTest extends TestCase | ||
{ | ||
public function testBoot() | ||
{ | ||
include_once __DIR__.'/ServiceProvider.php'; | ||
$service = new ServiceProvider(); | ||
$message = null; | ||
|
||
Carbon::macro('isHoliday', null); | ||
|
||
try { | ||
Carbon::parse('2019-04-08')->isHoliday(); | ||
} catch (\BadMethodCallException $e) { | ||
$message = $e->getMessage(); | ||
} | ||
|
||
$this->assertSame('Method isHoliday does not exist.', $message); | ||
|
||
$service->boot(); | ||
|
||
$this->assertSame('foo', Carbon::parse('2019-09-07')->getHolidayId()); | ||
$this->assertSame('us-national', Carbon::getHolidaysRegion()); | ||
|
||
$this->assertNull($service->register()); | ||
} | ||
} |
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
Oops, something went wrong.