Airship\Engine\Bolt\Supplier::getSupplier PHP Method

getSupplier() public method

Load all of the supplier's Ed25519 public keys
public getSupplier ( string $supplier = '', boolean $force_flush = false ) : Supplier | Supplier[]
$supplier string
$force_flush boolean
return Airship\Engine\Continuum\Supplier | Airship\Engine\Continuum\Supplier[]
    public function getSupplier(string $supplier = '', bool $force_flush = false)
    {
        if (empty($supplier)) {
            // Fetch all suppliers
            if ($force_flush || empty($this->supplierCache)) {
                $supplierCache = [];
                $allSuppliers = \Airship\list_all_files(ROOT . '/config/supplier_keys', 'json');
                foreach ($allSuppliers as $supplierKeyFile) {
                    // We want everything except the .json
                    $supplier = $this->escapeSupplierName(Binary::safeSubstr($this->getEndPiece($supplierKeyFile), 0, -5));
                    try {
                        $data = \Airship\loadJSON($supplierKeyFile);
                    } catch (FileNotFound $ex) {
                        $data = [];
                    }
                    $supplierCache[$supplier] = new SupplierObject($supplier, $data);
                }
                $this->supplierCache = $supplierCache;
            }
            return $this->supplierCache;
        }
        // Otherwise, we're just fetching one supplier's keys
        if ($force_flush || empty($this->supplierCache[$supplier])) {
            try {
                $supplier = $this->escapeSupplierName($supplier);
                $supplierFile = ROOT . '/config/supplier_keys/' . $supplier . '.json';
                if (!\file_exists($supplierFile)) {
                    throw new NoSupplier(\__("Supplier file not found: %s", "default", $supplierFile));
                }
                $data = \Airship\loadJSON($supplierFile);
            } catch (FileNotFound $ex) {
                throw new NoSupplier(\__("Supplier not found: %s", "default", $supplier), 0, $ex);
            }
            $this->supplierCache[$supplier] = new SupplierObject($supplier, $data);
        }
        if (isset($this->supplierCache[$supplier])) {
            return $this->supplierCache[$supplier];
        }
        throw new NoSupplier();
    }