Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7] Move Carbon macro methods #23938

Merged
merged 3 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"erusev/parsedown": "^1.7",
"league/flysystem": "^1.0.8",
"monolog/monolog": "^1.12",
"nesbot/carbon": "1.25.*",
"nesbot/carbon": "^1.26.3",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0",
"ramsey/uuid": "^3.7",
Expand Down
41 changes: 1 addition & 40 deletions src/Illuminate/Support/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,8 @@

namespace Illuminate\Support;

use JsonSerializable;
use Carbon\Carbon as BaseCarbon;
use Illuminate\Support\Traits\Macroable;

class Carbon extends BaseCarbon implements JsonSerializable
class Carbon extends BaseCarbon
{
use Macroable;

/**
* The custom Carbon JSON serializer.
*
* @var callable|null
*/
protected static $serializer;

/**
* Prepare the object for JSON serialization.
*
* @return array|string
*/
public function jsonSerialize()
{
if (static::$serializer) {
return call_user_func(static::$serializer, $this);
}

$carbon = $this;

return call_user_func(function () use ($carbon) {
return get_object_vars($carbon);
});
}

/**
* JSON serialize all Carbon instances using the given callback.
*
* @param callable $callback
* @return void
*/
public static function serializeUsing($callback)
{
static::$serializer = $callback;
}
}
4 changes: 2 additions & 2 deletions tests/Support/SupportCarbonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testCarbonIsMacroableWhenCalledStatically()

/**
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Method Illuminate\Support\Carbon::nonExistingStaticMacro does not exist.
* @expectedExceptionMessage nonExistingStaticMacro does not exist.
*/
public function testCarbonRaisesExceptionWhenStaticMacroIsNotFound()
{
Expand All @@ -67,7 +67,7 @@ public function testCarbonRaisesExceptionWhenStaticMacroIsNotFound()

/**
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Method Illuminate\Support\Carbon::nonExistingMacro does not exist.
* @expectedExceptionMessage nonExistingMacro does not exist.
*/
public function testCarbonRaisesExceptionWhenMacroIsNotFound()
{
Expand Down