PackageList.php

<?php

namespace Lia\Compo;

class PackageList extends \Lia\Compo {

    //@TODO write tests for package list

    protected $packages = [];

    public function apiAdd_lia_package_addPackage($package, $name){
        $this->packages[$name] = $package;
    }
    //@TODO maybe rename getPackage() to package(). I like the short short version, but... get is more explicit
    public function apiGet_lia_package_getPackage($name){
        $package = $this->packages[$name] ?? null;
        if ($package==null){
            throw new \Lia\Exception\Base("Package '{$name}' was not found.");
        }
        return $package;
    }


    // public function compo($name){
    // // TAKEN FROM Liaison. might be something to add. LEAVE THIS HERE, since I think I want to use it.
    //     $compos = [];
    //     foreach ($this->packages as $package){
    //         $compo = $package->compo($name);
    //         if ($compo!=null)$compos[] = $compo;
    //     }
    //     if (count($compos)==0) return null;
    //     else if (count($compos)==1)return $compos[0];
    //     else throw new \Exception("Multiple compos were found for '{$name}'. Try calling \$lia->package(...)->compo('{$name}'); to specify the source package.");


    // }
}