本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
}
示例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]];
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}