예제 #1
0
 /**
  * StubRepository constructor.
  */
 public function __construct()
 {
     $datas = [['modname' => 'FooExtension', 'name' => 'bar', 'value' => 'test'], ['modname' => 'BarExtension', 'name' => 'bar', 'value' => 7], ['modname' => 'BarExtension', 'name' => 'name', 'value' => 'steve'], ['modname' => 'BarExtension', 'name' => 'string', 'value' => 'xyz']];
     foreach ($datas as $data) {
         $entity = new ExtensionVarEntity();
         $entity->merge($data);
         $this->entities[] = $entity;
     }
 }
예제 #2
0
 /**
  * Set an extension variable.
  * @api Core-2.0
  *
  * @param string $extensionName The name of the extension.
  * @param string $variableName The name of the variable.
  * @param string $value The value of the variable.
  *
  * @return boolean True if successful, false otherwise.
  */
 public function set($extensionName, $variableName, $value = '')
 {
     if (empty($extensionName) || !is_string($extensionName) || empty($variableName) || !is_string($variableName)) {
         throw new \InvalidArgumentException();
     }
     if (!$this->isInitialized) {
         $this->initialize();
     }
     $entities = $this->repository->findBy(['modname' => $extensionName, 'name' => $variableName]);
     if (count($entities) > 1 || count($entities) == 0) {
         foreach ($entities as $entity) {
             // possible duplicates exist. remove all (refs #2385)
             $this->repository->remove($entity);
         }
         $entity = new ExtensionVarEntity();
         $entity->setModname($extensionName);
         $entity->setName($variableName);
     } else {
         $entity = $entities[0];
     }
     $entity->setValue($value);
     $this->repository->persistAndFlush($entity);
     $this->variables[$extensionName][$variableName] = $value;
     return true;
 }