本文整理汇总了PHP中Doctrine\Common\Collections\ArrayCollection::count方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayCollection::count方法的具体用法?PHP ArrayCollection::count怎么用?PHP ArrayCollection::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\ArrayCollection
的用法示例。
在下文中一共展示了ArrayCollection::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sameValueAs
/**
* @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);
});
});
}
示例2: testBind01
public function testBind01()
{
$expectedJSON = file_get_contents(dirname(__DIR__) . '/../../Resources/json/client_aftership_couriers_response_handler_01.json');
$this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue(200));
$this->response->expects($this->once())->method('getContent')->will($this->returnValue($expectedJSON));
$this->responseHandler->bind($this->response, $this->collection);
$this->assertEquals(26, $this->collection->count());
$courier0 = $this->collection[0];
$this->assertEquals('USPS', $courier0->getName());
$this->assertEquals('United States Postal Service', $courier0->getOtherName());
$this->assertEquals('+1 800-275-8777', $courier0->getPhone());
$this->assertEquals(['USA'], $courier0->getServiceCountries());
$this->assertEquals('usps', $courier0->getSlug());
$this->assertEquals(['en'], $courier0->getSupportLanguages());
$this->assertNotNull($courier0->getUpdatedAt());
$this->assertEquals("https://www.usps.com", $courier0->getUrl());
$courier13 = $this->collection[13];
$this->assertEquals('Hong Kong Post', $courier13->getName());
$this->assertEquals('香港郵政', $courier13->getOtherName());
$this->assertEquals('+852 2921 2222', $courier13->getPhone());
$this->assertEquals(['HKG'], $courier13->getServiceCountries());
$this->assertEquals('hong-kong-post', $courier13->getSlug());
$this->assertEquals(['en'], $courier13->getSupportLanguages());
$this->assertNotNull($courier13->getUpdatedAt());
$this->assertEquals("http://hongkongpost.com", $courier13->getUrl());
}
示例3: count
public function count()
{
if (null === $this->entries) {
return $this->repository->countByFeeds($this->feeds);
}
return $this->entries->count();
}
示例4: testOnSubmitDoNothing
public function testOnSubmitDoNothing()
{
$submittedData = array('test');
$event = new FormEvent($this->getForm(), $submittedData);
$this->dispatcher->dispatch(FormEvents::SUBMIT, $event);
$this->assertTrue($this->collection->contains('test'));
$this->assertSame(1, $this->collection->count());
}
示例5: add
public function add(IEntity $entity)
{
$this->errorOnInvalidEntityType($entity);
if ($this->getIdentityValue($entity) < 1) {
$this->setIdentityValue($entity, $this->collection->count() + 1);
}
$this->collection->set($entity->getId(), $entity);
}
示例6: isUnread
/**
* Gets whether the user has read this thread since the last post
*
* @param User $user
*
* @return boolean
*/
public function isUnread(User $user)
{
if ($this->posts->count() === 0) {
return false;
}
return $this->posts->last()->isUnread($user);
}
示例7: getQBAliasReference
public function getQBAliasReference($class, $attribute = NULL)
{
if (!is_object($class)) {
throw new \Exception("object must be of type object, type %s given.", gettype($class));
}
$class_name = get_class($class);
// get alias of class
$alias = NULL;
foreach ($this->qb_alias_reference->toArray() as $_class => $_alias) {
if (isset($_alias[$class_name])) {
$alias = $_alias[$class_name];
}
}
// if not found
if ($alias === NULL) {
// if empty, set new
if ($this->qb_alias_reference->count() == 0) {
$alias = 'a';
// get last and then count up
} else {
$lastAlias = $this->qb_alias_reference->last();
$alias = ++$lastAlias[key($lastAlias)];
}
// add new
$this->qb_alias_reference->add(array($class_name => $alias));
}
return $attribute === NULL ? $alias : $alias . '.' . $attribute;
}
示例8: isAllDead
/**
* @param array $deadEntities
* @return bool
*/
protected function isAllDead(array $deadEntities)
{
if (count($deadEntities) == $this->existEntityCollection->count()) {
return true;
}
return false;
}
示例9: getMediaForThumbnail
/**
* @return AbstractMediaEntity|null
*/
public function getMediaForThumbnail()
{
if ($this->media->count() > 0) {
return $this->media->first();
}
return null;
}
示例10: removeChannel
/**
* {@inheritdoc}
*/
public function removeChannel(ChannelInterface $channel)
{
$this->channels->removeElement($channel);
if ($this->channels->count() === 0) {
$this->activated = false;
}
return $this;
}
示例11: setComments
/**
* Set Comments
*
* @param array $comments
*
* @return $this
*/
public function setComments(array $comments)
{
foreach ($comments as $comment) {
$this->addComments($comment);
}
$this->nbComments = $this->comments->count();
return $this;
}
示例12: getRoles
public function getRoles()
{
if (!$this->roles->count()) {
return array(parent::ROLE_DEFAULT);
}
$roles = $this->roles->toArray();
foreach ($this->getGroups() as $group) {
$roles = array_merge($roles, $group->getRoles());
}
foreach ($roles as $k => $role) {
/*
* Ensure String[] to prevent bad unserialized UsernamePasswordToken with for instance
* UPT#roles:{Role('ROLE_USER'), 'ROLE_USER'} which ends in Error: Call to a member
* function getRole() on a non-object
*/
$roles[$k] = $role instanceof RoleInterface ? $role->getRole() : (string) $role;
}
return array_flip(array_flip($roles));
}
示例13: testReverseTransform
/**
* @dataProvider transformDataProvider
*
* @param mixed $expected
* @param mixed $value
*/
public function testReverseTransform($expected, $value)
{
if (!$expected) {
$expected = new ArrayCollection();
}
$this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
return $this->createDataObject(func_get_arg(1));
}));
$this->assertEquals($expected, $this->transformer->reverseTransform($value));
}
示例14: getCategory
/**
* @return Category
*/
public function getCategory()
{
if ($this->enrollments->count() > 1) {
throw new ValidationException("INVALIDENROLLMENT", "A team can not be enrolled for more than one category - team id=" . $this->id);
}
if ($this->enrollments->count() == 1) {
return $this->enrollments->first()->getCategory();
}
return null;
}
示例15: bulkInserts
/**
* @param ArrayCollection $articles
* @param Integer $batch_size
*/
public function bulkInserts(ArrayCollection $articles, $batch_size = 20)
{
$length = $articles->count();
for ($i = 1; $i < $length; ++$i) {
$this->merge($articles->get($i));
if (0 === $i % $batch_size) {
$this->detaches();
}
}
$this->detaches();
}