Exemplo n.º 1
0
 public function __construct()
 {
     $this->extensions = new Map();
     $this->packages = new Map();
     // load up all extensions
     $exts = ExtensionQuery::create()->joinPackage()->find();
     foreach ($exts as $ext) {
         /* @var $ext Extension */
         $key = $ext->getKey();
         $packageName = $ext->getPackage()->getName();
         $data = Json::decode($ext->getData());
         // add to global extensions
         if (!$this->extensions->has($key)) {
             $this->extensions->set($key, new ArrayList());
         }
         $this->extensions->get($key)->add($data);
         // add to package extensions
         if (!$this->packages->has($packageName)) {
             $this->packages->set($packageName, new Map());
         }
         $pkg = $this->packages->get($packageName);
         if (!$pkg->has($key)) {
             $pkg->set($key, new ArrayList());
         }
         $pkg->get($key)->add($data);
     }
 }
Exemplo n.º 2
0
 /**
  * Returns a set of allowed action ids
  *
  * @param User $user
  * @return Set
  */
 private function getPermissionTable(User $user)
 {
     $userId = $user->getId();
     if ($this->permissionTable->has($userId)) {
         return $this->permissionTable->get($userId);
     }
     // always allow what guests can do
     $guestGroup = GroupQuery::create()->findOneByIsGuest(true);
     // collect groups from user
     $groups = GroupQuery::create()->filterByUser($user)->find();
     $userGroup = GroupQuery::create()->filterByOwnerId($userId)->findOne();
     if ($userGroup) {
         $groups[] = $userGroup;
     }
     $groups[] = $guestGroup;
     // ... structure them
     $permissionTable = new Set();
     foreach ($groups as $group) {
         foreach ($group->getActions() as $action) {
             $permissionTable->add($action->getId());
         }
     }
     $this->permissionTable->set($userId, $permissionTable);
     return $this->permissionTable->get($userId);
 }
Exemplo n.º 3
0
 /**
  * @param Skill $skill
  * @return Skill[]
  */
 private function getDescendents(Skill $skill)
 {
     if (!$this->descendents->has($skill->getId())) {
         $this->descendents->set($skill->getId(), $skill->getDescendents());
     }
     return $this->descendents->get($skill->getId());
 }
Exemplo n.º 4
0
 /**
  *
  * @param string $packageName
  * @return CompletePackage
  */
 public function getComposerPackage($packageName)
 {
     if ($this->composerCache->has($packageName)) {
         return $this->composerCache->get($packageName);
     }
     $package = $this->loader->load($this->getJson($this->getFile($packageName)));
     $this->composerCache->set($packageName, $package);
     return $package;
 }
Exemplo n.º 5
0
 /**
  * Adds a constant
  *
  * @param string|PhpConstant $nameOrConstant constant name or instance
  * @param string $value
  * @return $this
  */
 public function setConstant($nameOrConstant, $value = null, $isExpression = false)
 {
     if ($nameOrConstant instanceof PhpConstant) {
         $name = $nameOrConstant->getName();
         $constant = $nameOrConstant;
     } else {
         $name = $nameOrConstant;
         $constant = new PhpConstant($nameOrConstant, $value, $isExpression);
     }
     $this->constants->set($name, $constant);
     return $this;
 }
Exemplo n.º 6
0
 /**
  * @param array $contents
  */
 protected function parse($contents = [])
 {
     $data = new Map($contents);
     $this->title = $data->get('title', '');
     $this->class = $data->get('class', '');
     $this->extensionPoints = $data->get('extension-points', new Map());
     $this->extensions = new Map();
     $extensions = CollectionUtils::toMap($data->get('extensions', []));
     foreach ($extensions as $key => $val) {
         $this->extensions->set($key, $val->map(function ($v) {
             return $v->toArray();
         }));
     }
     return $data;
 }
Exemplo n.º 7
0
 /**
  * 
  */
 public function import($data, Event $event)
 {
     $csv = Reader::createFromString(trim($data));
     $csv->setDelimiter(';');
     // get startgroups at first
     $groups = new Map();
     foreach ($csv->fetchColumn(0) as $name) {
         if (!$groups->has($name)) {
             $startgroup = $this->getStartgroup($name);
             $startgroup->setEvent($event);
             $groups->set($name, $startgroup);
         }
     }
     $id = 0;
     foreach ($csv as $row) {
         $id++;
         $routine = $this->getRoutine($id);
         $group = $groups->get($row[0]);
         $judges = (count($row) - 1) / 3;
         for ($j = 1; $j <= $judges; $j++) {
             $score = new PerformanceScore();
             $score->setRoutine($routine);
             $score->setJudge($group->getPerformanceJudge($j));
             $score->setExecution($row[($j - 1) * 3 + 1]);
             $score->setChoreography($row[($j - 1) * 3 + 2]);
             $score->setMusicAndTiming($row[($j - 1) * 3 + 3]);
             $score->setTotal($row[($j - 1) * 3 + 1] + $row[($j - 1) * 3 + 2] + $row[($j - 1) * 3 + 3]);
             $routine->addPerformanceScore($score);
         }
         $group->addRoutine($routine);
         $group->save();
     }
     $event->save();
 }
