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


PHP Collection::count方法代码示例

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


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

示例1: testClone

 public function testClone()
 {
     $clone = $this->collection->clone();
     $clone->push('test');
     $this->assertEquals(4, $this->collection->count());
     $this->assertEquals(5, $clone->count());
 }
开发者ID:dtkahl,项目名称:php-collection,代码行数:7,代码来源:CollectionTest.php

示例2: count

 /**
  * {@inheritdoc}
  */
 public function count()
 {
     if ($this->mapping['isInverseSide']) {
         $this->initialize();
     }
     return count($this->mongoData) + $this->coll->count();
 }
开发者ID:richardmiller,项目名称:mongodb-odm,代码行数:10,代码来源:PersistentCollection.php

示例3: testAddsAllElements

 public function testAddsAllElements()
 {
     $list = new Collection(\Cassandra::TYPE_VARINT);
     $list->add(new Varint('1'), new Varint('2'), new Varint('3'), new Varint('4'), new Varint('5'), new Varint('6'), new Varint('7'), new Varint('8'));
     $this->assertEquals(8, $list->count());
     $this->assertEquals(array(new Varint('1'), new Varint('2'), new Varint('3'), new Varint('4'), new Varint('5'), new Varint('6'), new Varint('7'), new Varint('8')), $list->values());
 }
开发者ID:Dylan1312,项目名称:php-driver,代码行数:7,代码来源:CollectionTest.php

示例4: getAvailableConfigOptions

 /**
  * Return a list of available configuration options.
  *
  * @param Collection $availableTypes Collection of Injector\InjectorInterface::TYPE_*
  *     constants indicating valid package types that could be injected.
  * @param string $projectRoot Path to the project root; assumes PWD by
  *     default.
  * @return Collection Collection of ConfigOption instances.
  */
 public function getAvailableConfigOptions(Collection $availableTypes, $projectRoot = '')
 {
     // Create an initial collection to which we'll append.
     // This approach is used to ensure indexes are sane.
     $discovered = new Collection([new ConfigOption('Do not inject', new Injector\NoopInjector())]);
     Collection::create($this->discovery)->map(function ($discoveryClass) use($projectRoot) {
         if (is_array($discoveryClass)) {
             return new ConfigDiscovery\DiscoveryChain($discoveryClass, $projectRoot);
         }
         return new $discoveryClass($projectRoot);
     })->filter(function ($discovery) {
         return $discovery->locate();
     })->map(function ($discovery, $file) use($projectRoot, $availableTypes) {
         // Look up the injector based on the file type
         $injectorClass = $this->injectors[$file];
         if (is_array($injectorClass)) {
             return new Injector\ConfigInjectorChain($injectorClass, $discovery, $availableTypes, $projectRoot);
         }
         return new $injectorClass($projectRoot);
     })->filter(function ($injector) use($availableTypes) {
         return $availableTypes->reduce(function ($flag, $type) use($injector) {
             return $flag || $injector->registersType($type);
         }, false);
     })->each(function ($injector, $file) use($discovered) {
         $discovered[] = new ConfigOption($file, $injector);
     });
     return 1 === $discovered->count() ? new Collection([]) : $discovered;
 }
开发者ID:zendframework,项目名称:zend-component-installer,代码行数:37,代码来源:ConfigDiscovery.php

示例5: find

 /**
  * Find element from collection by key and value
  * 
  * @param string $key - search index
  * @param string $value - search value
  * @param [boolean $onlyIndex] - this flag can return only indixes of records found
  * @return NULL|Collection <NULL, \VCAPI\Common\Collection>
  */
 public function find($key, $value, $onlyIndex = false)
 {
     if (empty($this->collection)) {
         return null;
     }
     $return = new Collection();
     foreach ($this->collection as $index => $item) {
         if (is_array($item)) {
             if (!isset($item[$key])) {
                 continue;
             }
             if ($item[$key] == $value) {
                 if ($onlyIndex) {
                     $return->add($index);
                 } else {
                     $return->add($item);
                 }
             }
         } elseif (is_object($item)) {
             if (!property_exists($item, $key)) {
                 continue;
             }
             if ($item->{$key} == $value) {
                 if ($onlyIndex) {
                     $return->add($index);
                 } else {
                     $return->add($item);
                 }
             }
         }
     }
     return $return->count() ? $return : null;
 }
开发者ID:pshon,项目名称:vcapi,代码行数:41,代码来源:Collection.php

