当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFixedArray::setSize方法代码示例

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


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

示例1: appendItems

 /**
  * {@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);
 }
开发者ID:battlerattle,项目名称:shuffle-bag,代码行数:13,代码来源:ArrayStorage.php

示例2: add

 /**
  * {@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;
 }
开发者ID:battlerattle,项目名称:shuffle-bag,代码行数:16,代码来源:ArrayShuffleBag.php

示例3: attach

 /**
  * 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;
 }
开发者ID:jgrnt,项目名称:ThumbVideo,代码行数:13,代码来源:Batch.php

示例4: add

 /**
  * 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));
 }
开发者ID:marviktintor,项目名称:pos-1,代码行数:20,代码来源:Database.php

示例5: storageResize

 /**
  * 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++;
 }
开发者ID:syaiful6,项目名称:headbanger,代码行数:26,代码来源:ArrayList.php

示例6: SplFixedArray

<?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);
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:SplFixedArray_setSize_filled_to_smaller.php

示例7: SplFixedArray

[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";
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:31,代码来源:SplFixedArray1.php

示例8: catch

    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";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:fixedarray_015.php

示例9: SplFixedArray

<?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);
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:SplFixedArray_setsize_shrink.php

示例10: SplFixedArray

<?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;
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:fixedarray_021.php

示例11: build

 /**
  * @return \Colada\Collection
  */
 public function build()
 {
     // Shrink array to actual size.
     $this->array->setSize($this->index);
     return $this->createCollection();
 }
开发者ID:alexeyshockov,项目名称:colada,代码行数:9,代码来源:CollectionBuilder.php

示例12: SplFixedArray

<?php

$ar = new SplFixedArray(1);
echo "size: " . $ar->getSize() . "\n";
$ar->setSize(PHP_INT_SIZE == 8 ? 0x2000000000000001 : 0x40000001);
echo "size: " . $ar->getSize() . "\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:6,代码来源:bug67247.php

示例13: catch

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";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:fixedarray_001.php

示例14: setSize

 public function setSize($size)
 {
     return $this->numbers->setSize($size);
 }
开发者ID:dpaduch,项目名称:BasketWithBalls,代码行数:4,代码来源:CustomBallsProvider.php

示例15: addUrl

 /**
  * 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();
 }
开发者ID:icamys,项目名称:php-sitemap-generator,代码行数:43,代码来源:SitemapGenerator.php


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