Exemplo n.º 8
0
 /**
  * Loads a module and returns the associated class or returns if already loaded
  *
  * @param String $packageName
  * @throws ModuleException
  * @return AbstractModule
  */
 public function load($packageName)
 {
     if ($this->loadedModules->has($packageName)) {
         return $this->loadedModules->get($packageName);
     }
     // check existence
     if (!$this->installedModules->has($packageName)) {
         throw new ModuleException(sprintf('Module (%s) does not exist.', $packageName), 500);
     }
     // check activation
     if (!$this->activatedModules->has($packageName)) {
         throw new ModuleException(sprintf('Module (%s) not activated', $packageName), 501);
     }
     $model = $this->activatedModules->get($packageName);
     if ($model->getInstalledVersion() > $model->getActivatedVersion()) {
         throw new ModuleException(sprintf('Module Version Mismatch (%s). Module needs to be updated by the Administrator', $packageName), 500);
     }
     // load
     $className = $model->getClassName();
     /* @var $module AbstractModule */
     $module = new $className($model, $this->service);
     $this->loadedModules->set($packageName, $module);
     // load locale
     $localeService = $this->getServiceContainer()->getLocaleService();
     $file = sprintf('/%s/locales/{locale}/translations.json', $packageName);
     $localeService->loadLocaleFile($file, $module->getCanonicalName());
     return $module;
 }
Exemplo n.º 9
0
 /**
  * Recursively transforms data into a map (on the first level, deeper levels
  * transformed to an appropriate collection) (experimental API)
  *
  * @param array|Iterator $collection
  * @return Map
  */
 public static function toMap($collection)
 {
     $map = new Map();
     foreach ($collection as $k => $v) {
         $map->set($k, self::toCollection($v));
     }
     return $map;
 }
Exemplo n.º 10
0
 public function testAddGetRemove()
 {
     $key1 = 'key1';
     $key2 = 'key2';
     $key3 = 'key3';
     $item1 = 'item 1';
     $item2 = 'item 2';
     $item3 = 'item 3';
     $items = [$key1 => $item1, $key2 => $item2];
     $keys = new Set([$key1, $key2]);
     $values = new ArrayList([$item1, $item2]);
     $map = new Map();
     $map->set($key1, $item1);
     $this->assertEquals(1, $map->size());
     $this->assertEquals($item1, $map->get($key1));
     $this->assertTrue($map->has($key1));
     $this->assertFalse($map->has($key2));
     $map->remove($key1);
     $this->assertEquals(0, $map->size());
     $map->setAll($items);
     $this->assertEquals(2, $map->size());
     $this->assertEquals($keys, $map->keys());
     $this->assertEquals($values, $map->values());
     $map->set($key3, $item3);
     $this->assertEquals(3, $map->size());
     $map->clear();
     $this->assertEquals(0, $map->size());
     $dupKeyItems = [$key1 => $item1, $key2 => $item2];
     $map->setAll($dupKeyItems);
     $map->set($key2, $item3);
     $this->assertEquals(2, $map->size());
     $this->assertEquals($item3, $map->get($key2));
     $this->assertEmpty($map->get('non_existing_key'));
     $this->assertEmpty($map->remove('non_existing_key'));
     $this->assertEquals([], $map->get('non_existing_key', []));
 }
Exemplo n.º 11
0
 private function registerListeners()
 {
     $reg = $this->service->getExtensionRegistry();
     $listeners = $reg->getExtensions(CoreModule::EXT_LISTENER);
     $map = new Map();
     $getClass = function ($className) use($map) {
         if (class_exists($className)) {
             if ($map->has($className)) {
                 $class = $map->get($className);
             } else {
                 $class = new $className();
                 $map->set($className, $class);
             }
             if ($class instanceof KeekoEventListenerInterface) {
                 $class->setServiceContainer($this->service);
             }
             return $class;
         }
         return null;
     };
     foreach ($listeners as $listener) {
         // subscriber first
         if (isset($listener['subscriber'])) {
             $className = $listener['subscriber'];
             $subscriber = $getClass($className);
             if ($subscriber !== null && $subscriber instanceof KeekoEventSubscriberInterface) {
                 $this->dispatcher->addSubscriber($subscriber);
             }
         }
         // class
         if (isset($listener['class']) && isset($listener['method']) && isset($listener['event'])) {
             $className = $listener['class'];
             $class = $getClass($className);
             if ($class !== null && $class instanceof KeekoEventListenerInterface && method_exists($class, $listener['method'])) {
                 $this->dispatcher->addListener($listener['event'], [$class, $listener['method']]);
             }
         }
     }
 }
