作者:Robert-Xi
项目:php-framework-benchmar
/**
* Make a deep clone of a fieldset
*
* @return void
*/
public function __clone()
{
$items = $this->iterator->toArray(PriorityQueue::EXTR_BOTH);
$this->byName = array();
$this->elements = array();
$this->fieldsets = array();
$this->iterator = new PriorityQueue();
foreach ($items as $item) {
$elementOrFieldset = clone $item['data'];
$name = $elementOrFieldset->getName();
$this->iterator->insert($elementOrFieldset, $item['priority']);
$this->byName[$name] = $elementOrFieldset;
if ($elementOrFieldset instanceof FieldsetInterface) {
$this->fieldsets[$name] = $elementOrFieldset;
} elseif ($elementOrFieldset instanceof ElementInterface) {
$this->elements[$name] = $elementOrFieldset;
}
}
// Also make a deep copy of the object in case it's used within a collection
if (is_object($this->object)) {
$this->object = clone $this->object;
}
}
作者:lafaiDe
项目:suive_co
/**
* Adds a collector.
*
* @param Collector\CollectorInterface $collector
* @return self
* @throws Exception\CollectorException
*/
public function addCollector($collector)
{
if (!isset($this->collectors)) {
$this->collectors = new PriorityQueue();
}
if ($collector instanceof Collector\CollectorInterface) {
$this->collectors->insert($collector, $collector->getPriority());
} else {
$error = sprintf('%s must implement CollectorInterface.', get_class($collector));
if ($this->strict === true) {
throw new Exception\CollectorException($error);
}
$this->report->addError($error);
}
return $this;
}
作者:navassouz
项目:zf
/**
* Make a deep clone of a fieldset
*
* @return void
*/
public function __clone()
{
$this->iterator = new PriorityQueue();
foreach ($this->byName as $key => $value) {
$value = clone $value;
$this->byName[$key] = $value;
$this->iterator->insert($value);
if ($value instanceof FieldsetInterface) {
$this->fieldsets[$key] = $value;
} elseif ($value instanceof ElementInterface) {
$this->elements[$key] = $value;
}
}
// Also make a deep copy of the object in case it's used within a collection
if (is_object($this->object)) {
$this->object = clone $this->object;
}
}
作者:MadCat3
项目:zend-validato
/**
* Get all the validators
*
* @return array
*/
public function getValidators()
{
return $this->validators->toArray(PriorityQueue::EXTR_DATA);
}
作者:ranxin102
项目:zf
/**
* Create the priority queue
*
* @return void
*/
protected function createPriorityQueue()
{
$queue = new PriorityQueue();
foreach ($this->prioritizedValues as $data) {
// Do not include priority 0 in list
if ($data['priority'] == 0) {
continue;
}
// Hack to ensure priorities are correct; was not treating
// fractional values correctly
$queue->insert($data['media_type'], (double) $data['priority'] * 10);
}
$this->priorityQueue = $queue;
}
作者:sporkcod
项目:sporktool
protected function renderEvent($name, EventManagerInterface $eventManager, $profile)
{
$listeners = new PriorityQueue();
foreach ($eventManager->getListeners($name) as $listener) {
$info = $this->getListenerInfo($listener);
$listeners->insert($info, $info['priority']);
}
$sharedEvents = $eventManager->getSharedManager();
foreach ($eventManager->getIdentifiers() as $identifier) {
$sharedListeners = $sharedEvents->getListeners($identifier, $name);
if ($sharedListeners) {
foreach ($sharedListeners as $sharedListener) {
$info = $this->getListenerInfo($sharedListener, $identifier);
$listeners->insert($info, $info['priority']);
}
}
}
$html = '';
foreach ($listeners as $listener) {
$html .= $this->renderListener($listener, $eventManager, $profile);
}
$html = <<<HDOC
<li><span class="name">{$this->escape($name)}</span>
<ol class="listeners">{$html}</ol></li>
HDOC;
return $html;
}
作者:razvansividr
项目:pnlzf2-
public function testCloningAlsoClonesQueue()
{
$foo = new \stdClass();
$foo->name = 'bar';
$queue = new PriorityQueue();
$queue->insert($foo, 1);
$queue->insert($foo, 2);
$queueClone = clone $queue;
while (!$queue->isEmpty()) {
$this->assertSame($foo, $queue->top());
$queue->remove($queue->top());
}
$this->assertTrue($queue->isEmpty());
$this->assertFalse($queueClone->isEmpty());
$this->assertEquals(2, $queueClone->count());
while (!$queueClone->isEmpty()) {
$this->assertSame($foo, $queueClone->top());
$queueClone->remove($queueClone->top());
}
$this->assertTrue($queueClone->isEmpty());
}
作者:Flesh19
项目:magent
/**
* Add listeners to the master queue of listeners
*
* Used to inject shared listeners and wildcard listeners.
*
* @param PriorityQueue $masterListeners
* @param array|Traversable $listeners
* @return void
*/
protected function insertListeners($masterListeners, $listeners)
{
foreach ($listeners as $listener) {
$priority = $listener->getMetadatum('priority');
if (null === $priority) {
$priority = 1;
} elseif (is_array($priority)) {
// If we have an array, likely using PriorityQueue. Grab first
// element of the array, as that's the actual priority.
$priority = array_shift($priority);
}
$masterListeners->insert($listener, $priority);
}
}
作者:ReissClothin
项目:Syliu
/**
* {@inheritdoc}
*/
public function handle($code)
{
if ($this->handlers->isEmpty()) {
throw new HandleException(self::class, 'There are no handlers defined.');
}
foreach ($this->handlers as $handler) {
$handler->handle($code);
}
}
作者:soka
项目:AssetManage
/**
* {@inheritDoc}
*/
public function addPath($path)
{
if (is_string($path)) {
$this->paths->insert($this->normalizePath($path), 1);
return;
}
if (!is_array($path) && !$path instanceof ArrayAccess) {
throw new Exception\InvalidArgumentException(sprintf('Provided path must be an array or an instance of ArrayAccess, %s given', is_object($path) ? get_class($path) : gettype($path)));
}
if (isset($path['priority']) && isset($path['path'])) {
$this->paths->insert($this->normalizePath($path['path']), $path['priority']);
return;
}
throw new Exception\InvalidArgumentException('Provided array must contain both keys "priority" and "path"');
}
作者:royaltyclubv
项目:BuzzyGal
/**
* Attach a filter to the chain
*
* @param callable|FilterInterface $callback A Filter implementation or valid PHP callback
* @param int $priority Priority at which to enqueue filter; defaults to 1000 (higher executes earlier)
* @throws Exception\InvalidArgumentException
* @return FilterChain
*/
public function attach($callback, $priority = self::DEFAULT_PRIORITY)
{
if (!is_callable($callback)) {
if (!$callback instanceof FilterInterface) {
throw new Exception\InvalidArgumentException(sprintf('Expected a valid PHP callback; received "%s"', is_object($callback) ? get_class($callback) : gettype($callback)));
}
$callback = array($callback, 'filter');
}
$this->filters->insert($callback, $priority);
return $this;
}
作者:mrubiosa
项目:asse
/**
* Add a JS
* @param string $path
* @param int (optional) $priority
* @return self
*/
public function addJS($path, $priority = self::DEFAULT_ASSET_PRIORITY, $attributes = null)
{
$path = $this->calculateUrl($path, $this->jsPath);
$tagAttributes = array();
$tagAttributes['src'] = $path . '?v=' . $this->jsVersion;
$tagAttributes['type'] = 'text/javascript';
if (isset($attributes) && is_array($attributes)) {
$tagAttributes = array_merge($tagAttributes, $attributes);
}
$tag = new Tag('script', $tagAttributes);
$this->jsQueue->insert($tag, $priority);
return $this;
}
作者:ranjithinnergy
项目:ZeThem
/**
* Get a theme configuration file
* @param string $theme
* @return array | null
*/
public function getThemeConfig($theme)
{
$theme = $this->cleanThemeName($theme);
$path_iterator = $this->themePaths->getIterator();
$config = null;
$n = $path_iterator->count();
while (!$config && $n-- > 0) {
$path = $path_iterator->extract();
if (file_exists($path . $theme . '/config.php')) {
$config = (include $path . $theme . '/config.php');
}
}
return $config;
}
作者:bb-drumme
项目:ZeThem
/**
* Get a theme configuration file
* @param string $theme
* @return array | null
*/
public function getThemeConfig($theme)
{
$theme = $this->cleanThemeName($theme);
$path_iterator = $this->themePaths->getIterator();
$config = null;
$n = $path_iterator->count();
while (!$config && $n-- > 0) {
$path = $path_iterator->extract();
$appConfig = $this->serviceManager->get('Configuration');
if ($appConfig['ze_theme']['custom_theme_path'] === true) {
$configFile = str_replace('{theme}', $theme, $path) . '/config.php';
} else {
$configFile = $path . $theme . '/config.php';
}
if (file_exists($configFile)) {
$config = (include $configFile);
}
}
return $config;
}
作者:ReissClothin
项目:Syliu
/**
* @param CartContextInterface $cartContext
* @param int $priority
*/
public function addContext(CartContextInterface $cartContext, $priority = 0)
{
$this->cartContexts->insert($cartContext, $priority);
}
作者:slkxmai
项目:Ap
/**
* @return int
*/
public function count()
{
return $this->iterator->count();
}
作者:CPD
项目:Sistema-de-controle-cpd
/**
* Attach a resolver
*
* @param ResolverInterface $resolver
* @param int $priority
* @return self
*/
public function attach(ResolverInterface $resolver, $priority = 1)
{
$this->queue->insert($resolver, $priority);
}
作者:outeredg
项目:edge-zf
/**
* Add a converter
*
* @param ConverterInterface $converter
* @param int $priority
*/
public function addConverter(ConverterInterface $converter, $priority = 1)
{
$this->converters->insert($converter, $priority);
return $this;
}
作者:eltondia
项目:Relogi
/**
* Attach a resolver
*
* @param Resolver $resolver
* @param int $priority
* @return AggregateResolver
*/
public function attach(Resolver $resolver, $priority = 1)
{
$this->queue->insert($resolver, $priority);
return $this;
}
作者:rpg60
项目:Syliu
/**
* {@inheritdoc}
*/
public function has($service)
{
$this->assertServiceHaveType($service);
return $this->services->contains($service);
}