-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d8093a
Showing
31 changed files
with
3,553 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: 2 | ||
|
||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/php:5.6 | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "composer.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: composer install --no-interaction | ||
|
||
- save_cache: | ||
paths: | ||
- vendor | ||
key: v1-dependencies-{{ checksum "composer.json" }} | ||
|
||
- run: vendor/bin/phpunit test/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor/ | ||
composer.lock | ||
/.idea/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Villermen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "villermen/feed-processing", | ||
"description": "Library for processing feeds in an efficient streaming way.", | ||
"type": "library", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=5.6", | ||
"villermen/data-handling": "^1.9" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Villermen\\FeedProcessing\\": "src/" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace Villermen\FeedProcessing; | ||
|
||
/** | ||
* Because face it, the one PHP provides is just nasty. | ||
*/ | ||
class ActuallySimpleXmlElement implements \ArrayAccess | ||
{ | ||
public $tagName; | ||
public $attributes = []; | ||
public $text = ""; | ||
|
||
/** @var ActuallySimpleXmlElement[] */ | ||
public $children = []; | ||
|
||
/** | ||
* @param \DOMNode $node | ||
* @return ActuallySimpleXmlElement | ||
*/ | ||
public static function fromDomNode(\DOMNode $node) | ||
{ | ||
$element = new ActuallySimpleXmlElement(); | ||
|
||
$element->tagName = $node->nodeName; | ||
|
||
/** @var \DOMAttr $attribute */ | ||
foreach ($node->attributes as $attribute) { | ||
$element->attributes[$attribute->name] = $attribute->value; | ||
} | ||
|
||
/** @var \DOMNode $childNode */ | ||
foreach ($node->childNodes as $childNode) { | ||
switch ($childNode->nodeType) { | ||
case XML_ELEMENT_NODE: | ||
$element->children[] = self::fromDomNode($childNode); | ||
break; | ||
|
||
case XML_TEXT_NODE: | ||
$element->text = trim($childNode->textContent); | ||
break; | ||
|
||
case XML_CDATA_SECTION_NODE: | ||
$element->text = $childNode->textContent; | ||
break; | ||
} | ||
} | ||
|
||
return $element; | ||
} | ||
|
||
/** | ||
* @param string $tagName | ||
* @return ActuallySimpleXmlElement[] | ||
*/ | ||
public function get($tagName) | ||
{ | ||
return array_filter($this->children, function($child) use ($tagName) { | ||
/** @var ActuallySimpleXmlElement $child */ | ||
return $child->tagName === $tagName; | ||
}); | ||
} | ||
|
||
/** | ||
* @param string $offset | ||
* @return bool | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
return count($this->get($offset)) > 0; | ||
} | ||
|
||
/** | ||
* @param string $offset | ||
* @return ActuallySimpleXmlElement The first matched child. | ||
* @throws \Exception When no direct children with the given tag name exist. | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
$matchedChildren = $this->get($offset); | ||
|
||
if (count($matchedChildren) === 0) { | ||
throw new \Exception("No direct children with tag name \"{$offset}\" exist."); | ||
} | ||
|
||
return current($matchedChildren); | ||
} | ||
|
||
public function offsetSet($offset, $value) | ||
{ | ||
throw new \Exception("Invalid operation."); | ||
} | ||
|
||
public function offsetUnset($offset) | ||
{ | ||
throw new \Exception("Invalid operation."); | ||
} | ||
} |
Oops, something went wrong.