Пример #1
0
 /**
  * Removes a component from the IContainer.
  * @return void
  */
 public function removeComponent(IComponent $component)
 {
     $name = $component->getName();
     if (!isset($this->components[$name]) || $this->components[$name] !== $component) {
         throw new Nette\InvalidArgumentException("Component named '{$name}' is not located in this container.");
     }
     unset($this->components[$name]);
     $component->setParent(NULL);
 }
Пример #2
0
 protected function checkRenderOutput(IComponent $control, $expected, array $renderParameters = [])
 {
     if (!$control->getParent()) {
         $this->attachToPresenter($control);
     }
     ob_start();
     $control->render(...$renderParameters);
     if (is_file($expected)) {
         \Tester\Assert::matchFile($expected, ob_get_clean());
     } else {
         \Tester\Assert::match($expected, ob_get_clean());
     }
 }
Пример #3
0
 /**
  * Adds the specified component to the IContainer.
  *
  * @param  IComponent
  * @param  string
  * @param  string
  *
  * @return Container  provides a fluent interface
  * @throws Nette\InvalidStateException
  */
 public function addComponent(IComponent $component, $name, $insertBefore = null)
 {
     if ($name === null) {
         $name = $component->getName();
     }
     if (is_int($name)) {
         $name = (string) $name;
     } elseif (!is_string($name)) {
         throw new Nette\InvalidArgumentException("Component name must be integer or string, " . gettype($name) . " given.");
     } elseif (!preg_match('#^[a-zA-Z0-9_]+$#', $name)) {
         throw new Nette\InvalidArgumentException("Component name must be non-empty alphanumeric string, '{$name}' given.");
     }
     if (isset($this->components[$name])) {
         throw new Nette\InvalidStateException("Component with name '{$name}' already exists.");
     }
     // check circular reference
     $obj = $this;
     do {
         if ($obj === $component) {
             throw new Nette\InvalidStateException("Circular reference detected while adding component '{$name}'.");
         }
         $obj = $obj->getParent();
     } while ($obj !== null);
     // user checking
     $this->validateChildComponent($component);
     try {
         if (isset($this->components[$insertBefore])) {
             $tmp = array();
             foreach ($this->components as $k => $v) {
                 if ($k === $insertBefore) {
                     $tmp[$name] = $component;
                 }
                 $tmp[$k] = $v;
             }
             $this->components = $tmp;
         } else {
             $this->components[$name] = $component;
         }
         $component->setParent($this, $name);
     } catch (\Exception $e) {
         unset($this->components[$name]);
         // undo
         throw $e;
     }
     return $this;
 }
 public function isPersistent(\Nette\ComponentModel\IComponent $object)
 {
     static $persistentParameters = NULL;
     if ($persistentParameters === NULL) {
         $presenter = $object instanceof \Nette\Application\IPresenter ? $object : $object->lookupPath('Nette\\Application\\IPresenter', FALSE);
         if ($presenter) {
             $persistentParameters = $presenter::getPersistentComponents();
         }
     }
     if (is_array($persistentParameters)) {
         return in_array($object->getName(), $persistentParameters);
     }
     return FALSE;
 }