/** * {@inheritdoc} */ public function getNotificationEmails() { $emails = []; $this->businessUnits->forAll(function (BusinessUnit $bu) use(&$emails) { $emails = array_merge($emails, $bu->getNotificationEmails()); }); return new ArrayCollection($emails); }
public function clearCollections() { $this->hookedObjectCollections->forAll(function ($key, HookedObjectCollectionEntity $hookedObjectCollectionEntity) { $hookedObjectCollectionEntity->getCollection()->getHookedObjectCollections()->removeElement($hookedObjectCollectionEntity); $hookedObjectCollectionEntity->setCollection(null)->setHookedObject(null); }); $this->hookedObjectCollections->clear(); }
/** * @param Itinerary $other * @return bool */ public function sameValueAs(Itinerary $other) : bool { //We use doctrine's ArrayCollection only to ease comparison //If Legs would be stored in an ArrayCollection hole the time //Itinerary itself would not be immutable, //cause a client could call $itinerary->legs()->add($anotherLeg); //Keeping ValueObjects immutable is a rule of thumb $myLegs = new ArrayCollection($this->legs()); $otherLegs = new ArrayCollection($other->legs()); if ($myLegs->count() !== $otherLegs->count()) { return false; } return $myLegs->forAll(function ($index, Leg $leg) use($otherLegs) { return $otherLegs->exists(function ($otherIndex, Leg $otherLeg) use($leg) { return $otherLeg->sameValueAs($leg); }); }); }
/** * @param mixed $valueOrObject * @param string $target * @return array */ protected function toMany($valueOrObject, $target, Collection $collection = null, $depth = 2) { if (!is_array($valueOrObject) && !$valueOrObject instanceof Traversable) { $valueOrObject = (array) $valueOrObject; } if (!$collection instanceof Collection) { $collection = new ArrayCollection(); } $keepers = array(); foreach ($valueOrObject as $value) { if (method_exists($value, 'toArray')) { $value = $value->toArray($depth); } else { if (!is_array($value) && !$value instanceof Traversable) { $value = (array) $value; } } if (isset($value['id']) && strlen($value['id']) && ($found = $this->find($target, $value['id']))) { $keepers[] = $found->id; $this->hydrate($value, $found); } else { $obj = new $target(); $obj->fromArray($value); $obj->id = null; if ($collection instanceof PersistentCollection) { if ($owner = $collection->getOwner()) { $mapping = $collection->getMapping(); $mappedBy = $mapping['mappedBy']; $obj->{$mappedBy} = $owner; } } $collection->add($obj); } } $collection->forAll(function ($key, $element) use($collection, $keepers) { if (strlen($element->id) && !in_array($element->id, $keepers)) { $collection->remove($key); } }); return $collection; }
/** * Constructor * * @param string $text * @param WordFactory $wordFactory */ public function __construct($text, WordFactory $wordFactory) { $this->text = $text; $this->words = new ArrayCollection(explode(' ', $text)); $this->words->forAll(function ($index, $word) use($wordFactory) { $this->words->set($index, $wordFactory->make($word)); return true; }); }
public function forAll(Closure $p) { if (null === $this->entries) { $this->__load___(); } return $this->entries->forAll($p); }
public function testReferenceMany() { $colPush = new ArrayCollection(array(new GH453ReferencedDocument(), new GH453ReferencedDocument(), new GH453ReferencedDocument())); $colSet = $colPush->map(function ($v) { return clone $v; }); $colSetArray = $colPush->map(function ($v) { return clone $v; }); $colAddToSet = $colPush->map(function ($v) { return clone $v; }); $dm = $this->dm; $colPush->forAll(function ($k, $v) use($dm) { $dm->persist($v); return true; }); $colSet->forAll(function ($k, $v) use($dm) { $dm->persist($v); return true; }); $colSetArray->forAll(function ($k, $v) use($dm) { $dm->persist($v); return true; }); $colAddToSet->forAll(function ($k, $v) use($dm) { $dm->persist($v); return true; }); $doc = new GH453Document(); $doc->referenceManyPush = $colPush; $doc->referenceManySet = $colSet; $doc->referenceManySetArray = $colSetArray; $doc->referenceManyAddToSet = $colAddToSet; $this->dm->persist($doc); $this->dm->flush(); $this->dm->clear(); // No need to assert the value of the referenced document structure $this->assertBsonArray($doc->id, 'referenceManyPush'); $this->assertBsonArray($doc->id, 'referenceManySet'); $this->assertBsonArray($doc->id, 'referenceManySetArray'); $this->assertBsonArray($doc->id, 'referenceManyAddToSet'); // Check that the value is changed properly unset($colPush[1], $colSet[1], $colSetArray[1], $colAddToSet[1]); $doc->referenceManyPush = $colPush; $doc->referenceManySet = $colSet; $doc->referenceManySetArray = $colSetArray; $doc->referenceManyAddToSet = $colAddToSet; /* Merging must be done after re-assigning the collections, as the * referenced documents must be re-persisted through the merge cascade. */ $doc = $this->dm->merge($doc); $this->dm->flush(); $this->dm->clear(); $this->assertBsonArray($doc->id, 'referenceManyPush'); $this->assertBsonObject($doc->id, 'referenceManySet'); $this->assertBsonArray($doc->id, 'referenceManySetArray'); $this->assertBsonArray($doc->id, 'referenceManyAddToSet'); }
/** {@inheritDoc} */ public function forAll(Closure $p) { $this->initialize(); return $this->collection->forAll($p); }
/** * Tests whether the given predicate p holds for all elements of this collection. * * @param Closure $p The predicate. * * @return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise. */ public function forAll(Closure $p) { return $this->collection->forAll($p); }
/** * Create a new order * * @param Application $app * @param Request $request * * @return RedirectResponse|JsonResponse */ public function createOrder(Application $app, Request $request) { $success = false; $collectionHasOrderAdmins = new ArrayCollection(); $toRemove = []; $records = RecordsRequest::fromRequest($app, $request, true, ['cancmd']); $hasOneAdmin = []; if (!$records->isEmpty()) { $order = new OrderEntity(); $order->setUser($app['authentication']->getUser()); $order->setDeadline(null !== ($deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine); $order->setOrderUsage($request->request->get('use', '')); foreach ($records as $key => $record) { if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) { if (!$collectionHasOrderAdmins->get($record->get_base_id())) { $records->remove($key); } } if (!isset($hasOneAdmin[$record->get_base_id()])) { $query = new \User_Query($app); $hasOneAdmin[$record->get_base_id()] = (bool) count($query->on_base_ids([$record->get_base_id()])->who_have_right(['order_master'])->execute()->get_results()); } $collectionHasOrderAdmins->set($record->get_base_id(), $hasOneAdmin[$record->get_base_id()]); if (!$hasOneAdmin[$record->get_base_id()]) { $toRemove[] = $key; } else { $orderElement = new OrderElement(); $order->addElement($orderElement); $orderElement->setOrder($order); $orderElement->setBaseId($record->get_base_id()); $orderElement->setRecordId($record->get_record_id()); $app['EM']->persist($orderElement); } } foreach ($toRemove as $key) { if ($records->containsKey($key)) { $records->remove($key); } } $noAdmins = $collectionHasOrderAdmins->forAll(function ($key, $hasAdmin) { return false === $hasAdmin; }); if ($noAdmins) { $msg = $app->trans('There is no one to validate orders, please contact an administrator'); } $order->setTodo($order->getElements()->count()); try { $app['events-manager']->trigger('__NEW_ORDER__', ['order_id' => $order->getId(), 'usr_id' => $order->getUser()->getId()]); $success = true; $app['EM']->persist($order); $app['EM']->flush(); } catch (\Exception $e) { } if ($success) { $msg = $app->trans('The records have been properly ordered'); } else { $msg = $app->trans('An error occured'); } } else { $msg = $app->trans('There is no record eligible for an order'); } if ('json' === $app['request']->getRequestFormat()) { return $app->json(['success' => $success, 'msg' => $msg]); } return $app->redirectPath('prod_orders', ['success' => (int) $success, 'action' => 'send']); }
function forAll(\Closure $p) { return $this->fields->forAll($p); }
/** * @inheritdoc * @todo change since and flags to array of options after implementing another VCS type. */ public function commits($since = '', $flags = 0) { // if (!$this->isDeployed()) { // // @todo throw exception or clone // } $commandParts = []; $commandParts['executable'] = (string) $this->gitExecutablePath; $commandParts['remotePath'] = '-C "' . $this->repoPath . '"'; $commandParts['action'] = 'log --date=iso --numstat'; $commandParts['option-no-merges'] = $this->hasFlag(VCS_FLAG_NO_MERGES, $flags) ? '--no-merges' : ''; $commandParts['option-no-walk'] = $this->hasFlag(VCS_FLAG_NO_WALK, $flags) ? '--no-walk' : ''; $commandParts['option-tags'] = $this->hasFlag(VCS_FLAG_TAGS, $flags) ? '--tags' : ''; $commandParts['format'] = '--pretty=format:"{\\"commit\\":\\"%H\\",\\"committer_name\\":\\"%cN\\",\\"committer_email\\":\\"%cE\\",\\"committer_date\\":\\"%ci\\",\\"subject\\":\\"%f\\"}"'; $commandParts['since'] = strlen($since) > 0 ? '--since="' . $since . '"' : ''; $commandString = implode(' ', array_filter($commandParts)); $extractListing = new ArrayCollection($this->launcher->run($commandString)); $responseListing = new ArrayCollection(); $state = []; $extractListing->forAll(function ($index, $item) use($responseListing, &$state) { switch (true) { case trim($item) === '': break; case substr($item, 0, 1) === '{': // adding an item that didn't have changed files (successive log entries) if (count($state) > 0) { $commit = Commit::build($state); $responseListing->set($commit->sha, $commit); } $state = json_decode($item, true); $state['changes'] = []; break; default: $parts = explode("\t", $item); if (count($parts) === 3 && $responseListing->count() > 0) { $responseListing->last()->putChangedFile($parts[2], $parts[0], $parts[1]); } break; } return true; }); return $responseListing; }