mirror of
https://github.com/flarum/core.git
synced 2025-10-27 13:40:24 +01:00
Move events to Flarum\Api namespace
This commit is contained in:
83
src/Api/Event/Serializing.php
Normal file
83
src/Api/Event/Serializing.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Event;
|
||||
|
||||
use DateTime;
|
||||
use Flarum\Api\Serializer\AbstractSerializer;
|
||||
|
||||
/**
|
||||
* Prepare API attributes.
|
||||
*
|
||||
* This event is fired when a serializer is constructing an array of resource
|
||||
* attributes for API output.
|
||||
*/
|
||||
class Serializing
|
||||
{
|
||||
/**
|
||||
* The class doing the serializing.
|
||||
*
|
||||
* @var AbstractSerializer
|
||||
*/
|
||||
public $serializer;
|
||||
|
||||
/**
|
||||
* The model being serialized.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* The serialized attributes of the resource.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attributes;
|
||||
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @param AbstractSerializer $serializer The class doing the serializing.
|
||||
* @param object|array $model The model being serialized.
|
||||
* @param array $attributes The serialized attributes of the resource.
|
||||
*/
|
||||
public function __construct(AbstractSerializer $serializer, $model, array &$attributes)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
$this->model = $model;
|
||||
$this->attributes = &$attributes;
|
||||
$this->actor = $serializer->getActor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serializer
|
||||
* @return bool
|
||||
*/
|
||||
public function isSerializer($serializer)
|
||||
{
|
||||
return $this->serializer instanceof $serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime|null $date
|
||||
* @return string|null
|
||||
*/
|
||||
public function formatDate(DateTime $date = null)
|
||||
{
|
||||
if ($date) {
|
||||
return $date->format(DateTime::RFC3339);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user