Skip to content

Commit

Permalink
Allow to call macros directly on Date
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Apr 6, 2019
1 parent f816ca2 commit 7621ba1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Support/DateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public function __call($method, $parameters)
$dateClass = static::$dateClass ?: $defaultClassName;

// Check if date can be created using public class method...
if (method_exists($dateClass, $method)) {
if (method_exists($dateClass, $method) ||
method_exists($dateClass, 'hasMacro') && $dateClass::hasMacro($method)) {
return $dateClass::$method(...$parameters);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Support/DateFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ public function testUseInvalidHandler()
{
DateFactory::use(42);
}

public function testMacro()
{
Date::macro('returnNonDate', function () {
return 'string';
});

$this->assertSame('string', Date::returnNonDate());
}
}

0 comments on commit 7621ba1

Please sign in to comment.