Exemplo n.º 12
0
 public function setResponder($type, $class)
 {
     $this->responder->set($type, $class);
 }
Exemplo n.º 13
0
 /**
  * Adds a method
  *
  * @param PhpMethod $method
  * @return $this
  */
 public function setMethod(PhpMethod $method)
 {
     $method->setParent($this);
     $this->methods->set($method->getName(), $method);
     return $this;
 }
Exemplo n.º 14
0
 /**
  * Sets the scheme
  *
  * @param string $id
  * @param Set $scopes
  * @return $this
  */
 public function add($id, Set $scopes)
 {
     $this->securities->set($id, $scopes);
     return $this;
 }
Exemplo n.º 15
0
 /**
  * Adds a property
  *
  * @param PhpProperty $property
  * @return $this
  */
 public function setProperty(PhpProperty $property)
 {
     $property->setParent($this);
     $this->properties->set($property->getName(), $property);
     return $this;
 }
Exemplo n.º 16
0
 private function prepareMap(Map $map)
 {
     foreach (array_keys($this->targets) as $target) {
         $map->set($target, new ArrayList());
     }
 }
Exemplo n.º 17
0
 /**
  * Sets the response
  *
  * @param Response $code
  */
 public function add(Response $response)
 {
     $this->responses->set($response->getCode(), $response);
 }
Exemplo n.º 18
0
 public function testTextAsKey()
 {
     $map = new Map();
     $key = new Text('k');
     $map->set($key, 'val');
     $this->assertTrue($map->has($key));
     $this->assertEquals('val', $map->get($key));
     $map->remove($key);
     $this->assertEquals(0, $map->size());
 }
Exemplo n.º 19
0
 /**
  * Sets the path
  *
  * @param Path $path
  * @return $this
  */
 public function add(Path $path)
 {
     $this->paths->set($path->getPath(), $path);
     return $this;
 }
Exemplo n.º 20
0
 /**
  * Sets the scheme
  *
  * @param SecurityScheme $scheme
  * @return $this
  */
 public function add(SecurityScheme $scheme)
 {
     $this->schemes->set($scheme->getId(), $scheme);
     return $this;
 }
Exemplo n.º 21
0
 /**
  * A list of tags sorted by tag-name
  * 
  * @return ArrayList
  */
 public function getSortedTags()
 {
     if ($this->comparator === null) {
         $this->comparator = new TagNameComparator();
     }
     // 1) group by tag name
     $group = new Map();
     foreach ($this->tags as $tag) {
         if (!$group->has($tag->getTagName())) {
             $group->set($tag->getTagName(), new ArrayList());
         }
         $group->get($tag->getTagName())->add($tag);
     }
     // 2) Sort the group by tag name
     $group->sortKeys(new TagNameComparator());
     // 3) flatten the group
     $sorted = new ArrayList();
     foreach ($group->values() as $tags) {
         $sorted->addAll($tags);
     }
     return $sorted;
 }
Exemplo n.º 22
0
 /**
  * Sets the header
  *
  * @param Header $header
  */
 public function add(Header $header)
 {
     $this->headers->set($header->getHeader(), $header);
 }
Exemplo n.º 23
0
 /**
  * @return Skill[]
  */
 public function getDescendents()
 {
     $descendents = new Map();
     $add = function (Skill $skill) use($descendents) {
         if ($skill->isMultiple() || $skill->isTransition()) {
             return;
         }
         $descendents->set($skill->getId(), $skill);
         $descendents->setAll($skill->getDescendents());
     };
     foreach ($this->getVariations() as $variation) {
         $add($variation);
     }
     foreach ($this->getChildren() as $child) {
         $add($child);
     }
     return $descendents->toArray();
 }
Exemplo n.º 24
0
 /**
  * Sets the field
  *
  * @param string name
  * @param Schema $schame
  */
 public function set($name, Schema $schema)
 {
     $this->definitions->set($name, $schema);
 }