當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SplFixedArray::fromArray方法代碼示例

本文整理匯總了PHP中SplFixedArray::fromArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP SplFixedArray::fromArray方法的具體用法?PHP SplFixedArray::fromArray怎麽用?PHP SplFixedArray::fromArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SplFixedArray的用法示例。


在下文中一共展示了SplFixedArray::fromArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: fromArray

 /**
  * @param array $array
  * @param boolean $save_indexes = true
  * @return SplFixedArray, DataStructures\SerializableFixedArray
  */
 public static function fromArray(array $array, $save_indexes = true)
 {
     if (self::$_useSpl === null) {
         self::_checkEnvironment();
     }
     return self::$_useSpl ? \SplFixedArray::fromArray($array, $save_indexes) : new self(count($array), $save_indexes ? $array : array_values($array));
 }
開發者ID:performics,項目名稱:ga-cli-api,代碼行數:12,代碼來源:SerializableFixedArray.class.php

示例2: testMapTraversable

 public function testMapTraversable()
 {
     $expected = [1, 2, 3, 4];
     $arr = \SplFixedArray::fromArray($expected);
     $actual = t::into([], t::map(t::value()), $arr);
     $this->assertEquals($expected, $actual);
 }
開發者ID:bahulneel,項目名稱:phonon,代碼行數:7,代碼來源:ReduceTest.php

示例3: testFromArrayDisordered

 public function testFromArrayDisordered()
 {
     $array = array(1 => 'foo', 3 => 'bar', 2 => 'baz', 0 => 'qux');
     $the_DS = DynamicArray::fromArray($array);
     $SPL_DS = \SplFixedArray::fromArray($array);
     $this->assertMethodsEqual($SPL_DS, $the_DS);
 }
開發者ID:daniel-ac-martin,項目名稱:php-seids,代碼行數:7,代碼來源:DynamicArrayTest.php

示例4: __construct

 /**
  * Create a new instance.
  *
  * @param array            $matchRegexps The regexes to match files.
  *
  * @param AbstractFilter[] $filters      The filters to apply.
  */
 public function __construct(array $matchRegexps, $filters)
 {
     foreach ($matchRegexps as $pattern) {
         $this->matchRegexps[] = $this->toRegex($pattern);
     }
     $this->filters = \SplFixedArray::fromArray($filters);
 }
開發者ID:cyberspectrum,項目名稱:pharpiler,代碼行數:14,代碼來源:Collection.php

示例5: copyOf

 /**
  * Create a new ImmutableVector from the given traversable.
  * @param array|Traversable $traversable
  * @param bool $preserveKeys
  * @return ImmutableVector
  */
 public static function copyOf($traversable, $preserveKeys = true)
 {
     if (is_array($traversable)) {
         return new self(\SplFixedArray::fromArray($traversable, $preserveKeys));
     } else {
         return new self(\SplFixedArray::fromArray(iterator_to_array($traversable), $preserveKeys));
     }
 }
開發者ID:hoesler,項目名稱:traver,代碼行數:14,代碼來源:ImmutableVector.php

示例6: valuesDataProvider

 public function valuesDataProvider()
 {
     $splFixedArrayIn = \SplFixedArray::fromArray([2, 154, 2342, 1001, 7651, 4523, 1343, 756, 6324, 1]);
     $expected = [1, 2, 154, 756, 1001, 1343, 2342, 4523, 6324, 7651];
     $splFixedArrayIn2 = clone $splFixedArrayIn;
     $splFixedArrayIn2[9] = 8000;
     $expected2 = [2, 154, 756, 1001, 1343, 2342, 4523, 6324, 7651, 8000];
     return [[$splFixedArrayIn, $expected], [$splFixedArrayIn2, $expected2]];
 }
開發者ID:valdislav,項目名稱:SplFixedArray,代碼行數:9,代碼來源:SortStrategyTest.php

示例7: __construct

 public function __construct(array $list = array())
 {
     array_map(function ($item) {
         if (!$item instanceof FFMpegThumbnailer) {
             throw new \InvalidArgumentException('Excpecting list of FFMpegThumbnailer\\FFMpegThumbnailer objects only');
         }
     }, $list);
     $this->attaches = \SplFixedArray::fromArray($list, false);
 }
開發者ID:jgrnt,項目名稱:ThumbVideo,代碼行數:9,代碼來源:Batch.php

示例8: slice

 /**
  * @param int|string $start
  * @param int|string $length
  * @return $this
  */
 public function slice($start, $length)
 {
     $end = $this->set->getSize();
     if ($start > $end || $length > $end) {
         throw new \RuntimeException('Invalid start or length');
     }
     $this->set = \SplFixedArray::fromArray(array_slice($this->set->toArray(), $start, $length));
     return $this;
 }
開發者ID:nmarley,項目名稱:bitcoin-php,代碼行數:14,代碼來源:WitnessCollectionMutator.php

