当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayCollection::matching方法代码示例

本文整理汇总了PHP中Doctrine\Common\Collections\ArrayCollection::matching方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayCollection::matching方法的具体用法?PHP ArrayCollection::matching怎么用?PHP ArrayCollection::matching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Collections\ArrayCollection的用法示例。


在下文中一共展示了ArrayCollection::matching方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initDatabaseMock

 /**
  * Initialize mocks for Doctrine
  * 
  * @param array $managersToMock List of managers to be mocked
  * 
  * @return void
  */
 protected function initDatabaseMock($managersToMock)
 {
     if (is_null($this->mockedManager)) {
         $test = $this;
         foreach ($managersToMock as $manager) {
             $entityName = $manager['entityName'];
             // EntityManager mock
             $entityManagerMock = new \mock\Doctrine\ORM\EntityManager();
             // ClassMetadata mock
             $classMetadata = new \mock\Doctrine\ORM\Mapping\ClassMetadata($entityName);
             $entityClassName = $manager['entityClassName'];
             $this->calling($classMetadata)->getName = function () use($entityClassName) {
                 return $entityClassName;
             };
             // EntityRepository mock
             $entityRepositoryMock = new \mock\Doctrine\ORM\EntityRepository($entityManagerMock, $classMetadata);
             $this->calling($entityRepositoryMock)->find = function ($id) use($test, $entityName) {
                 if (!empty($test->database[$entityName]) && array_key_exists($id, $test->database[$entityName])) {
                     return clone $test->database[$entityName][$id];
                 }
                 return null;
             };
             $this->calling($entityRepositoryMock)->findBy = function ($criteria = [], $sort = null, $limit = null, $start = 0) use($test, $entityName) {
                 $entities = new ArrayCollection($test->database[$entityName]);
                 $crit = new Criteria();
                 foreach ($criteria as $field => $value) {
                     $crit->andWhere($crit->expr()->eq($field, $value));
                 }
                 if (!is_null($sort)) {
                     $crit->orderBy($sort);
                 }
                 $crit->setFirstResult($start);
                 $crit->setMaxResults($limit);
                 return $entities->matching($crit)->map(function ($item) {
                     return clone $item;
                 });
             };
             // Overload main EntityManager functions
             $this->calling($entityManagerMock)->getRepository = function () use($entityRepositoryMock) {
                 return $entityRepositoryMock;
             };
             $this->calling($entityManagerMock)->getClassMetadata = function ($entity) use($classMetadata) {
                 return $classMetadata;
             };
             $this->calling($entityManagerMock)->persist = function ($entity) use($test, $entityName) {
                 if (!$entity->getId()) {
                     if (!empty($test->database[$entityName])) {
                         $entity->setId(count($test->database[$entityName]) + 1);
                     } else {
                         $entity->setId(1);
                     }
                 }
                 $test->database[$entityName][$entity->getId()] = $entity;
                 return true;
             };
             $this->calling($entityManagerMock)->remove = function ($entity) use($test, $entityName) {
                 if (!$entity->getId() || empty($test->database[$entityName][$entity->getId()])) {
                     return false;
                 }
                 unset($test->database[$entityName][$entity->getId()]);
                 return true;
             };
             $mockClass = '\\mock' . $manager['className'];
             $managerMock = new $mockClass($entityManagerMock, $entityName);
             $this->mockedManager[$manager['serviceName']] = $managerMock;
         }
     }
 }
开发者ID:e-ReColNat,项目名称:recolnat-diff,代码行数:75,代码来源:AbstractDoctrineMockedTest.php

