Exemple #1
0
 /**
  *
  * @return Config
  */
 public function getLayoutStructure()
 {
     if (null === $this->layoutStructure) {
         $this->layoutStructure = new Config([], true);
         $handles = $this->getHandles();
         $event = new UpdateEvent();
         $event->setLayoutStructure($this->layoutStructure);
         $event->setHandles($handles);
         $event->setArea($this->getArea());
         $event->setName(UpdateEvent::EVENT_COLLECT);
         $event->setTarget($this);
         $results = $this->getEventManager()->triggerEventUntil(function ($result) {
             return $result instanceof Config;
         }, $event);
         if ($results->stopped()) {
             $this->layoutStructure = $results->last();
         } else {
             $this->fetchUpdates();
             $event->setName(UpdateEvent::EVENT_COLLECT_POST);
             $this->getEventManager()->triggerEvent($event);
         }
         $this->layoutStructure->setReadOnly();
     }
     return $this->layoutStructure;
 }
Exemple #2
0
 /**
  * getMergedConfig
  * Build a merged config object for all loaded modules
  * 
  * @return Zend\Config\Config
  */
 public function getMergedConfig($readOnly = true)
 {
     if (null === $this->mergedConfig) {
         $this->setMergedConfig(new Config(array(), true));
     }
     if (true === $readOnly) {
         $this->mergedConfig->setReadOnly();
     }
     return $this->mergedConfig;
 }
 /**
  *
  * @return Config
  */
 public function getLayoutStructure()
 {
     if (null === $this->layoutStructure) {
         $this->layoutStructure = new Config([], true);
         $handles = $this->getHandles();
         $event = new UpdateEvent();
         $event->setLayoutStructure($this->layoutStructure);
         $event->setHandles($handles);
         $event->setArea($this->getArea());
         $results = $this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this, $event, function ($result) {
             return $result instanceof Config;
         });
         if ($results->stopped()) {
             $this->layoutStructure = $results->last();
         } else {
             $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $event);
         }
         $this->layoutStructure->setReadOnly();
     }
     return $this->layoutStructure;
 }
 /**
  * @group ZF-4728
  *
  */
 public function testSetReadOnlyAppliesToChildren()
 {
     $config = new Config($this->all, true);
     $config->setReadOnly();
     $this->assertTrue($config->isReadOnly());
     $this->assertTrue($config->one->isReadOnly(), 'First level children are writable');
     $this->assertTrue($config->one->two->isReadOnly(), 'Second level children are writable');
 }
 /**
  * Validate fields and their data
  *
  * @param Config $fields Fields
  * @return Config Validated fields
  * @throws Exception
  */
 protected function validateFields(Config $fields) : Config
 {
     $valid_field_attributes = ['name', 'required', 'form', 'multivalue'];
     /** @var Config $field */
     foreach ($fields as $field) {
         if (!$field->offsetExists('name')) {
             throw new Exception("Name is mandatory attribute for a field!");
         }
         foreach ($field as $attribute => $value) {
             if (!in_array($attribute, $valid_field_attributes)) {
                 throw new Exception(sprintf("Field base attribute %s is not valid!", $attribute));
             }
             switch ($attribute) {
                 case 'required':
                     $field->offsetSet($attribute, (int) $value);
                     if ($value !== 1) {
                         throw new Exception(sprintf("Only valid values for required is 1, value of '%s' (%s) was given.", $value, gettype($value)));
                     }
                     break;
             }
             // TODO check if attribute has a validator?
         }
     }
     $fields->setReadOnly();
     return $fields;
 }