I would like to use https://github.com/azuyalabs/yasumi package in a laravel application.
I did the installation using:
$ composer require azuyalabs/yasumi
now, with a laravel package I would, after installing register the service providers and the aliases (facades) in config/app.php:
This library has some facades of it's own.
What would be the way to integrate this library into Laravel ?
Should I create a new Service Provider class and register Yasumi within that ?
Something like:
class YasumiServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
}
}
I wouldn't do that in the vendor folder as that is to be overwritten or even replaced at times.
Expanding from my comment:
Fork the repository and make changes (note, you can always make "self pull-requests" from original to your fork).
After changes are done use this inside your composer.json file
{
"name": "...",
"type": "project",
"description": "...",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/{YOUR GITHUB NAME}/yasumi"
}
],
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"azuyalabs/yasumi": "dev-{NAME OF BRANCH IN FORK}"
},
...
Note: placeholders are in use
{YOUR GITHUB NAME}and{NAME OF BRANCH IN FORK}
Note: to sync your fork using webhooks see this.
Additional make a PR so other can use Laravel service provider.
Here's a simpler way.
In App\Providers\AppServiceProvider
public function register()
{
$this->app->singleton('yasumi', \Yasumi\Yasumi::create('USA', 2016));
}
then in your app, you can use
$holidays = app('yasumi'); // now the equivalent of = \Yasumi\Yasumi::create('USA', 2016)
Then carry on as in the documentation.
You could even avoid the variable assignment, e.g.
foreach(app('yasumi')->getHolidayNames() as $name)
{
echo $name . PHP_EOL;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With