/**
  * {@inheritdoc}
  */
 public function appendItems(array $items)
 {
     $size = $this->items->getSize();
     $amount = count($items);
     $this->items->setSize($size + $amount);
     for ($i = 0; $i < $amount; $i++) {
         $this->items[$size + $i] = $items[$i];
     }
     $this->setCurrentPosition($this->items->getSize() - 1);
 }
 /**
  * {@inheritdoc}
  */
 public function add($item, $amount = 1)
 {
     if ($amount < 1) {
         throw new \InvalidArgumentException('The amount must be a positive number');
     }
     $size = $this->items->getSize();
     $this->items->setSize($size + $amount);
     for ($i = 0; $i < $amount; $i++) {
         $this->items[$size + $i] = $item;
     }
     $this->currentPosition = $size + $amount - 1;
     return $this;
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * Adds the given Document to the database
  *
  * @param DocumentInterface $document
  */
 public function add($document)
 {
     $this->_assertDataInstancesDatabaseIdentifier($document);
     DocumentUtility::assertDocumentIdentifier($document);
     $currentCount = $this->count();
     if ($this->contains($document)) {
         throw new InvalidDataException(sprintf('Object with GUID %s already exists in the database. Maybe the values of the identifier is not expressive', $document->getGuid()), 1411205350);
     }
     $this->objectData->setSize($currentCount + 1);
     $this->_setObjectDataForIndex($document, $currentCount);
     $this->rawData->setSize($currentCount + 1);
     $this->_setRawDataForIndex($document->getData(), $currentCount);
     $this->_addToIndexAtPosition($document, $currentCount);
     SharedEventEmitter::emit(Event::DATABASE_DOCUMENT_ADDED, array($document));
 }
Example #5
0
 /**
  * Resize the underlying storage, only resize when necessary. When resizing
  * we allocate more than newsize, to avoid resizing each item being added.
  *
  * @param  int $newsize
  * @return void
  */
 private function storageResize($newsize)
 {
     $allocated = $this->items->getSize();
     if ($allocated >= $newsize && $newsize >= $allocated >> 1) {
         $this->size++;
         return;
     }
     $newAllocated = ($newsize >> 3) + ($newsize < 9 ? 3 : 6);
     if ($newAllocated > PHP_INT_MAX - $newsize) {
         throw new \RuntimeException(sprintf('Trying to allocated too big array'));
     } else {
         $newAllocated += $newsize;
     }
     if ($newsize == 0) {
         $newAllocated = 0;
     }
     $this->items->setSize($newAllocated);
     $this->size++;
 }
<?php

$array = new SplFixedArray(5);
$array[0] = 1;
$array[1] = 1;
$array[2] = 1;
$array[3] = 1;
$array[4] = 1;
$array->setSize(2);
var_dump($array);
Example #7
0
[expect php]
[file]
<?php 
// Initialize the array with a fixed length
$array = new SplFixedArray(5);
$array[1] = 2;
$array[4] = "foo";
var_dump($array[0]);
// NULL
var_dump($array[1]);
// int(2)
var_dump($array["4"]);
// string(3) "foo"
// Increase the size of the array to 10
$array->setSize(10);
$array[9] = "asdf";
var_dump($array[false]);
var_dump($array[1.0]);
// Shrink the array to a size of 2
$array->setSize(2);
// The following lines throw a RuntimeException: Index invalid or out of range
try {
    var_dump($array["non-numeric"]);
} catch (RuntimeException $re) {
    echo "RuntimeException: " . $re->getMessage() . "\n";
}
try {
    var_dump($array[-1]);
} catch (RuntimeException $re) {
    echo "RuntimeException: " . $re->getMessage() . "\n";
}
Example #8
0
    var_dump($a[1]);
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    $a[1] = 1;
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(count($a[1]));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($a->getSize());
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    foreach ($a as $v) {
    }
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($a->setSize(10));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
echo "Done\n";
<?php

$array = new SplFixedArray(5);
$array[0] = 1;
$array[1] = 1;
$array[2] = 1;
$array[3] = 1;
$array[4] = 1;
$array->setSize(4);
var_dump($array);
Example #10
0
<?php

/* empty count */
$a = new SplFixedArray();
var_dump(count($a));
var_dump($a->count());
/* negative init value */
try {
    $b = new SplFixedArray(-10);
} catch (Exception $e) {
    var_dump($e->getMessage());
}
/* resize and negative value */
$b = new SplFixedArray();
try {
    $b->setSize(-5);
} catch (Exception $e) {
    var_dump($e->getMessage());
}
/* calling __construct() twice */
$c = new SplFixedArray(0);
var_dump($c->__construct());
/* fromArray() from empty array */
$d = new SplFixedArray();
$d->fromArray(array());
var_dump(count($a));
var_dump($a->count());
var_dump($a);
/* foreach by ref */
$e = new SplFixedArray(10);
$e[0] = 1;
 /**
  * @return \Colada\Collection
  */
 public function build()
 {
     // Shrink array to actual size.
     $this->array->setSize($this->index);
     return $this->createCollection();
 }
Example #12
0
<?php

$ar = new SplFixedArray(1);
echo "size: " . $ar->getSize() . "\n";
$ar->setSize(PHP_INT_SIZE == 8 ? 0x2000000000000001 : 0x40000001);
echo "size: " . $ar->getSize() . "\n";
Example #13
0
try {
    $a[0] = "value1";
} catch (RuntimeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
try {
    var_dump($a["asdf"]);
} catch (RuntimeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
try {
    unset($a[-1]);
} catch (RuntimeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
$a->setSize(10);
$a[0] = "value0";
$a[1] = "value1";
$a[2] = "value2";
$a[3] = "value3";
$ref = "value4";
$ref2 =& $ref;
$a[4] = $ref;
$ref = "value5";
unset($a[1]);
var_dump($a[0], $a[2], $a[3], $a[4]);
// countable
var_dump(count($a), $a->getSize(), count($a) == $a->getSize());
// clonable
$b = clone $a;
$a[0] = "valueNew";
 public function setSize($size)
 {
     return $this->numbers->setSize($size);
 }
 /**
  * Use this to add single URL to sitemap.
  * @param string $url URL
  * @param string $lastModified When it was modified, use ISO 8601
  * @param string $changeFrequency How often search engines should revisit this URL
  * @param string $priority Priority of URL on You site
  * @see http://en.wikipedia.org/wiki/ISO_8601
  * @see http://php.net/manual/en/function.date.php
  * @throws \InvalidArgumentException
  */
 public function addUrl($url, $lastModified = null, $changeFrequency = null, $priority = null)
 {
     if ($url == null) {
         throw new \InvalidArgumentException("URL is mandatory. At least one argument should be given.");
     }
     $urlLength = extension_loaded('mbstring') ? mb_strlen($url) : strlen($url);
     if ($urlLength > 2048) {
         throw new \InvalidArgumentException("URL length can't be bigger than 2048 characters.\n                Note, that precise url length check is guaranteed only using mb_string extension.\n                Make sure Your server allow to use mbstring extension.");
     }
     $tmp = new \SplFixedArray(1);
     $tmp[self::URL_PARAM_LOC] = $url;
     if (isset($lastModified)) {
         $tmp->setSize(2);
         $tmp[self::URL_PARAM_LASTMOD] = $lastModified;
     }
     if (isset($changeFrequency)) {
         $tmp->setSize(3);
         $tmp[self::URL_PARAM_CHANGEFREQ] = $changeFrequency;
     }
     if (isset($priority)) {
         $tmp->setSize(4);
         $tmp[self::URL_PARAM_PRIORITY] = $priority;
     }
     if ($this->urls->getSize() === 0) {
         $this->urls->setSize(1);
     } else {
         if ($this->urls->getSize() === $this->urls->key()) {
             $this->urls->setSize($this->urls->getSize() * 2);
         }
     }
     $this->urls[$this->urls->key()] = $tmp;
     $this->urls->next();
 }
Example #16
0
<?php

$fa = new SplFixedArray(2);
$fa[0] = 'Hello';
$fa[1] = 'World';
$fa->setSize(3);
$fa[2] = '!';
var_dump($fa);
$fa->setSize(2);
var_dump($fa);
var_dump($fa->getSize());
<?php

$fixed_array = new SplFixedArray(2);
$fixed_array->setSize(array());
var_dump($fixed_array);
<?php

$fixed_array = new SplFixedArray(2);
$fixed_array->setSize(null);
var_dump($fixed_array);
 /**
  * Add url to $mUrl
  * @access public
  * @static
  * @param array $pArr
  */
 public static function setUrl($pArr)
 {
     $count = self::$mUrl->getSize();
     self::$mUrl->setSize($count + 1);
     self::$mUrl[$count] = $pArr;
 }
Example #20
0
<?php

$a = new SplFixedArray(100);
$a->setSize(NULL);
print "ok\n";
Example #21
0
<?php

echo "Commit from Mint command line";
$array = new SplFixedArray(5);
echo $array->count();
$array->setSize(10);
echo '<br>' . $array->count();
$array[4] = 'lalala';
$array[1] = 'bababa';
$array->next();
echo '<br>' . $array->current();
echo '<br>' . $array->key();
echo "commit from mint PhpStorm";
<?php

$array = new SplFixedArray(5);
$array[0] = 'a';
$array[1] = 'b';
$array[2] = 'c';
$array[3] = 'd';
$array[4] = 'e';
$array->setSize(3);
print_r($array);
Example #23
0
<?php

$a = new SplFixedArray(0);
$a = new SplFixedArray(3);
$a[0] = 1;
$a->setSize(2);
$a->setSize(3);
$a->setSize(0);
$a = new SplFixedArray(0);
$a->setSize(0);
var_dump($a->getSize());
$a = new SplFixedArray(10);
$a->setSize(10);
var_dump($a->getSize());
$a = new SplFixedArray(1);
$a->setSize(5);
var_dump($a->getSize());
$a = new SplFixedArray(20);
$a->setSize(3);
var_dump($a->getSize());
$a = new SplFixedArray(3);
$a[0] = "test";
$a[1] = array(1, 2, "blah");
$a[2] = 1;
$a[0] = "test";
$a->setSize(0);
var_dump($a->getSize());
print "ok\n";
Example #24
0
 /**
  * Set new size of collection.
  *
  * @param int $size
  */
 public function setSize($size)
 {
     if ($this->getSize() !== $size) {
         $this->changed = true;
         parent::setSize($size);
     }
 }
Example #25
0
File: DB.php Project: xdire/dude
 /**
  * @param string $statement        SQL SELECT query
  * @param array $params            OPTIONAL Params for query
  * @param bool $compressResult     Return SplFixedArray instead of usual array
  * @return array | \SplFixedArray
  * @throws DBException
  */
 public function select($statement, array $params = null, $compressResult = false)
 {
     try {
         $query = $this->dbinstance->prepare($statement);
         $result = $query->execute($params);
         $this->rowsSelected = $query->rowCount();
         if ($result) {
             if (!$compressResult) {
                 return $query->fetchAll(\PDO::FETCH_ASSOC);
             } else {
                 // Default result compressing operation
                 // using incremental raise of array size.
                 // By default it's not will double the
                 // array size, but make incremental grow
                 $return = new \SplFixedArray(2000);
                 $i = 0;
                 $k = 0;
                 while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
                     $return[$k] = $row;
                     $i++;
                     $k++;
                     if ($i > 1999) {
                         $i = 0;
                         $oldIndex = $return->getSize();
                         $return->setSize($oldIndex + 2000);
                     }
                 }
                 $return->setSize($k);
                 return $return;
             }
         } else {
             throw new DBReadException("Data read was failed", 404, $query->errorInfo(), $query->errorCode());
         }
     } catch (\PDOException $e) {
         throw new DBReadException("Data read was failed", 500, $e->getMessage(), $e->getCode());
     }
 }
<?php

$fixed_array = new SplFixedArray(2);
$fixed_array->setSize(3.14159);
var_dump($fixed_array);
<?php

$fixedarr = new SplFixedArray();
echo "Errors:", PHP_EOL;
$fixedarr->setSize([]);
$fixedarr->setSize("notanint");
echo "No Error:", PHP_EOL;
$fixedarr->setSize("5");
$fixedarr->setSize("6.6");
var_dump($fixedarr->getSize() == 6);
$fixedarr->setSize(2.2);
var_dump($fixedarr->getSize() == 2);
$fixedarr->setSize(true);
var_dump($fixedarr->getSize() == 1);
// because php...
$fixedarr->setSize(false);
var_dump($fixedarr->getSize() == 0);
// because php...