Download the PHP package cmixin/season without Composer
On this page you can find all versions of the php package cmixin/season. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cmixin/season
More information about cmixin/season
Files in cmixin/season
Package season
Short Description Carbon mixin to handle business days and opening hours
License MIT
Informations about the package season
Season
DateTime
modifiers such as startOfSeason
, isInSummer
Season
can be used as a service which can work with anyDateTime
orDateTimeImmutable
object or date strings (which includes any subclass such asCarbon
orChronos
).- Or it can be used as a mixin to call the methods directly on
Carbon
objects. - Mixin get automatically enabled on Laravel if auto-discovery is on.
How to use
The simple way
Methods are available from the class \Season\Season
which is cheap to create,
so you can just call methods from a new class everytime.
As a good practice, it's recommended you import the class with use Season\Season;
at the beginning of the file:
And also to keep the same instance to re-use multiple times:
As a service
You can use dependency injection with your framework:
With Laravel it will be provided by default.
With Symfony, you'll have to register \Season\Season
as a service and
so edit config/services.yaml the following way:
Learn more from Symfony documentation: Configuring Services in the Container
As Carbon methods (mixin)
You can use mixin on CarbonImmutable
, Carbon
or any of
their subclasses.
Configuration
Disable mixin in Laravel
If you use Laravel but don't want to enable Season
mixin
globally for Carbon
, you can remove it from auto-discovery using:
Customize days
By default, Season
is created with the following config:
mapping the month (as key) with the day (as value) for each season start.
But you can pass a custom config with other days as long as the keys remain.
In Laravel, you can set the config in config/season.php which will apply to both the mixin and the service:
When using Carbon
mixin alone, you can still call setSeasonConfig()
to
change the config globally:
Or apply a config on specific call:
With Symfony you can edit config/services.yaml to configure the service: