kylekatarnls / business-time

Carbon mixin to handle business days and opening hours
MIT License
297 stars 14 forks source link

Exception when calling methods from this package #49

Closed Bjornar97 closed 3 years ago

Bjornar97 commented 3 years ago

Im using Laravel 8

When Im trying to use methods from this package I get the exception shown below, however methods from business-day are working fine.

  Class name must be a valid object or a string

  at vendor/cmixin/business-time/src/BusinessTime/MixinBase.php:147
    143▕         [$region, $holidays, $defaultOpeningHours] = self::getOpeningHoursOptions(
    144▕             $defaultOpeningHours,
    145▕             $arguments,
    146▕             function ($date) use ($carbonClass) {
  ➜ 147▕                 return $carbonClass::instance($date)->isHoliday();
    148▕             }
    149▕         );
    150▕ 
    151▕         foreach ($carbonClasses as $carbonClass) {

  1   vendor/cmixin/business-time/src/BusinessTime/DefinitionParser.php:199
      BusinessTime\MixinBase::BusinessTime\{closure}()

  2   vendor/spatie/opening-hours/src/OpeningHours.php:253
      BusinessTime\DefinitionParser::BusinessTime\{closure}()

  3   vendor/spatie/opening-hours/src/OpeningHours.php:312
      Spatie\OpeningHours\OpeningHours::forDate()

  4   vendor/spatie/opening-hours/src/OpeningHours.php:319
      Spatie\OpeningHours\OpeningHours::isOpenAt()

  5   vendor/cmixin/business-time/src/BusinessTime/Traits/IsMethods.php:75
      Spatie\OpeningHours\OpeningHours::isClosedAt()

config/carbon.php:

<?php

return [
    'opening-hours' => [
        'monday' => ['08:00-16:00'],
        'tuesday' => ['08:00-16:00'],
        'wednesday' => ['08:00-16:00'],
        'thursday' => ['08:00-16:00'],
        'friday' => ['08:00-16:00'],
        'saturday' => [],
        'sunday' => [],
        'exceptions' => [],
    ],
    'holidaysAreClosed' => true,
    'holidays' => [
        // Loads the norwegian holidays
        'region' => 'no',
    ],
];
Bjornar97 commented 3 years ago

Example: dd(Carbon::parse("2021-09-04")->nextOpen());

Bjornar97 commented 3 years ago

It works if I add BusinessTime::enable('Illuminate\Support\Carbon', config("carbon.opening-hours")); to AppServiceProvider.

kylekatarnls commented 3 years ago

Thanks for your report, I can reproduce it with 1.11.1 and checked 1.11.0 which is fine, so we have a regression in the very last patch.

You can exclude this version to fix it:

composer.json:

...
"require": {
   ...
   "cmixin/business-time": "^1.11 !=1.11.1",
kylekatarnls commented 3 years ago

Fix released in 1.11.2, please try to upgrade and rerun. 🙏

Bjornar97 commented 3 years ago

It is working! Thank you for the incredibly fast fix 👍🏻