当前位置: 首页>>代码示例>>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;未经允许,请勿转载。