private function parseTags(Map $data) { $this->tags = new ArrayList(); foreach ($data->get('tags', []) as $t) { $this->tags->add(new Tag($t)); } }
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; }
/** * 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); }
/** * */ 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(); }
/** * @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()); }
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'); }
/** * 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; }
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()); }
/** * * @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; }
/** * 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 []; }
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')); } }
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); }
/** * 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(); }
/** * 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; }
/** * Clears all properties * * @return $this */ public function clearProperties() { foreach ($this->properties as $property) { $property->setParent(null); } $this->properties->clear(); return $this; }
/** * Clears all methods * * @return $this */ public function clearMethods() { foreach ($this->methods as $method) { $method->setParent(null); } $this->methods->clear(); return $this; }
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']]); } } } }
private function parseConsumes(Map $data) { $this->consumes = $data->get('consumes', new Set()); }
private function prepareMap(Map $map) { foreach (array_keys($this->targets) as $target) { $map->set($target, new ArrayList()); } }
private function parseExternalDocs(Map $data) { $this->externalDocs = new ExternalDocs($data->get('externalDocs', new Map())); }
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); }
private function parseItems(Map $data) { if ($data->has('items')) { $this->items = new Items($data->get('items')); } }
private function parseDescription(Map $data) { $this->description = $data->get('description'); }
public function valid() { return $this->headers->valid(); }
public function valid() { return $this->securities->valid(); }
/** * 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; }
public function getResponder($type) { return $this->responder->get($type); }
/** * Returns the path of the schema for the given key * * @param string $key * @return string */ public function getExtensionPoint($key) { return $this->extensionPoints->get($key); }
private function parseSchema(Map $data) { $this->schema = new Schema($data->get('schema')); }
private function parseRequired(Map $data) { $this->required = $data->has('required') && $data->get('required'); }