コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getItem($index)
 {
     if (!$this->items->offsetExists($index)) {
         throw new \OutOfBoundsException('The index ' . $index . ' is not set');
     }
     return $this->items[$index];
 }
コード例 #2
0
ファイル: Hand.php プロジェクト: ranpafin/phpoker
 /**
  * @param int $numberOfCardsToKeep
  *
  * @return HandInterface
  */
 public function keep(int $numberOfCardsToKeep) : HandInterface
 {
     if ($this->cards->count() <= $numberOfCardsToKeep) {
         return $this;
     }
     return new self(...array_slice($this->getCards(), 0, $numberOfCardsToKeep));
 }
コード例 #3
0
 /**
  * @param int $offset
  * @return mixed
  */
 public function offsetGet($offset)
 {
     if (!$this->set->offsetExists($offset)) {
         throw new \OutOfRangeException('Nothing found at this offset');
     }
     return $this->set->offsetGet($offset);
 }
コード例 #4
0
ファイル: Util.php プロジェクト: chuyskywalker/phpaes
 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());
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 /**
  * {@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;
 }
コード例 #7
0
 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);
 }
コード例 #8
0
ファイル: Tuple.php プロジェクト: luijar/fp-php
 public function offsetSet($offset, $value)
 {
     if (!$this->isValid($offset, $value)) {
         throw new \RuntimeException();
     }
     return parent::offsetSet($offset, $value);
 }
コード例 #9
0
 /**
  * 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);
 }
コード例 #10
0
ファイル: Batch.php プロジェクト: jgrnt/ThumbVideo
 /**
  * Attach other object to be executed in batch mode (make only one system call e.g. shell>cmd && cmd1 && cmdx)
  * 
  * @param FFMpegThumbnailer $fft
  * @return FFMpegThumbnailer Fluent interface
  */
 public function attach(FFMpegThumbnailer $fft)
 {
     $size = $this->attaches->getSize();
     $this->attaches->setSize(++$size);
     $this->attaches[--$size] = $fft;
     return $this;
 }
コード例 #11
0
 /**
  * {@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;
 }
コード例 #12
0
 /**
  * @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));
 }
コード例 #13
0
ファイル: ReduceTest.php プロジェクト: bahulneel/phonon
 public function testMapTraversable()
 {
     $expected = [1, 2, 3, 4];
     $arr = \SplFixedArray::fromArray($expected);
     $actual = t::into([], t::map(t::value()), $arr);
     $this->assertEquals($expected, $actual);
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 public function offsetSet($index, $newval)
 {
     if (!empty($newval) && false === $newval instanceof Hypothesis) {
         throw new \InvalidArgumentException(sprintf('HypothesesList could only contain Hypothesis, %s given.', get_class($newval)));
     }
     parent::offsetSet($index, $newval);
 }
コード例 #15
0
ファイル: LiquidaJp.php プロジェクト: he--/liquidaJp
 /**
  * @return \SplStack
  */
 public function getNotificacoes()
 {
     $notificacoes = new \SplStack();
     for ($i = 0; $i < $this->listaDeItens->count(); $i++) {
         $notificacoes->push($this->listaDeItens[$i]->notify());
     }
     return $notificacoes;
 }
コード例 #16
0
ファイル: ImmutableVector.php プロジェクト: hoesler/traver
 /**
  * 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));
     }
 }
コード例 #17
0
 /**
  * @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;
 }
コード例 #18
0
 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]];
 }
コード例 #19
0
ファイル: FixedArray.php プロジェクト: brick/brick
 /**
  * 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;
 }
コード例 #20
0
 /**
  * 
  * @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);
 }
コード例 #21
0
 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);
 }
コード例 #22
0
 /**
  * {@inheritdoc}
  */
 public function next()
 {
     if ($this->currentPosition == -1) {
         throw new \LogicException('Cannot fetch an item from empty bag.');
     }
     if ($this->currentPosition == 0) {
         $this->currentPosition = $this->items->getSize() - 1;
         return $this->items[0];
     }
     $maxOffset = $this->currentPosition;
     $randomOffset = (int) ($this->generator->next() * $maxOffset);
     $item = $this->items[$randomOffset];
     if ($randomOffset < $maxOffset) {
         $this->items[$randomOffset] = $this->items[$this->currentPosition];
         $this->items[$this->currentPosition] = $item;
     }
     $this->currentPosition--;
     return $item;
 }
コード例 #23
0
 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);
 }
コード例 #24
0
 /**
  * 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);
 }
コード例 #25
0
 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);
 }
コード例 #26
0
 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();
 }
コード例 #27
0
 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));
 }
コード例 #28
0
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++;
    }
}
コード例 #29
0
ファイル: Csv.php プロジェクト: robertrico/GridFS
 /**
  * @return SplFixedArray
  */
 public function parse($fileId)
 {
     $fileId = new MongoId($fileId);
     $file = $this->Gridfs->readFile('csv', $fileId);
     $Data = str_getcsv($file, "\n", "\"");
     foreach ($Data as &$Row) {
         $Row = str_getcsv($Row, ",");
     }
     //parse the items in rows
     $spl = SplFixedArray::fromArray($Data);
     return $spl;
 }
コード例 #30
0
ファイル: AngleCollection.php プロジェクト: samizdam/Geometry
 /**
  * Note: angle will be construct from given points anticlockwise on Cartesian 2D system!
  * Geometry library, by default, use full positive circle for present angle value: from 0 to 360 degrees.
  * For some cases, angle can be greater than 180, not negative!
  *
  * For example: if points presents as [A, B, C] (middle point is vertex), angle size is 270 deg for this case
  * B>____C
  * |
  * | 270
  * |
  * ^A
  *
  * For create rigth (90) angle you must allow this order:
  *
  * A
  * |
  * | 90
  * |
  * B>_____C
  *
  * Or this:
  *
  *
  *
  *
  * @param PointInterface[] $points
  * @param AngleFactoryInterface $angleFactory
  */
 public function __construct(array $points, AngleFactoryInterface $angleFactory)
 {
     if (count($points) < 3) {
         throw new Exceptions\DomainException("For build set of  Angles need more that 3 points");
     }
     $items = [];
     // and proceed edge cases
     $items[] = $angleFactory->createAngleByPoints($points[1], $points[0], $points[count($points) - 1]);
     for ($i = 0; $i < count($points) - 2; $i++) {
         $items[] = $angleFactory->createAngleByPoints($points[$i + 2], $points[$i + 1], $points[$i]);
     }
     $items[] = $angleFactory->createAngleByPoints($points[0], $points[count($points) - 1], $points[count($points) - 2]);
     $this->items = \SplFixedArray::fromArray($items);
 }