Exemplo n.º 1
0
 private function parseTags(Map $data)
 {
     $this->tags = new ArrayList();
     foreach ($data->get('tags', []) as $t) {
         $this->tags->add(new Tag($t));
     }
 }
Exemplo n.º 2
0
 public function toArray()
 {
     $authors = [];
     foreach ($this->authors as $author) {
         $authors[] = $author->toArray();
     }
     $keys = ['name', 'description', 'type', 'license', 'keywords', 'authors', 'autoload', 'require', 'require-dev', 'extra'];
     $arr = array_merge(array_flip($keys), $this->data->toArray());
     $arr['name'] = $this->fullName;
     $arr['description'] = $this->description;
     $arr['type'] = $this->type;
     $arr['license'] = $this->license;
     $arr['keywords'] = $this->keywords->toArray();
     $arr['authors'] = $authors;
     $arr['autoload'] = $this->autoload->toArray();
     $arr['require'] = $this->require->toArray();
     $arr['require-dev'] = $this->requireDev->toArray();
     $arr['extra'] = array_map(function ($v) {
         if (is_object($v) && method_exists($v, 'toArray')) {
             return $v->toArray();
         }
         return $v;
     }, $this->extra->toArray());
     $keeko = $this->keeko->toArray();
     if (count($keeko) > 0) {
         $arr['extra']['keeko'] = $keeko;
     }
     if (count($arr['keywords']) == 0) {
         unset($arr['keywords']);
     }
     if (count($arr['extra']) == 0) {
         unset($arr['extra']);
     }
     return $arr;
 }
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
0
 private function parse($contents)
 {
     $data = new Map($contents);
     $this->name = $data->get('name');
     $this->email = $data->get('email');
     $this->homepage = $data->get('homepage');
     $this->role = $data->get('role');
 }
Exemplo n.º 7
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.º 8
0
 private function parse($contents)
 {
     $data = new Map($contents);
     $this->psr0 = new PsrSchema($data->get('psr-0', []));
     $this->psr4 = new PsrSchema($data->get('psr-4', []));
     $this->classmap = $data->get('classmap', new Map());
     $this->files = $data->get('files', new Map());
 }
Exemplo n.º 9
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.º 10
0
 /**
  * Returns the extension for the given key by a given packageName
  *
  * @param string $key
  * @param string $packageName
  * @return ArrayList
  */
 public function getExtensionsByPackage($key, $packageName)
 {
     if ($this->packages->has($packageName)) {
         $pkg = $this->packages->get($packageName);
         if ($pkg->has($key)) {
             return $pkg->get($key);
         }
     }
     return [];
 }
Exemplo n.º 11
0
 protected function parse($contents)
 {
     $data = new Map($contents);
     if ($data->has('app')) {
         $this->app = new AppSchema($this->package, $data->get('app'));
     }
     if ($data->has('module')) {
         $this->module = new ModuleSchema($this->package, $data->get('module'));
     }
 }
Exemplo n.º 12
0
 public function testToMap()
 {
     $data = [['a' => 'b'], ['c' => 'd'], [1, 2, 3]];
     $map = CollectionUtils::toMap($data);
     $this->assertTrue($map instanceof Map);
     $this->assertTrue($map->get(0) instanceof Map);
     $this->assertTrue($map->get(2) instanceof ArrayList);
     $map = new Map($data);
     $this->assertFalse($map->get(0) instanceof Map);
     $this->assertFalse($map->get(2) instanceof ArrayList);
 }
Exemplo n.º 13
0
 /**
  * Returns additional includes for a given model
  *
  * @param string $modelName
  * @return ArrayList
  */
 public function getIncludes($modelName)
 {
     if ($this->models->has($modelName) && $this->models->get($modelName)->has('includes')) {
         return $this->models->get($modelName)->get('includes');
     }
     return new ArrayList();
 }
Exemplo n.º 14
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.º 15
0
 /**
  * Clears all properties
  *
  * @return $this
  */
 public function clearProperties()
 {
     foreach ($this->properties as $property) {
         $property->setParent(null);
     }
     $this->properties->clear();
     return $this;
 }
Exemplo n.º 16
0
 /**
  * Clears all methods
  *
  * @return $this
  */
 public function clearMethods()
 {
     foreach ($this->methods as $method) {
         $method->setParent(null);
     }
     $this->methods->clear();
     return $this;
 }
Exemplo n.º 17
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.º 18
0
 private function parseConsumes(Map $data)
 {
     $this->consumes = $data->get('consumes', new Set());
 }
Exemplo n.º 19
0
 private function prepareMap(Map $map)
 {
     foreach (array_keys($this->targets) as $target) {
         $map->set($target, new ArrayList());
     }
 }
Exemplo n.º 20
0
 private function parseExternalDocs(Map $data)
 {
     $this->externalDocs = new ExternalDocs($data->get('externalDocs', new Map()));
 }
Exemplo n.º 21
0
 public function testEach()
 {
     $result = [];
     $map = new Map(['b' => 'bval', 'a' => 'aval', 'c' => 'cval']);
     $map->each(function ($key, $value) use(&$result) {
         $result[$key] = $value;
     });
     $this->assertEquals($map->toArray(), $result);
 }
Exemplo n.º 22
0
 private function parseItems(Map $data)
 {
     if ($data->has('items')) {
         $this->items = new Items($data->get('items'));
     }
 }
Exemplo n.º 23
0
 private function parseDescription(Map $data)
 {
     $this->description = $data->get('description');
 }
Exemplo n.º 24
0
 public function valid()
 {
     return $this->headers->valid();
 }
Exemplo n.º 25
0
 public function valid()
 {
     return $this->securities->valid();
 }
Exemplo n.º 26
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.º 27
0
 public function getResponder($type)
 {
     return $this->responder->get($type);
 }
Exemplo n.º 28
0
 /**
  * Returns the path of the schema for the given key
  *
  * @param string $key
  * @return string
  */
 public function getExtensionPoint($key)
 {
     return $this->extensionPoints->get($key);
 }
Exemplo n.º 29
0
 private function parseSchema(Map $data)
 {
     $this->schema = new Schema($data->get('schema'));
 }
Exemplo n.º 30
0
 private function parseRequired(Map $data)
 {
     $this->required = $data->has('required') && $data->get('required');
 }