示例2: testMatchingWithSortingPreservesyKeys

 public function testMatchingWithSortingPreservesyKeys()
 {
     $object1 = new \stdClass();
     $object2 = new \stdClass();
     $object1->sortField = 2;
     $object2->sortField = 1;
     $collection = new ArrayCollection(array('object1' => $object1, 'object2' => $object2));
     $this->assertSame(array('object2' => $object2, 'object1' => $object1), $collection->matching(new Criteria(null, array('sortField' => Criteria::ASC)))->toArray());
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:9,代码来源:ArrayCollectionTest.php

示例3: matching

 public function matching(Criteria $criteria)
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->matching($criteria);
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:7,代码来源:AggregateEntryCollection.php

示例4: getUserPermissions

 /**
  * Gets permissions of the given user
  *
  * @param User          $user
  * @param Criteria|null $filters
  *
  * @return array
  */
 public function getUserPermissions(User $user, Criteria $filters = null)
 {
     $entityAclExtension = $this->aclSelector->select($user);
     $resources = array_map(function (AclClassInfo $class) use($entityAclExtension) {
         return ['type' => $entityAclExtension->getExtensionKey(), 'resource' => $class->getClassName()];
     }, $entityAclExtension->getClasses());
     if ($filters) {
         $collection = new ArrayCollection($resources);
         $resources = $collection->matching($filters)->toArray();
     }
     $result = [];
     $originalToken = $this->impersonateUser($user);
     try {
         foreach ($resources as $resource) {
             $oid = new ObjectIdentity($resource['type'], $resource['resource']);
             $permissions = [];
             foreach ($entityAclExtension->getAllowedPermissions($oid) as $permission) {
                 if ($this->securityContext->isGranted($permission, $oid)) {
                     $permissions[] = $permission;
                 }
             }
             $result[] = array_merge($resource, ['permissions' => $permissions]);
         }
         $this->undoImpersonation($originalToken);
     } catch (\Exception $e) {
         $this->undoImpersonation($originalToken);
         throw $e;
     }
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:38,代码来源:UserPermissionApiEntityManager.php

示例5: getVoteInfoAssignment

 private function getVoteInfoAssignment(AbstractTerritoire $territoire)
 {
     // try to fetch from cache
     if (isset($this->cache['voteInfo'][spl_object_hash($territoire)])) {
         return $this->cache['voteInfo'][spl_object_hash($territoire)];
     }
     // if not in cache, not changed, so we dont mind fetching from db
     if ($this->voteInfos instanceof PersistentCollection) {
         $this->voteInfos->setDirty(false);
     }
     $criteria = Criteria::create()->where(Criteria::expr()->eq('territoire_id', $territoire->getId()));
     $collection = $this->voteInfos->matching($criteria);
     if ($this->voteInfos instanceof PersistentCollection) {
         $this->voteInfos->setDirty(true);
     }
     // filter again if territoire_id were not initialized
     $criteria = Criteria::create()->where(Criteria::expr()->eq('territoire', $territoire));
     $array = array_values($collection->matching($criteria)->toArray());
     if (array_key_exists(0, $array)) {
         $voteInfoAssignment = $array[0];
     }
     // new one if not found
     if (!isset($voteInfoAssignment)) {
         $voteInfoAssignment = new VoteInfoAssignment($this, $territoire);
         $this->voteInfos[] = $voteInfoAssignment;
     }
     // put to cache
     $this->cache['voteInfo'][spl_object_hash($territoire)] = $voteInfoAssignment;
     return $voteInfoAssignment;
 }
开发者ID:AlexisEidelman,项目名称:dataelections.fr,代码行数:30,代码来源:Election.php

示例6: getPluginByCriteria

 public function getPluginByCriteria($criteria, $needle)
 {
     $eb = new ExpressionBuilder();
     $expr = $eb->eq($criteria, $needle);
     $criteria = new Criteria($expr);
     $availablePlugins = new ArrayCollection($this->getAllAvailablePlugins());
     return $availablePlugins->matching($criteria);
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:8,代码来源:PluginsService.php

示例7: getAnnouncements

 public function getAnnouncements()
 {
     $eb = new ExpressionBuilder();
     $expr = $eb->eq('removed', false);
     $criteria = new Criteria($expr);
     $announcements = new ArrayCollection($this->announcements->toArray());
     return $announcements->matching($criteria);
 }
开发者ID:riverans,项目名称:AdvertsPluginBundle,代码行数:8,代码来源:Category.php

示例8: thereAreRecordsInWhere

 /**
  * @Given /^Records in \'([^\']+)\' where \'([^\']+)\', has data$/
  * @param $tableName
  * @param $where
  * @param TableNode $table
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Exception
  */
 public function thereAreRecordsInWhere($tableName, $where, TableNode $table)
 {
     /** @var Connection $connection */
     $connection = $this->container->get('doctrine')->getConnection();
     $exists = new ArrayCollection($connection->query("SELECT * FROM {$tableName} WHERE {$where}")->fetchAll());
     $criteria = new Criteria();
     $recordsMatching = $exists->matching($criteria);
     $record = $recordsMatching->first();
     $i = 1;
     foreach ($table as $row) {
         foreach ($row as $key => $value) {
             \PHPUnit_Framework_Assert::assertArrayHasKey($key, $record, "Column '{$key}' doesn't exists in database");
             \PHPUnit_Framework_Assert::assertEquals($value, $record[$key], "Invalid value for '{$key}' in row {$i}");
         }
         ++$i;
     }
 }
开发者ID:Combination,项目名称:BehatDatabaseFixtureExtension,代码行数:25,代码来源:CoreContext.php

示例9: filter

 /**
  * Filter a result set for a given configuration.
  *
  * @param ActiveConfigurationInterface $config
  * @param array $data
  * @return array
  */
 public static function filter(ActiveConfigurationInterface $config, array $data)
 {
     $data = new ArrayCollection($data);
     $filters = $config->getFields();
     $filterOptions = $config->getOriginalConfig()->getFields();
     $fields = array_keys($filters);
     $criteria = Criteria::create();
     foreach ($fields as $field) {
         foreach ($filters[$field] as $key => $filter) {
             $resolver = new OptionsResolver();
             $filter->configureOptions($resolver);
             $options = $filter->resolveOptions($resolver, $filterOptions[$field][$key]->getOptions());
             $filter->filter($criteria, $config->getField($field), $options);
         }
     }
     return $data->matching($criteria)->getValues();
 }
开发者ID:upenn-dag,项目名称:patient-repository,代码行数:24,代码来源:BaseDataset.php

示例10: getHeadEmail

 /**
  * Get head email in thread
  *
  * @param EntityManager $entityManager
  * @param Email $entity
  *
  * @return Email
  */
 public function getHeadEmail(EntityManager $entityManager, Email $entity)
 {
     $headEmail = $entity;
     $thread = $entity->getThread();
     if ($thread) {
         $emails = new ArrayCollection($this->getThreadEmails($entityManager, $entity));
         $criteria = new Criteria();
         $criteria->orderBy(['sentAt' => Criteria::DESC]);
         $criteria->setMaxResults(1);
         $unseenEmails = $emails->matching($criteria);
         if (count($unseenEmails)) {
             $headEmail = $unseenEmails[0];
         } elseif (count($emails)) {
             $headEmail = $emails[0];
         }
     }
     return $headEmail;
 }
开发者ID:Maksold,项目名称:platform,代码行数:26,代码来源:EmailThreadProvider.php

示例11: getTermsBy

 /**
  * Collects terms where $prop matches $value
  *
  * @return ArrayCollection
  */
 protected function getTermsBy($prop, $value)
 {
     $criteria = new Criteria(Criteria::expr()->eq($prop, $value));
     return $this->terms->matching($criteria);
 }
开发者ID:jtallant,项目名称:skimpy-engine,代码行数:10,代码来源:Taxonomy.php

示例12: getUserCourseSubscriptionsByStatus

 /**
  * Get user from course by status
  * @param \Chamilo\CoreBundle\Entity\Course $course
  * @param string $status
  * @return \Doctrine\Common\Collections\Collection|static
  */
 public function getUserCourseSubscriptionsByStatus(Course $course, $status)
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq("course", $course))->andWhere(Criteria::expr()->eq("status", $status));
     return $this->userCourseSubscriptions->matching($criteria);
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:11,代码来源:Session.php

示例13: getCountryDescriptionByLanguage

 /**
  * Get Country Description by language
  *
  * @param integer $languageId
  * @return CountryDescription
  */
 public function getCountryDescriptionByLanguage($languageId = 2)
 {
     $criteria = Criteria::create();
     $criteria->where(Criteria::expr()->eq('languageId', $languageId));
     return $this->descriptions->matching($criteria)->current();
 }
开发者ID:plescanicolai,项目名称:base,代码行数:12,代码来源:Country.php

示例14: getMetaByKey

 /**
  * @param string $name
  *
  * @return \Doctrine\Common\Collections\Collection
  */
 public function getMetaByKey($name)
 {
     $criteria = Criteria::create();
     $criteria->where(Criteria::expr()->eq('key', $name));
     return $this->metas->matching($criteria);
 }
开发者ID:thedarsideofit,项目名称:EkinoWordpressBundle,代码行数:11,代码来源:Post.php

示例15: testMultiColumnSortAppliesAllSorts

 public function testMultiColumnSortAppliesAllSorts()
 {
     $collection = new ArrayCollection(array(array('foo' => 1, 'bar' => 2), array('foo' => 2, 'bar' => 4), array('foo' => 2, 'bar' => 3)));
     $expected = array(1 => array('foo' => 2, 'bar' => 4), 2 => array('foo' => 2, 'bar' => 3), 0 => array('foo' => 1, 'bar' => 2));
     $this->assertSame($expected, $collection->matching(new Criteria(null, array('foo' => Criteria::DESC, 'bar' => Criteria::DESC)))->toArray());
 }
开发者ID:lenninsanchez,项目名称:donadores,代码行数:6,代码来源:ArrayCollectionTest.php


注:本文中的Doctrine\Common\Collections\ArrayCollection::matching方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。