/**
  * @see \Ableron\Lib\Storage\AbstractStorage::performDeleteAll()
  */
 protected function performDeleteAll()
 {
     // clear storage
     $this->arrayStorage->clear();
     // indicate that storage items have been deleted successfully
     return true;
 }
 public function testToArray()
 {
     $obj = new stdClass();
     $collection = new OrderedMap(array('test', 12, $obj));
     $array = $collection->toArray();
     $this->assertTrue(is_array($array));
     $this->assertSame(3, count($array));
     $this->assertSame($obj, $array[2]);
 }
 /**
  * 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);
     }
 }
 /**
  * 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']);
     }
 }
 /**
  * Fires an event which then will be dispatched to all event handlers
  * registered for the event.
  *
  * First executes all event handlers listening implicitly on the fired event
  * (i.e. event handlers registered to listen on event "*").
  * Then executes all event handlers listening explicitly on the fired event.
  *
  * In case an event handler is registered to listen on event "*" and
  * additionally registered to listen explicitly on an event, the event
  * handler will be executed multiple times.
  *
  * @param \Ableron\Lib\Event\EventInterface $event The event to fire
  * @return void
  */
 public function fireEvent(EventInterface $event)
 {
     foreach (array('*', $event->getName()) as $eventName) {
         if ($this->eventHandlers->containsKey($eventName)) {
             /** @var \Ableron\Lib\Event\EventHandlerInterface $eventHandler */
             foreach ($this->eventHandlers->get($eventName) as $eventHandler) {
                 $eventHandler->handle($event);
             }
         }
     }
 }
 /**
  * @see \Ableron\Core\Form\FormInterface::getOpenTag()
  */
 public function getOpenTag()
 {
     // get form attributes
     $formAttributes = $this->attributes->toArray();
     // if name is set but and id is not, treat element name as id
     if (!$this->attributes->containsKey('id') && $this->attributes->containsKey(self::ATTR_NAME)) {
         $formAttributes['id'] = $this->attributes->get([self::ATTR_NAME]);
     }
     // declare attribute strings
     $attributeStrings = array();
     // build attribute string
     foreach ($formAttributes as $formAttributeName => $formAttributeValue) {
         // make key lower case
         $formAttributeName = StringUtil::toLowerCase($formAttributeName);
         // skip boolean attributes which values are "false" (false = default)
         if ($formAttributeValue === false) {
             continue;
         }
         // compose attribute
         $attributeStrings[] = sprintf('%s="%s"', StringUtil::encodeHtml($formAttributeName), StringUtil::encodeHtml($formAttributeValue));
     }
     // build final HTML tag
     return sprintf('<form %s>', implode(' ', $attributeStrings));
 }
 /**
  * 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);
 }
 /**
  * @see \Ableron\Core\Form\FormElementInterface::setLabelOption()
  */
 public function setLabelOption($optionName, $optionValue)
 {
     $this->options->set($optionName, $optionValue);
     return $this;
 }
Exemple #9
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;
 }
 /**
  * Tests whether removeByValue() removed all elements with the given value.
  *
  * @return void
  */
 public function testRemoveByValueRemovesAllMatchingElements()
 {
     $map = new OrderedMap(array('foo' => 'bar', 'bar' => 'bar', 'baz' => 'bar', 'foobar' => 'foobarbaz'));
     $this->assertSame(array('foo' => 'bar', 'bar' => 'bar', 'baz' => 'bar', 'foobar' => 'foobarbaz'), $map->toArray());
     $map->removeByValue('bar');
     $this->assertSame(array('foobar' => 'foobarbaz'), $map->toArray());
 }