示例9: fromArray

 /**
  * Imports a PHP array in a FixedArray instance.
  *
  * This method needs to be reimplemented as SplFixedArray does not return `new static`.
  * @see https://bugs.php.net/bug.php?id=55128
  *
  * Subclasses of FixedArray do not need to reimplement this method.
  *
  * @param array   $array
  * @param boolean $saveIndexes
  *
  * @return FixedArray
  *
  * @throws \InvalidArgumentException If the array contains non-numeric or negative indexes.
  */
 public static function fromArray($array, $saveIndexes = true)
 {
     $splFixedArray = \SplFixedArray::fromArray($array, $saveIndexes);
     $result = new static($splFixedArray->count());
     $source = $saveIndexes ? $array : $splFixedArray;
     foreach ($source as $key => $value) {
         $result[$key] = $value;
     }
     return $result;
 }
開發者ID:brick,項目名稱:brick,代碼行數:25,代碼來源:FixedArray.php

示例10: __construct

 /**
  * 
  * @param PointInterface[] $points
  * @param LineFactoryInterface $lineFactory
  */
 public function __construct(array $points, LineFactoryInterface $lineFactory)
 {
     $items = [];
     for ($i = 0; $i < count($points) - 1;) {
         $items[] = $lineFactory->createLineSegment($points[$i], $points[++$i]);
     }
     // and add last segment
     $items[] = $lineFactory->createLineSegment($points[$i], $points[0]);
     $this->items = \SplFixedArray::fromArray($items);
 }
開發者ID:samizdam,項目名稱:Geometry,代碼行數:15,代碼來源:LineSegmentCollection.php

示例11: testItReceivesAResultWhenBodyFollowsResponse

 public function testItReceivesAResultWhenBodyFollowsResponse()
 {
     $command = $this->createCommandInstance();
     $response = $this->getMockBuilder('Rvdv\\Nntp\\Response\\MultiLineResponse')->disableOriginalConstructor()->getMock();
     $lines = \SplFixedArray::fromArray(['Lorem ipsum dolor sit amet, ', 'consectetur adipiscing elit. ', 'Sed volutpat sit amet leo sit amet sagittis.']);
     $response->expects($this->once())->method('getLines')->will($this->returnValue($lines));
     $command->onBodyFollows($response);
     $result = $command->getResult();
     $this->assertEquals(implode("\r\n", $lines->toArray()), $result);
 }
開發者ID:thebandit,項目名稱:php-nntp,代碼行數:10,代碼來源:BodyCommandTest.php

示例12: testWhenThereIsAFailedReport

 public function testWhenThereIsAFailedReport()
 {
     $report_mock = \Mockery::mock('\\SimpleHealth\\EndpointReport');
     $report_mock->pass = false;
     $report_mock->message = StringLiteral::fromNative('');
     $reports = new Collection(\SplFixedArray::fromArray([$report_mock]));
     $subject = new NodeValidator();
     $report = $subject->isValid($reports);
     $this->assertEquals($report->pass, false);
 }
開發者ID:jshthornton,項目名稱:simplehealth,代碼行數:10,代碼來源:NodeValidatorTest.php

示例13: __construct

 /**
  * This list only accepts an array of integers, or throw an exception with invalid type.
  *
  * @param int[] $ids
  * @throws \InvalidArgumentException
  */
 public function __construct(array $ids)
 {
     foreach ($ids as $key => $id) {
         $type = gettype($id);
         if ('integer' !== $type) {
             throw new \InvalidArgumentException(sprintf('The array of IDs can only contain integers. Item of type %s given at the offset %s', $type, $key));
         }
     }
     $this->list = \SplFixedArray::fromArray($ids, false);
 }
開發者ID:MartialGeek,項目名稱:transmission-api,代碼行數:16,代碼來源:TorrentIdList.php

示例14: __construct

 /**
  * Hand constructor.
  * @param Card[] ...$cards
  */
 public function __construct(Card ...$cards)
 {
     if (count($cards) > 5) {
         throw new \BadMethodCallException('max 5 cards. Found: ' . count($cards));
     }
     usort($cards, function (Card $a, Card $b) {
         $faceValueDifference = $b->getFaceValue() - $a->getFaceValue();
         return $faceValueDifference === 0 ? $b->getSuit()->getSuit() - $a->getSuit()->getSuit() : $faceValueDifference;
     });
     $this->cards = \SplFixedArray::fromArray($cards, false);
 }
開發者ID:ranpafin,項目名稱:phpoker,代碼行數:15,代碼來源:Hand.php

示例15: build

 public function build()
 {
     $endpoints = \SplFixedArray::fromArray($this->endpoints);
     for ($i = 0, $len = count($endpoints); $i < $len; $i++) {
         $endpoints[$i] = Url::fromNative($endpoints[$i]);
     }
     $endpoints = new Collection($endpoints);
     $node_healthcheck_factory = new NodeHealthCheckFactory();
     $node_healthcheck = $node_healthcheck_factory->make($endpoints);
     return new SimpleHealth($endpoints, $node_healthcheck);
 }
開發者ID:jshthornton,項目名稱:simplehealth,代碼行數:11,代碼來源:SimpleHealthBuilder.php


注:本文中的SplFixedArray::fromArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。