Пример #1
0
 /**
  * @see \Ableron\Lib\Storage\AbstractStorage::performSet()
  */
 protected function performSet(string $storageKey, StorageItemInterface $storageItem)
 {
     // store data in array
     $this->arrayStorage->set($storageKey, $storageItem);
     // indicate that data has been stored successfully
     return true;
 }
 /**
  * Reads all settings from database.
  *
  * @return void
  */
 private function readSettings()
 {
     /**
      * @var \Ableron\Modules\Core\Model\Entities\SettingEntity $settingEntity
      */
     foreach ($this->settingEntityRepository->findAll() as $settingEntity) {
         $this->settings->set($settingEntity->getName(), $settingEntity);
     }
 }
Пример #3
0
 /**
  * Registers the given event handler to listen to events of the given name.
  *
  * @param string $eventName Name of the event to listen to
  * @param \Ableron\Lib\Event\EventHandlerInterface $eventHandler The event handler
  * @return void
  */
 public function registerEventHandler(string $eventName, EventHandlerInterface $eventHandler)
 {
     // make sure event name is mapped to a set of event handlers
     if (!$this->eventHandlers->containsKey($eventName)) {
         $this->eventHandlers->set($eventName, new ObjectSet(EventHandlerInterface::class));
     }
     // let the event handler listen to the event
     $this->eventHandlers->get($eventName)->add($eventHandler);
 }
 /**
  * Reads the tag arguments based on $this->argumentDefinition.
  *
  * @throws \Ableron\Core\Exception\SystemException
  * @return void
  */
 private function readArguments()
 {
     // init arguments map
     $this->tagArguments = new OrderedMap();
     // read arguments
     foreach ($this->argumentDefinition as $argument) {
         // determine whether argument value shall be dequoted
         $dequote = isset($argument['dequoteValue']) ? $argument['dequoteValue'] : true;
         // check whether argument is set in the template tag
         if ($this->templateTag->getArguments()->containsKey($argument['name'])) {
             $this->tagArguments->set($argument['name'], $this->templateTag->getArgument($argument['name'], $dequote));
             continue;
         }
         // handle shorthand argument
         if (isset($argument['isShorthandArgument']) && $argument['isShorthandArgument'] && $this->templateTag->getArguments()->containsKey(0)) {
             $this->tagArguments->set($argument['name'], $this->templateTag->getArgument(0, $dequote));
             continue;
         }
         // throw exception in case the argument is mandatory but missing
         if (isset($argument['isMandatory']) && $argument['isMandatory']) {
             throw new SystemException(sprintf('Missing argument "%s" in tag {%s}', $argument['name'], $this->getTag()->getTagName()), 0, E_USER_ERROR, __FILE__, __LINE__);
         }
         // check whether default value is set (use array_key_exists() to make sure default value is recognized even if set to NULL)
         if (!array_key_exists('defaultValue', $argument)) {
             throw new SystemException(sprintf('Missing default value for argument "%s" in tag {%s}', $argument['name'], $this->getTag()->getTagName()), 0, E_USER_ERROR, __FILE__, __LINE__);
         }
         // use default value as argument value
         $this->tagArguments->set($argument['name'], $argument['defaultValue']);
     }
 }
Пример #5
0
 /**
  * @see \Ableron\Core\Form\FormInterface::setAttribute()
  */
 public function setAttribute($attributeName, $attributeValue)
 {
     $this->attributes->set($attributeName, $attributeValue);
 }
Пример #6
0
 /**
  * Returns an instance of the compiler plugin with the given class name.
  *
  * Does not contain error handling for the case, the plugin could not be found because this
  * method only gets called for plugin which already have been found.
  *
  * @param string $pluginClassName Class name of the template plugin
  * @param \Ableron\Core\Template\TemplateTag $templateTag The template tag to get the compiler plugin for
  * @return \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface
  */
 private function getCompilerPlugin($pluginClassName, TemplateTag $templateTag)
 {
     // build cache key
     $pluginKey = $pluginClassName . $templateTag->getFullTag();
     // find and initialize plugin if not already done
     if (!$this->compilerPluginInstances->containsKey($pluginKey)) {
         foreach ($this->pluginDirectories as $pluginDirectory => $namespace) {
             if (is_file(sprintf('%s/%s.php', $pluginDirectory, $pluginClassName))) {
                 $this->compilerPluginInstances->set($pluginKey, ClassUtil::getInstance($namespace . '\\' . $pluginClassName, array($templateTag)));
                 break;
             }
         }
     }
     // return compiler plugin
     return $this->compilerPluginInstances->get($pluginKey);
 }
Пример #7
0
 /**
  * @see \Ableron\Core\Form\FormElementInterface::setLabelOption()
  */
 public function setLabelOption($optionName, $optionValue)
 {
     $this->options->set($optionName, $optionValue);
     return $this;
 }
Пример #8
0
 /**
  * Parses the tag argument string and returns a map of all arguments.
  *
  * In case there is only a single argument value without a key, the key to access this
  * argument will be set to "0".
  *
  * @param string|null $argumentString The argument string to parse
  * @return \Ableron\Lib\Collections\Implementations\OrderedMap
  */
 private function parseArgumentString($argumentString)
 {
     // prepare return value
     $arguments = new OrderedMap();
     // check whether argument string is given
     if ($argumentString !== null) {
         // extract arguments
         preg_match_all('#(?:^|\\s+)(\\w+)=((?:(?!\\s+\\w+=).)+)#s', $argumentString, $argumentMatches);
         // in case $argumentMatches[0] is empty, the argument string itself is the only argument (key is set to "0")
         if (empty($argumentMatches[0])) {
             $arguments->add($argumentString);
         } else {
             for ($argumentIndex = 0, $argumentCount = count($argumentMatches[0]); $argumentIndex < $argumentCount; $argumentIndex++) {
                 // get argument name and value
                 $argumentName = $argumentMatches[1][$argumentIndex];
                 $argumentValue = $this->argumentValueToPhpValue($argumentMatches[2][$argumentIndex]);
                 // add argument to return value
                 $arguments->set($argumentName, $argumentValue);
             }
         }
     }
     // return arguments
     return $arguments;
 }
Пример #9
0
 /**
  * Tests whether set() works as expected.
  *
  * @return void
  */
 public function testSet()
 {
     $map = new OrderedMap();
     $map->set('foo', 'bar');
     $this->assertTrue($map->containsKey('foo'));
     $this->assertTrue($map->containsValue('bar'));
     $this->assertSame('bar', $map->get('foo'));
     $map->set('foo', 'baz');
     $this->assertTrue($map->containsKey('foo'));
     $this->assertTrue($map->containsValue('baz'));
     $this->assertSame('baz', $map->get('foo'));
     $map->set(0, 42);
     $this->assertTrue($map->containsKey(0));
     $this->assertTrue($map->containsValue(42));
     $this->assertSame(42, $map->get(0));
     $map->set(0, 'foo');
     $this->assertSame('foo', $map->get(0));
 }