diff --git a/composer.lock b/composer.lock index 78d34e5..bb24035 100644 --- a/composer.lock +++ b/composer.lock @@ -42,16 +42,16 @@ }, { "name": "phpgt/dom", - "version": "v2.0.2", + "version": "v2.0.3", "source": { "type": "git", "url": "https://github.com/PhpGt/Dom.git", - "reference": "3d7070765971e3799615d64cf1cad3c24443bea2" + "reference": "ad48666c58910e266bb381c7ff54fc96718d3a96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/Dom/zipball/3d7070765971e3799615d64cf1cad3c24443bea2", - "reference": "3d7070765971e3799615d64cf1cad3c24443bea2", + "url": "https://api.github.com/repos/PhpGt/Dom/zipball/ad48666c58910e266bb381c7ff54fc96718d3a96", + "reference": "ad48666c58910e266bb381c7ff54fc96718d3a96", "shasum": "" }, "require": { @@ -77,48 +77,48 @@ "authors": [ { "name": "Greg Bowler", + "role": "Developer", "email": "greg.bowler@g105b.com", - "homepage": "https://www.g105b.com", - "role": "Developer" + "homepage": "https://www.g105b.com" }, { "name": "Alvaro Guimaraes", - "homepage": "https://github.com/aguimaraes", - "role": "Developer" + "role": "Developer", + "homepage": "https://github.com/aguimaraes" }, { "name": "James Fellows", - "homepage": "https://github.com/j4m3s", - "role": "Developer" + "role": "Developer", + "homepage": "https://github.com/j4m3s" }, { "name": "Emile Ward", - "homepage": "https://github.com/emileward", - "role": "Developer" + "role": "Developer", + "homepage": "https://github.com/emileward" }, { "name": "Jelmer Wijnja", - "homepage": "https://github.com/Jelmergu", - "role": "Developer" + "role": "Developer", + "homepage": "https://github.com/Jelmergu" }, { "name": "Ognjen Petrovic", - "homepage": "https://github.com/ognjen-petrovic", - "role": "Developer" + "role": "Developer", + "homepage": "https://github.com/ognjen-petrovic" }, { "name": "Jacob Bearden", - "homepage": "https://github.com/jacobbearden", - "role": "Documentation contributor" + "role": "Documentation contributor", + "homepage": "https://github.com/jacobbearden" }, { "name": "Jaroslav Týc", - "homepage": "https://www.jaroslavtyc.com/", - "role": "Developer" + "role": "Developer", + "homepage": "https://www.jaroslavtyc.com/" } ], "description": "The modern DOM API for PHP 7 projects.", - "time": "2019-07-08T15:06:07+00:00" + "time": "2019-07-31T15:30:50+00:00" } ], "packages-dev": [ @@ -545,16 +545,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.6", + "version": "7.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315" + "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d471d0d2b529a67c6a722dd446c4ec90881ac315", - "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", + "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", "shasum": "" }, "require": { @@ -563,7 +563,7 @@ "php": "^7.2", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0.2", + "phpunit/php-token-stream": "^3.1.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", @@ -593,8 +593,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "role": "lead", + "email": "sebastian@phpunit.de" } ], "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", @@ -604,7 +604,7 @@ "testing", "xunit" ], - "time": "2019-07-08T05:29:42+00:00" + "time": "2019-07-25T05:31:54+00:00" }, { "name": "phpunit/php-file-iterator", @@ -748,16 +748,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c" + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c", - "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", "shasum": "" }, "require": { @@ -770,7 +770,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -793,7 +793,7 @@ "keywords": [ "tokenizer" ], - "time": "2019-07-08T05:24:54+00:00" + "time": "2019-07-25T05:29:42+00:00" }, { "name": "phpunit/phpunit", @@ -865,8 +865,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "role": "lead", + "email": "sebastian@phpunit.de" } ], "description": "The PHP Unit Testing framework.", diff --git a/src/Bindable.php b/src/Bindable.php index 9fc6da7..2e474d8 100644 --- a/src/Bindable.php +++ b/src/Bindable.php @@ -319,6 +319,20 @@ protected function setPropertyValue( case "innerText": $element->innerText = $value; break; + + case "value": + $tagName = strtoupper($element->tagName); + switch($tagName) { + case "SELECT": + case "INPUT": + case "TEXTAREA": + $element->value = $value; + break; + default: + $element->setAttribute($bindProperty, $value); + } + break; + default: $element->setAttribute($bindProperty, $value); } diff --git a/src/HTMLDocument.php b/src/HTMLDocument.php index 2c67a51..7e60174 100644 --- a/src/HTMLDocument.php +++ b/src/HTMLDocument.php @@ -17,8 +17,13 @@ * @property-read Element $firstElementChild; * @property-read Element $lastElementChild; * @property-read Element $body; - * @method Node getElementById(string $id) - * @method Element createElement(string $name, string $value = null) + * + * @method Attr createAttribute(string $name) + * @method Comment createComment(string $data) + * @method DocumentFragment createDocumentFragment() + * @method Element createElement(string $name) + * @method Element createTextNode(string $content) + * @method ?Element getElementById(string $id) * */ class HTMLDocument extends BaseHTMLDocument { @@ -197,7 +202,7 @@ public function storeBoundAttribute(BaseAttr $attr) { } public function validateBinds():void { - $allBindableElements = $this->getAllBindableElements(); + $allBindableElements = $this->getAllDomTemplateElements(); foreach($allBindableElements as $element) { foreach($element->attributes as $attr) { @@ -214,24 +219,23 @@ public function validateBinds():void { } } - public function removeBinds():void { - $allBindableElements = $this->getAllBindableElements(); + public function removeTemplateAttributes():void { + $allBindableElements = $this->getAllDomTemplateElements(); foreach($allBindableElements as $element) { foreach($element->attributes as $attr) { /** @var \Gt\Dom\Attr $attr */ - if(strpos($attr->name, "data-bind") !== 0) { - continue; + if(strpos($attr->name, "data-bind") === 0 + || strpos($attr->name, "data-template") === 0) { + $attr->remove(); } - - $attr->remove(); } } } - protected function getAllBindableElements():BaseHTMLCollection { + protected function getAllDomTemplateElements():BaseHTMLCollection { return $this->documentElement->xPath( - "descendant-or-self::*[@*[starts-with(name(), 'data-bind')]]" + "descendant-or-self::*[@*[starts-with(name(), 'data-bind')]]|descendant-or-self::*[@*[starts-with(name(), 'data-template')]]" ); } } \ No newline at end of file diff --git a/test/unit/BindableTest.php b/test/unit/BindableTest.php index 92cf4fe..e4b801a 100644 --- a/test/unit/BindableTest.php +++ b/test/unit/BindableTest.php @@ -173,7 +173,7 @@ public function testBindDataRemoved() { "age" => $age, ]); - $document->removeBinds(); + $document->removeTemplateAttributes(); $boundDataTestElement = $document->querySelector(".bound-data-test"); $spanChildren = $boundDataTestElement->querySelectorAll("span"); diff --git a/test/unit/HTMLDocumentTest.php b/test/unit/HTMLDocumentTest.php index 23b5add..022428b 100644 --- a/test/unit/HTMLDocumentTest.php +++ b/test/unit/HTMLDocumentTest.php @@ -13,5 +13,9 @@ public function testOverriddenClasses() { self::assertInstanceOf(DocumentFragment::class, $fragment); } - + public function testGetElementById() { + $document = new HTMLDocument("