MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/sites.artinside.com.br/festival/vendor/aplus/debug/src/Collection.php
<?php declare(strict_types=1);
/*
 * This file is part of Aplus Framework Debug Library.
 *
 * (c) Natan Felles <natanfelles@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Framework\Debug;

use RuntimeException;

/**
 * Class Collection.
 *
 * @package debug
 */
class Collection
{
    protected string $name;
    /**
     * @var array<Collector>
     */
    protected array $collectors = [];
    /**
     * @var array<string>
     */
    protected array $actions = [];
    protected string $icon = '';
    protected string $iconPath;

    public function __construct(string $name)
    {
        $this->name = $name;
        $this->prepare();
    }

    protected function prepare() : void
    {
        if (isset($this->iconPath)) {
            if (!\is_file($this->iconPath)) {
                throw new RuntimeException(
                    'Icon path is invalid: ' . $this->iconPath
                );
            }
            $this->setIcon((string) \file_get_contents($this->iconPath));
        }
    }

    public function getName() : string
    {
        return $this->name;
    }

    public function getSafeName() : string
    {
        return Debugger::makeSafeName($this->getName());
    }

    public function addCollector(Collector $collector) : static
    {
        $this->collectors[] = $collector;
        return $this;
    }

    /**
     * @return array<Collector>
     */
    public function getCollectors() : array
    {
        return $this->collectors;
    }

    public function addAction(string $action) : static
    {
        $this->actions[] = $action;
        return $this;
    }

    /**
     * @return array<string>
     */
    public function getActions() : array
    {
        return $this->actions;
    }

    public function hasCollectors() : bool
    {
        return !empty($this->collectors);
    }

    /**
     * @return array<int,array<int,array<string,mixed>>>
     */
    public function getActivities() : array
    {
        $result = [];
        foreach ($this->getCollectors() as $collector) {
            $activities = $collector->getActivities();
            if ($activities) {
                foreach ($activities as &$activity) {
                    $activity = \array_merge([
                        'collection' => $this->getName(),
                    ], $activity);
                }
                unset($activity);
                $result[] = $activities;
            }
        }
        return $result;
    }

    public function getIcon() : string
    {
        return $this->icon;
    }

    public function setIcon(string $icon) : static
    {
        $this->icon = $icon;
        return $this;
    }

    public function hasIcon() : bool
    {
        return $this->icon !== '';
    }
}