示例6: __get

 /**
  * Dynamically retrieve attributes on the model.
  *
  * @param  string $key
  *
  * @return Collection
  */
 public function __get($key)
 {
     $newCollection = new Collection();
     foreach ($this->items as $item) {
         if ($item instanceof Collection) {
             foreach ($item as $subItem) {
                 $newCollection->put($newCollection->count(), $subItem->{$key});
             }
         } elseif (is_object($item) && !$item instanceof Collection && $item->{$key} instanceof Collection) {
             foreach ($item->{$key} as $subItem) {
                 $newCollection->put($newCollection->count(), $subItem);
             }
         } else {
             $newCollection->put($newCollection->count(), $item->{$key});
         }
     }
     return $newCollection;
 }
开发者ID:adamdburton,项目名称:Steam,代码行数:25,代码来源:Collection.php

示例7: addCategory

 /**
  * Add a new category that list items
  *
  * @param \Amisure\P4SApiBundle\Entity\EvaluationItemCategory|string $category
  *        	Evaluation item category, or name of the evaluation item category
  * @see \Amisure\P4SApiBundle\Entity\EvaluationItemCategory
  * @return \Amisure\P4SApiBundle\Entity\Evaluation
  */
 public function addCategory($category)
 {
     $evaluationCategory = $category;
     if (is_string($category)) {
         $evaluationCategory = new EvaluationModelCategory($category);
     }
     $evaluationCategory->setEvaluation($this);
     if (-1 == $evaluationCategory->getCategoryId()) {
         $evaluationCategory->setCategoryId($this->categories->count());
     }
     $this->categories->add($evaluationCategory);
     return $this;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:21,代码来源:EvaluationModel.php

示例8: addItem

 /**
  * Add a new item
  *
  * @param \Amisure\P4SApiBundle\Entity\EvaluationModelItem|string $item
  *        	Evaluation item, or description of the evaluation item
  * @param string $value
  *        	Value of the evaluation item if the evaluation item itself is not previsously provided
  * @see \Amisure\P4SApiBundle\Entity\EvaluationModelItem
  * @return \Amisure\P4SApiBundle\Entity\EvaluationModelCategory
  */
 public function addItem($item, $responseType = '')
 {
     $evaluationItem = $item;
     if (is_string($item)) {
         $evaluationItem = new EvaluationModelItem($item, $responseType);
     }
     $evaluationItem->setCategory($this);
     if (-1 == $evaluationItem->getItemId()) {
         $evaluationItem->setItemId($this->items->count());
     }
     $this->items->add($evaluationItem);
     return $this;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:23,代码来源:EvaluationModelCategory.php

示例9: addResponse

 /**
  * Add a new item response
  *
  * @param \Amisure\P4SApiBundle\Entity\EvaluationModelItemResponse|string $item
  *        	Evaluation item, or description of the evaluation item
  * @param string $label
  *        	Label of the evaluation item response if the evaluation item response itself is not previsously provided
  * @param string $type
  *        	Type of the evaluation item response if the evaluation item response itself is not previsously provided
  * @see \Amisure\P4SApiBundle\Entity\EvaluationModelItem
  * @return \Amisure\P4SApiBundle\Entity\EvaluationModelItem
  */
 public function addResponse($response, $label = '', $type = EvaluationModelItemResponse::TypeString)
 {
     $evaluationResponse = $response;
     if (is_string($response)) {
         $evaluationResponse = new EvaluationModelItem($response, $label, $type);
     }
     $evaluationResponse->setItem($this);
     if (-1 == $evaluationResponse->getResponseId()) {
         $evaluationResponse->setResponseId($this->responses->count());
     }
     $this->responses->add($evaluationResponse);
     return $this;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:25,代码来源:EvaluationModelItem.php

示例10: test3_Appending

 public function test3_Appending()
 {
     $collection = new Collection(new Yaml());
     $collection_of_values = new Collection(new Yaml());
     # appending
     static::$collection->append('part1.item2', ['name' => 'Janice']);
     $this->assertEquals('Janice', static::$collection->get('part1.item2.name'));
     static::$collection->forget('part1');
     static::$collection->append('part1', ['item2' => ['name' => 'Janice']]);
     static::$collection->with('with', 'with test');
     $this->assertEquals('with test', static::$collection->get('with'));
     $this->assertTrue(static::$collection->count() === 2);
     static::$collection->forget('with');
     $this->assertTrue(static::$collection->count() === 1);
     # setup
     $test_array = ['merge_with' => ['merge' => 'this']];
     $collection_of_values->with($test_array);
     # test with an array
     $collection->merge($test_array);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with a collection as a value object
     $collection->merge($collection_of_values);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with value object
     $value_object = new \stdClass();
     $value_object->merge_with = $test_array['merge_with'];
     $collection->merge($value_object);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     # test with flat array
     $collection->merge(Util::array_from_str('merge with'));
     $this->assertEquals($collection->get('merge'), NULL);
     $this->assertEquals($collection->get('with'), NULL);
     $this->setExpectedException('InvalidArgumentException', "Cannot append an already existing key: 'part1'");
     static::$collection->append('part1', ['item2' => ['name' => 'Mary']]);
 }
开发者ID:anctemarry27,项目名称:cogs,代码行数:37,代码来源:CollectionTest.php

示例11: buildCollection

 /**
  * build a Collection object with objects of this class based on filters
  *
  * @param Array $filters
  * @param string|null $order literal SQL appended to "ORDER BY " if used.
  * @returns Collection object
  */
 public static function buildCollection($filters, $order = null)
 {
     Debug::log(">>" . get_called_class() . ":: " . __FUNCTION__ . " called with filters:", $filters);
     $collection = new Collection();
     $sql = static::buildCollectionSql($params, $filters, $order);
     $stmt = static::getConnection()->prepAndExecute(new \ArtfulRobot\PDO_Query("Fetch records from " . static::TABLE_NAME, $sql, $params));
     if ($stmt->errorCode() != '00000') {
         throw new Exception("PDO error: " . print_r($stmt->errorInfo(), 1));
     }
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         // create an object of the class
         $obj = new static();
         $obj->loadFromArray($row, false, self::CAST_DB);
         $collection->append($obj, $obj->id);
         unset($obj);
     }
     Debug::log("<< Returning collection with " . $collection->count() . " entries");
     return $collection;
 }
开发者ID:artfulrobot,项目名称:artfulrobot,代码行数:26,代码来源:Model.php

示例12: count

 /**
  * Get the number of public properties in the ArrayObject
  * @return int
  */
 public function count()
 {
     if (!$this->isLoaded() && $this->isLoadable()) {
         $this->load();
     }
     return parent::count();
 }
开发者ID:matak,项目名称:dbrecord,代码行数:11,代码来源:LazyCollection.php

示例13: hasChildren

 /**
  * Check node children
  *
  * @return bool
  */
 public function hasChildren()
 {
     return $this->_childNodes->count() > 0;
 }
开发者ID:schpill,项目名称:standalone,代码行数:9,代码来源:Node.php

示例14: Patch

<?php

include "../patches.php";
$patch = new Patch(18);
if (!$patch->exists()) {
    $createSql = "CREATE TABLE IF NOT EXISTS `webcam_images` (\n\t\t\t  `timestamp` datetime NOT NULL,\n\t\t\t  `image_id` bigint(11) unsigned NOT NULL,\n\t\t\t  `user_id` int(11) unsigned NOT NULL,\n\t\t\t  `bot_id` int(11) unsigned NULL,\n\t\t\t  `job_id` int(11) unsigned NULL,\n\t\t\t  PRIMARY KEY (`timestamp`, `image_id`),\n\t\t\t  FOREIGN KEY (`image_id`) REFERENCES s3_files(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`bot_id`) REFERENCES bots(`id`) ON DELETE CASCADE,\n\t\t\t  FOREIGN KEY (`job_id`) REFERENCES jobs(`id`) ON DELETE CASCADE\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    db()->execute($createSql);
    $failCount = 0;
    $rowSql = "SELECT id from jobs where webcam_images!=''";
    $jobsCollection = new Collection($rowSql);
    $jobsCollection->bindType('id', 'Job');
    $jobs = $jobsCollection->getAll();
    $total = $jobsCollection->count();
    $count = 0;
    $patch->progress(0);
    // Get the current webcam images in an array, so we can quickly skip those.
    $pdoStatement = db()->query("SELECT image_id from webcam_images");
    $existingImages = array();
    foreach ($pdoStatement->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $existingImages[$row['image_id']] = true;
    }
    foreach ($jobs as $row) {
        /** @var Job $job */
        $job = $row['Job'];
        $images_json = $job->get('webcam_images');
        if ($job->isHydrated() && $images_json != "") {
            $images = json_decode($images_json, true);
            $rowData = array();
            foreach ($images as $timestamp => $image_id) {
                if (!array_key_exists($image_id, $existingImages)) {
                    $file = Storage::get($image_id);
开发者ID:eric116,项目名称:BotQueue,代码行数:31,代码来源:v05p06.php

示例15: hasGists

 /**
  * @return bool
  */
 public function hasGists()
 {
     return $this->gists->count() > 0;
 }
开发者ID:thomasbabuj,项目名称:gistlog,代码行数:7,代码来源:Author.php


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