/** * Get related entity attribute * * @return Attribute * @throws UnknownAttributeException */ public function getEntityAttribute() { if (!$this->attributes->containsKey($this->entityAttributeName)) { throw new UnknownAttributeException('There is no entity attribute'); } return $this->attributes->get($this->entityAttributeName); }
function let(LoaderInterface $loader, Collection $resourcesToThemes, ThemeInterface $theme) { $theme->getLogicalName()->willReturn("sylius/sample-theme"); $resourcesToThemes->get(realpath($this->getThemeTranslationResourcePath()))->willReturn($theme); $resourcesToThemes->get(realpath($this->getVanillaTranslationResourcePath()))->willReturn(null); $this->beConstructedWith($loader, $resourcesToThemes); }
private function getCalculator(ShippingMethodInterface $shippingMethod) : ShippingCalculatorInterface { $calculator = $shippingMethod->getCalculator(); if (false === $this->calculators->containsKey($calculator)) { throw new CalculatorNotFoundException($calculator); } return $this->calculators->get($calculator); }
/** * @param Product $product * @param Quantity $quantity * @return Cart */ public function addProduct(Product $product, Quantity $quantity) : Cart { $key = $product->getId()->getValue(); /** @var LineItem $lineItem */ $lineItem = $this->lineItems->get($key); if ($lineItem === null) { $lineItem = new LineItem($product, $quantity); } else { $lineItem = new LineItem($product, $lineItem->getQuantity()->add($quantity)); } $this->lineItems->set($key, $lineItem); return $this; }
/** * {@inheritdoc} */ public function load($resource, $locale, $domain = 'messages') { $messageCatalogue = $this->loader->load($resource, $locale, $domain); if (null !== ($theme = $this->resourcesToThemes->get(realpath($resource)))) { $messages = $messageCatalogue->all($domain); foreach ($messages as $key => $value) { unset($messages[$key]); $messages[$key . '|' . $theme->getLogicalName()] = $value; } $messageCatalogue->replace($messages, $domain); } return $messageCatalogue; }
/** * @param bool $allowCreate * * @return TranslationInterface */ public function getTranslation($allowCreate = false) { $locales = $this->getLocales(); if (empty($locales)) { throw new LocaleNotFoundException(); } $translation = null; foreach ($locales as $locale) { if (($translation = $this->translations->get($locale)) !== null) { break; } } if ($translation === null && $allowCreate) { $translation = $this->getTranslationFactory()->create(['locale' => reset($locales)]); $this->addTranslation($translation); } if ($translation === null && $this->hasFallbackLocale()) { $translation = $this->translations->get($this->getFallbackLocale()); } if ($translation === null) { if ($this->hasFallbackLocale()) { $locales[] = $this->getFallbackLocale(); } throw new TranslationNotFoundException(); } return $translation; }
public function getType(string $type) : TypeInterface { if (false === $this->types->containsKey($type)) { throw new TypeNotFoundException($type, $this->types->getKeys()); } return $this->types->get($type); }
/** * @param int $index * @return \Kdyby\Doctrine\Forms\EntityContainer */ private function createNewContainer($index) { if (!$this->collection->containsKey($index)) { $this->collection->set($index, $this->createNewEntity()); } $class = $this->containerClass; return new $class($this->collection->get($index)); }
/** * Check if the given permission is allowed. * Only explicitly allowed permissions will return true. * * @param string $permissionName * @return bool */ protected function allows($permissionName) { foreach ($this->getMatchingPermissions($permissionName) as $key) { /** @var Permission $permission */ $permission = $this->permissions->get($key); if ($permission->isAllowed()) { return true; } } return false; }
/** * @param Package $package * @param array $packageInfo */ private function resolveDependencies(Package $package, array $packageInfo) { if (!isset($packageInfo[self::DEPENDENCIES_KEY])) { return; } foreach ($packageInfo[self::DEPENDENCIES_KEY] as $dependencyName => $dependencyInfo) { $dependencyPackage = $this->packages->get($dependencyName); if (null !== $dependencyPackage) { $package->addDependency($dependencyPackage); } } }
/** * Creates formulae for the given package. * * @param \Sp\BowerBundle\Bower\Package\Package $package * @param string $packageName * @param string $extension * * @return array<string,array<array>> */ protected function createPackageFormulae(Package $package, $packageName, $extension) { /** @var PackageResource $packageResource */ $packageResource = $this->packageResources->get($packageName); $nestDependencies = $this->shouldNestDependencies(); if (null !== $packageResource && null !== $packageResource->shouldNestDependencies()) { $nestDependencies = $packageResource->shouldNestDependencies(); } if (null !== ($assets = $this->createSingleFormula($package, $nestDependencies, $extension))) { return array($assets, $this->resolveFilters($extension, $packageResource), array()); } return array(); }
/** * Get step by name * * @param string $stepName * @return Step */ public function getStep($stepName) { return $this->steps->get($stepName); }
/** * @param string $coordinate * * @return Cell|null */ public function getCellByCoordinate(string $coordinate) { return $this->cells->get($coordinate); }
public function getCelestialBody($number) { return $this->celestialBodies->get($number); }
/** * {@inheritdoc} */ public function getSetting($key) { return $this->settings->get($key); }
public function getModifier(string $name) : OrderModifierInterface { return $this->modifiers->get($name); }
/** * @param string $attributeName * @return Attribute */ public function getAttribute($attributeName) { return $this->attributes->get($attributeName); }
private function getDefaultOrderModifier(string $name) : OrderModifierInterface { return $this->defaultModifiers->get($name); }
public function getSystem($number) { return $this->systems->get($number); }
/** * {@inheritdoc} */ public function get($key) { $this->initialize(); return $this->coll->get($key); }
/** * {@inheritdoc} */ public function get($key) { if (!$this->initialized && $this->association['type'] === Mapping\ClassMetadataInfo::ONE_TO_MANY && $this->association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY && isset($this->association['indexBy'])) { if (!$this->typeClass->isIdentifierComposite && $this->typeClass->isIdentifier($this->association['indexBy'])) { return $this->em->find($this->typeClass->name, $key); } return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->get($this, $key); } $this->initialize(); return $this->coll->get($key); }
/** * @param string $transitionName * @return Transition|null */ public function getTransition($transitionName) { return $this->transitions->get($transitionName); }
function it_returns_null_when_getting_for_a_key_with_type_other_than_specified(Collection $internal) { $internal->get(Argument::any())->shouldNotBeCalled(); $internal->offsetGet(Argument::any())->shouldNotBeCalled(); $this->get('4')->shouldBe(null); $this->offsetGet('4')->shouldBe(null); }
public function getGalaxy($number) { return $this->galaxies->get($number); }
/** * {@inheritdoc} */ public function getChild($name) { return $this->children->get($name); }
/** * {@inheritdoc} */ public function get($key) { return $this->inner->get($key); }
public function testGet() { $this->collection[0] = 'Test'; $this->assertEquals('Test', $this->collection->get(0)); }
/** * @param string $taskName * @param array $options * * @throws \RuntimeException */ public function executeTask($taskName, $options = []) { $startTime = new \DateTime(); $this->logInfo(sprintf("%s.%s started", $this->alias, $taskName)); if ($this->locker->hasLock($this, $taskName)) { $this->logInfo(sprintf("%s.%s has lock, exiting", $this->alias, $taskName)); return; } $this->locker->lock($this, $taskName); if (!($task = $this->tasks->get($taskName))) { $this->logError(sprintf("%s.%s %s not configured", $this->alias, $taskName, 'RuntimeException', 'TaskInterface')); $this->finish($startTime, $taskName); return; } if (!($dataContext = $task->getDataContext())) { $this->logError(sprintf("%s.%s %s not configured", $this->alias, $taskName, 'RuntimeException', 'DataContextInterface')); $this->finish($startTime, $taskName); return; } $dataContext->setStartedAt($startTime); if (!($extractor = $task->getExtractor())) { $this->logError(sprintf("%s.%s %s not configured", $this->alias, $taskName, 'RuntimeException', 'ExtractorInterface')); $this->finish($startTime, $taskName); return; } if (!($taskListener = $task->getListener())) { $this->logError(sprintf("%s.%s %s not configured", $this->alias, $taskName, 'RuntimeException', 'TaskListenerInterface')); $this->finish($startTime, $taskName); return; } if (!($loader = $task->getLoader())) { $this->logError(sprintf("%s.%s %s not configured", $this->alias, $taskName, 'RuntimeException', 'LoaderInterface')); $this->finish($startTime, $taskName); return; } // Run Extract try { $iterator = $extractor->getIterator(); $this->logInfo(sprintf("%s.%s Extracted Batch Iterator", $this->alias, $taskName)); } catch (ExtractException $e) { $this->logError(sprintf("%s.%s %s %s", $this->alias, $taskName, 'LoadException', $e->getMessage())); $this->finish($startTime, $taskName); return; } // Run Transformations $transformations = $task->getTransformations(); $task->setDataContext($dataContext); $taskEventName = sprintf("%s.%s.task.complete", $this->alias, $taskName); $this->eventDispatcher->addListener($taskEventName, array($taskListener, 'onComplete')); foreach ($iterator as $iteration => $extractedRecord) { $dataContext->setCurrentIteration($iteration); $dataContext->setCurrentExtractedRecord($extractedRecord); $dataContext->setCurrentTransformedRecord([]); foreach ($transformations as $transformationKey => $transformation) { $transformationEventName = sprintf("%s.%s.transformation.%s.complete", $this->alias, $taskName, $transformationKey); if (!$this->eventDispatcher->hasListeners($transformationEventName) && ($transformationListener = $transformation->getListener())) { $this->eventDispatcher->addListener($transformationEventName, array($transformationListener, 'onComplete')); } try { $transformation->shouldContinue(); $field = $transformation->getField(); $value = $extractedRecord[$field]; $transformers = $transformation->getTransformers(); foreach ($transformers as $transformer) { try { $value = $transformer->transform($value, $transformation); $transformer->bind($value, $transformation); } catch (TransformException $e) { $this->logError(sprintf("%s.%s %s %s", $this->alias, $taskName, 'TransformException', $e->getMessage())); } } try { $transformation->postTransform(); } catch (TransformException $e) { $this->logError(sprintf("%s.%s %s %s", $this->alias, $taskName, 'TransformException', $e->getMessage())); } } catch (TransformationContinueException $e) { continue; } $transformationEvent = $this->createTransformationEvent($transformation); try { $this->eventDispatcher->dispatch($transformationEventName, $transformationEvent); } catch (LoadException $e) { $this->logError(sprintf("%s.%s %s %s", $this->alias, $taskName, 'LoadException', $e->getMessage())); } } if (true === $iterator->isBatchComplete()) { $this->logInfo(sprintf("%s.%s %s Transformed extract records to load via %s", $this->alias, $taskName, $dataContext->getTransformedCount(), get_class($loader))); $taskEvent = $this->createTaskEvent($task); try { $this->eventDispatcher->dispatch($taskEventName, $taskEvent); $this->logInfo(sprintf("%s.%s %s Loaded records affected", $this->alias, $taskName, $dataContext->getLoadedCount())); } catch (LoadException $e) { $this->logError(sprintf("%s.%s %s %s", $this->alias, $taskName, 'LoadException', $e->getMessage())); } $dataContext = $this->cloneDataContext($dataContext); $task->setDataContext($dataContext); } } $this->logInfo(sprintf("%s.%s %s Transformed extract records to load via %s", $this->alias, $taskName, $dataContext->getTransformedCount(), get_class($loader))); $taskEvent = $this->createTaskEvent($task); try { $this->eventDispatcher->dispatch($taskEventName, $taskEvent); $this->logInfo(sprintf("%s.%s %s Loaded records affected", $this->alias, $taskName, $dataContext->getLoadedCount())); } catch (LoadException $e) { $this->logError(sprintf("%s.%s %s %s", $this->alias, $taskName, 'LoadException', $e->getMessage())); } $this->finish($startTime, $taskName); }
public function testGet() { $this->_coll[0] = 'test'; $this->assertEquals('test', $this->_coll->get(0)); }
/** * @param string $category * @return Collection|AttributeOptionDiscoverer[] */ public function getMapperCategory($category) { return $this->optionMappers->get($category); }