loadCargo() public static method

Store cargo to be rendered into a template
public static loadCargo ( string $name, string $source )
$name string
$source string File path (can be within phar://)
Ejemplo n.º 1
0
 /**
  * @route motif-config/{string}
  *
  * @param string $motifName
  */
 public function configure(string $motifName)
 {
     $motifs = $this->getAllMotifs();
     if (!\array_key_exists($motifName, $motifs)) {
         \Airship\redirect($this->airship_cabin_prefix . '/motifs');
     }
     if (!$this->can('update')) {
         \Airship\redirect($this->airship_cabin_prefix . '/motifs');
     }
     $selected = $motifs[$motifName];
     $path = ROOT . '/Motifs/' . $selected['supplier'] . '/' . $selected['name'];
     // Should we load overload the configuration lens?
     if (\file_exists($path . '/lens/config.twig')) {
         Gadgets::loadCargo('bridge_motifs_config_overloaded', 'motif/' . $motifName . '/config.twig');
     }
     $inputFilter = null;
     if (\file_exists($path . '/config_filter.php')) {
         $inputFilter = $this->getConfigFilter($path . '/config_filter.php');
     }
     try {
         $motifConfig = \Airship\loadJSON(ROOT . '/config/motifs/' . $motifName . '.json');
     } catch (\Throwable $ex) {
         $motifConfig = [];
     }
     // Handle POST data
     if ($inputFilter instanceof InputFilterContainer) {
         $post = $this->post($inputFilter);
     } else {
         $post = $this->post();
         if (\is_string($post['motif_config'])) {
             $post['motif_config'] = \Airship\parseJSON($post['motif_config'], true);
         }
     }
     if ($post) {
         if (empty($post['motif_config'])) {
             $post['motif_config'] = [];
         }
         if ($this->saveMotifConfig($motifName, $post['motif_config'])) {
             \Airship\redirect($this->airship_cabin_prefix . '/motif_config/' . $motifName);
         }
     }
     $this->lens('motif_configure', ['cabin_name' => $motifName, 'motifs' => $motifs, 'motif_config' => $motifConfig, 'title' => \__('Configuring %s/%s', 'default', Util::noHTML($selected['supplier']), Util::noHTML($selected['name']))]);
 }
Ejemplo n.º 2
0
 /**
  * Load the cargo for these motifs
  *
  * @param string $name
  * @return self
  */
 public function loadMotifCargo(string $name) : self
 {
     $state = State::instance();
     if (isset($state->motifs[$name]) && isset($state->motifs[$name]['config']['cargo'])) {
         $cargoIterator = isset($state->cargoIterator) ? $state->cargoIterator : [];
         foreach ($state->motifs[$name]['config']['cargo'] as $key => $subPath) {
             $cargoIterator[$key] = 0;
             Gadgets::loadCargo($key, 'motif/' . $name . '/cargo/' . $subPath);
         }
         $state->cargoIterator = $cargoIterator;
     }
     return $this;
 }