• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP SplFixedArray类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: bytestring

 public function bytestring($data)
 {
     $a = new \SplFixedArray(strlen($data));
     for ($i = 0; $i < strlen($data); $i++) {
         $a[$i] = str_pad(ord($data[$i]), 3, ' ', STR_PAD_LEFT);
     }
     return implode(' ', $a->toArray());
 }
开发者ID:chuyskywalker,项目名称:phpaes,代码行数:8,代码来源:Util.php


示例2: values

 /**
  * Returns a Collection of the values.
  *
  * @return Collection
  */
 public function values()
 {
     $count = $this->count()->toNative();
     $valuesArray = new \SplFixedArray($count);
     foreach ($this->items as $key => $item) {
         $valuesArray->offsetSet($key, $item->getValue());
     }
     return new Collection($valuesArray);
 }
开发者ID:embarknow,项目名称:value-objects,代码行数:14,代码来源:Dictionary.php


示例3: sort

 /**
  * {@inheritdoc}
  */
 public function sort(\SplFixedArray $array)
 {
     $length = $array->count();
     for ($i = 1; $i < $length; $i++) {
         $key = $array[$i];
         $j = $i - 1;
         while ($j >= 0 && $array[$j] > $key) {
             $array[$j + 1] = $array[$j];
             $j--;
         }
         $array[$j + 1] = $key;
     }
     return $array;
 }
开发者ID:valdislav,项目名称:SplFixedArray,代码行数:17,代码来源:InsertionSortStrategy.php


示例4: 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


示例5: __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


示例6: sort

 /**
  * {@inheritdoc}
  */
 public function sort(\SplFixedArray $array)
 {
     $length = $array->count();
     for ($i = 0; $i < $length - 1; $i++) {
         $smallest = $i;
         for ($j = $i + 1; $j < $length; $j++) {
             if ($array[$j] < $array[$smallest]) {
                 $smallest = $j;
             }
         }
         $tmp = $array[$i];
         $array[$i] = $array[$smallest];
         $array[$smallest] = $tmp;
     }
     return $array;
 }
开发者ID:valdislav,项目名称:SplFixedArray,代码行数:19,代码来源:SelectionSortStrategy.php


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: __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


示例14: 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


示例15: 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


示例16: insert

 /**
  * insert
  *
  * @param array/string $data
  * @access public
  * @return void
  */
 public function insert($data)
 {
     if (is_array($data)) {
         $data = \SplFixedArray::fromArray($data);
     }
     if (!$data instanceof \Iterator) {
         $data = \SplFixedArray::fromArray([$data]);
     }
     $transformedList = $this->transformer->transform($data);
     return $this->writer->insert($transformedList);
 }
开发者ID:Rbn3D,项目名称:SimstringBundle,代码行数:18,代码来源:SimstringTransformerWriter.php


示例17: 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


示例18: testCacheGet

 public function testCacheGet()
 {
     $curlFactoryMock = new \mock\M6Web\Bundle\GuzzleHttpBundle\Handler\CurlFactory(3);
     $cacheMock = new \mock\M6Web\Bundle\GuzzleHttpBundle\Cache\CacheInterface();
     $cacheMock->getMockController()->has = true;
     $cacheMock->getMockController()->get = $this->getSerializedResponse(new Response(200, [], "The answer is 42", '1.1', 'OK'));
     $cacheMock->getMockController()->ttl = 256;
     $this->if($testedClass = new TestedClass(['handle_factory' => $curlFactoryMock]))->and($testedClass->setCache($cacheMock, 500, false))->and($testedClass->setDebug(true))->and($request = new Request('GET', 'http://httpbin.org'))->then->object($response = $testedClass($request, [])->wait())->isInstanceOf('GuzzleHttp\\Psr7\\Response')->integer($response->getStatuscode())->isEqualTo(200)->string($response->getReasonPhrase())->isEqualTo('OK')->string($response->getBody()->__toString())->isEqualTo('The answer is 42')->boolean($response->cached)->isTrue()->integer($response->cacheTtl)->isEqualTo(256)->mock($cacheMock)->call('get')->withArguments(md5($request->getMethod() . $request->getUri()))->once()->call('ttl')->withArguments(md5($request->getMethod() . $request->getUri()))->once()->mock($curlFactoryMock)->call('release')->never();
     // Test unserialize issue
     $cacheMock->getMockController()->get = serialize(\SplFixedArray::fromArray([null, null, null, null, null]));
     $this->object($response = $testedClass($request, [])->wait())->isInstanceOf('GuzzleHttp\\Psr7\\Response')->integer($response->getStatuscode())->isEqualTo(200)->boolean(isset($response->cached) ? $response->cached : false)->isFalse()->mock($cacheMock)->call('get')->withArguments(md5($request->getMethod() . $request->getUri()))->twice()->call('ttl')->withArguments(md5($request->getMethod() . $request->getUri()))->once()->mock($curlFactoryMock)->call('release')->once();
 }
开发者ID:AlliterativeAnimals,项目名称:GuzzleHttpBundle,代码行数:12,代码来源:CurlMultiHandler.php


示例19: testSameValueAs

 public function testSameValueAs()
 {
     $array = \SplFixedArray::fromArray(array(new StringLiteral('one'), new StringLiteral('two'), new Integer(3)));
     $collection2 = new Collection($array);
     $array = \SplFixedArray::fromArray(array('one', 'two', array(1, 2)));
     $collection3 = Collection::fromNative($array);
     $this->assertTrue($this->collection->sameValueAs($collection2));
     $this->assertTrue($collection2->sameValueAs($this->collection));
     $this->assertFalse($this->collection->sameValueAs($collection3));
     $mock = $this->getMock('EmbarkNow\\ValueObjects\\ValueObjectInterface');
     $this->assertFalse($this->collection->sameValueAs($mock));
 }
开发者ID:embarknow,项目名称:value-objects,代码行数:12,代码来源:CollectionTest.php


示例20: selectionsort

function selectionsort(SplFixedArray $arr)
{
    $sIndex = 0;
    $smallestIndex = 0;
    $tmp = null;
    $count = $arr->count();
    while ($sIndex < $count) {
        $smallestIndex = $sIndex;
        for ($i = $sIndex; $i < $count; $i++) {
            if ($arr[$i] < $arr[$smallestIndex]) {
                $smallestIndex = $i;
            }
        }
        if ($sIndex < $smallestIndex) {
            $tmp = $arr[$smallestIndex];
            $arr[$smallestIndex] = $arr[$sIndex];
            $arr[$sIndex] = $tmp;
        }
        $sIndex++;
    }
}
开发者ID:bylexus,项目名称:selsort-bench,代码行数:21,代码来源:selectionsort_fixedarray.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP SplObjectStorage类代码示例发布时间:2022-05-23
下一篇:
PHP SplFileObject类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap