for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDraw for the canonical source repository
* @copyright Copyright (c) 2015-2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <[email protected]>
* @license BSD-3-Clause
*/
namespace WebinoDraw\Dom;
use WebinoDraw\Exception;
* Class NodeTrait
trait NodeTrait
{
* @var callable[]
private $onReplace = [];
* @param callable $callback
* @return $this
public function setOnReplace(callable $callback)
$this->onReplace[] = $callback;
return $this;
}
* @return Document|null
public function getOwnerDocument()
return isset($this->ownerDocument) ? $this->ownerDocument : null;
ownerDocument
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
* @return Element|null
public function getParentNode()
return isset($this->parentNode) ? $this->parentNode : null;
parentNode
* @param string $html
* @return NodeInterface
* @throws Exception\LogicException
public function replaceWith($html)
$frag = $this->getOwnerDocument()->createDocumentFragment();
$frag->appendXml($html);
$parentNode = $this->getParentNode();
$newNode = $parentNode->insertBefore($frag, $this);
if (!empty($this->onReplace)) {
foreach ($this->onReplace as $onReplace) {
call_user_func($onReplace, $newNode, $this, $frag);
$parentNode->removeChild($this);
return $newNode;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: