Created
September 22, 2010 10:27
-
-
Save fprochazka/591475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UglyComponentPointer implements \Nette\IComponent, \ArrayAccess | |
{ | |
/** @var \Nette\Component */ | |
private $pointer; | |
private $noesark = array(); | |
public function __construct($pointer = NULL) | |
{ | |
$this->setPointer($pointer); | |
} | |
public function setPointer($pointer) | |
{ | |
$this->pointer = $pointer; | |
} | |
/** | |
* @return string | |
*/ | |
function getName() | |
{ | |
return $this->pointer ? $this->pointer->getName() : NULL; | |
} | |
/** | |
* Returns the container if any. | |
* @return \Nette\IComponentContainer|NULL | |
*/ | |
function getParent() | |
{ | |
return $this->pointer ? $this->pointer->getParent() : NULL; | |
} | |
/** | |
* Sets the parent of this component. | |
* @param \Nette\IComponentContainer | |
* @param string | |
* @return void | |
*/ | |
public function setParent(\Nette\IComponentContainer $parent = NULL, $name = NULL) | |
{ | |
//$this->pointer->setParent($parent, $name); | |
} | |
public function getReflection() | |
{ | |
return $this->pointer->reflection; | |
} | |
public function __call($method, $args) | |
{ | |
return callback($this->pointer, $method)->invokeArgs($args); | |
} | |
public function __get($property) | |
{ | |
if (isset($this->noesark[$property])) { // silence! | |
return $this->noesark[$property]; | |
} | |
return $this->pointer->{$property}; | |
} | |
public function __set($property, $value) | |
{ | |
if (!isset($this->pointer->{$property})) { // silence! | |
$this->noesark[$property] = $value; | |
return; | |
} | |
$this->pointer->{$property} = $value; | |
} | |
public function __isset($property) | |
{ | |
return isset($this->pointer->{$property}); | |
} | |
public function __unset($property) | |
{ | |
unset($this->pointer->{$property}); | |
} | |
public function __clone() | |
{ | |
return $this->pointer; | |
} | |
/********************* interface \ArrayAccess ****************d*g**/ | |
/** | |
* Adds the component to the container. | |
* @param string component name | |
* @param Nette\IComponent | |
* @return void | |
*/ | |
final public function offsetSet($name, $component) | |
{ | |
$this->pointer[$name] = $component; | |
} | |
/** | |
* Returns component specified by name. Throws exception if component doesn't exist. | |
* @param string component name | |
* @return Nette\IComponent | |
* @throws \InvalidArgumentException | |
*/ | |
final public function offsetGet($name) | |
{ | |
return $this->pointer[$name]; | |
} | |
/** | |
* Does component specified by name exists? | |
* @param string component name | |
* @return bool | |
*/ | |
final public function offsetExists($name) | |
{ | |
return isset($this->pointer[$name]); | |
} | |
/** | |
* Removes component from the container. | |
* @param string component name | |
* @return void | |
*/ | |
final public function offsetUnset($name) | |
{ | |
unset($this->pointer[$name]); | |
} | |
} |
hodilo by se něco jako ukazatel na komponentu v jiném místě stromu komponent :)
dneska jsem bastlil tohle a vubec se mi to nelíbí, ale posloužilo to... nachvilku než jsem to udělal líp :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Component delegate?