Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mautic.corals.io/vendor/jms/serializer-bundle/Serializer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mautic.corals.io/vendor/jms/serializer-bundle/Serializer/StopwatchEventSubscriber.php
<?php

declare(strict_types=1);

namespace JMS\SerializerBundle\Serializer;

use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\ObjectEvent;

/**
 * @author Adrien Brault <[email protected]>
 */
class StopwatchEventSubscriber implements EventSubscriberInterface
{
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            ['event' => Events::PRE_SERIALIZE, 'method' => 'onPreSerialize', 'priority' => -1000],
            ['event' => Events::POST_SERIALIZE, 'method' => 'onPostSerialize', 'priority' => 1000],
        ];
    }

    /**
     * A stopwatch object which exposes a start($name) and a stop($name) method.
     *
     * @var object
     */
    private $stopwatch;

    /**
     * @var string
     */
    private $name;

    /**
     * @var object
     */
    private $rootObject;

    public function __construct($stopwatch, $name = 'jms_serializer')
    {
        $this->stopwatch = $stopwatch;
        $this->name = $name;
    }

    public function onPreSerialize(ObjectEvent $event)
    {
        if ($event->getContext()->getDepth() > 1 || null !== $this->rootObject) {
            return;
        }

        $this->stopwatch->start($this->name);
        $this->rootObject = $event->getObject();
    }

    public function onPostSerialize(ObjectEvent $event)
    {
        if (null === $this->rootObject || $event->getObject() !== $this->rootObject) {
            return;
        }

        $this->stopwatch->stop($this->name);
        $this->rootObject = null;
    }
}

Spamworldpro Mini