Skip to content

Commit

Permalink
Started parser result refinementt
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Mar 12, 2017
1 parent 5e546db commit a2e7326
Show file tree
Hide file tree
Showing 11 changed files with 460 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/Micrometa/Application/Factory/ItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

use Jkphl\Micrometa\Application\Exceptions\InvalidArgumentException;
use Jkphl\Micrometa\Application\Item\Item;
use Jkphl\Micrometa\Application\Item\ItemInterface;
use Jkphl\Micrometa\Application\Value\AlternateValues;
use Jkphl\Micrometa\Application\Value\StringValue;
use Jkphl\Micrometa\Domain\Value\ValueInterface;
Expand Down Expand Up @@ -88,7 +89,7 @@ protected function processPropertyValue($propertyValue)
* Create an item instance
*
* @param \stdClass $item Raw item
* @return Item Item instance
* @return ItemInterface Item instance
*/
public function __invoke(\stdClass $item)
{
Expand Down
70 changes: 70 additions & 0 deletions src/Micrometa/Infrastructure/Factory/AlternateFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* micrometa
*
* @category Jkphl
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Infrastructure
* @author Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @copyright Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*/

/***********************************************************************************
* The MIT License (MIT)
*
* Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
*
* 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.
***********************************************************************************/

namespace Jkphl\Micrometa\Infrastructure\Factory;

use Jkphl\Micrometa\Ports\Rel\Alternate;

/**
* Alternate resource factory
*
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Infrastructure
*/
class AlternateFactory
{
/**
* Create alternate resource declaration from parser results
*
* @param array[] $rels Parser results
* @return Alternate[] Alternate resource declarations
*/
public static function createFromParserResult(array $alternates)
{
return array_map([static::class, 'createAlternate'], $alternates);
}

/**
* Create an alternate resource declaration
*
* @param array $alternate Alternate resource values
* @return Alternate Alternate resource
*/
protected function createRel($alternate)
{
return new Alternate($alternate['value'], $alternate['type'], $alternate['title']);
}
}
64 changes: 64 additions & 0 deletions src/Micrometa/Infrastructure/Factory/ItemFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* micrometa
*
* @category Jkphl
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Infrastructure
* @author Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @copyright Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*/

/***********************************************************************************
* The MIT License (MIT)
*
* Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
*
* 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.
***********************************************************************************/

namespace Jkphl\Micrometa\Infrastructure\Factory;

use Jkphl\Micrometa\Application\Item\ItemInterface as ApplicationItemInterface;
use Jkphl\Micrometa\Ports\Item\ItemInterface;

/**
* Item factory
*
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Infrastructure
*/
class ItemFactory
{
/**
* Create items from parser results
*
* @param ApplicationItemInterface[] $items Items
* @return ItemInterface[] Items
*/
public static function createFromParserResult(array $items)
{
return array_map([static::class, 'createItem'], $items);
}

public static function createItem(ApplicationItemInterface $item) {

}
}
81 changes: 81 additions & 0 deletions src/Micrometa/Infrastructure/Factory/RelFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* micrometa
*
* @category Jkphl
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Infrastructure
* @author Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @copyright Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*/

/***********************************************************************************
* The MIT License (MIT)
*
* Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
*
* 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.
***********************************************************************************/

namespace Jkphl\Micrometa\Infrastructure\Factory;

use Jkphl\Micrometa\Ports\Rel\Rel;

/**
* Rel declaration factory
*
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Infrastructure
*/
class RelFactory
{
/**
* Create rel declaration from parser results
*
* @param array[] $rels Parser results
* @return array[] Rel declaration
*/
public static function createFromParserResult(array $rels)
{
return array_map([static::class, 'createRelType'], $rels);
}

/**
* Create rel declarations of a particular type
*
* @param array $relType Rel type values
* @return Rel[] Rel declarations
*/
protected static function createRelType(array $relType)
{
return array_map([static::class, 'createRel'], $relType);
}

/**
* Create a rel declaration
*
* @param string $relValue Rel declaration value
* @return Rel Rel declaration
*/
protected function createRel($relValue)
{
return new Rel($relValue);
}
}
83 changes: 83 additions & 0 deletions src/Micrometa/Ports/Exceptions/OutOfBoundsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/**
* micrometa
*
* @category Jkphl
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Ports
* @author Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @copyright Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*/

/***********************************************************************************
* The MIT License (MIT)
*
* Copyright © 2017 Joschi Kuphal <joschi@kuphal.net> / @jkphl
*
* 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.
***********************************************************************************/

namespace Jkphl\Micrometa\Ports\Exceptions;

/**
* Out of bounds exception
*
* @package Jkphl\Micrometa
* @subpackage Jkphl\Micrometa\Ports
*/
class OutOfBoundsException extends \OutOfBoundsException implements MicrometaExceptionInterface
{
/**
* Invalid rel tyle
*
* @var string
*/
const INVALID_REL_TYPE_STR = 'Rel type "%s" is out of bounds';
/**
* Invalid rel type
*
* @var int
*/
const INVALID_REL_TYPE = 1489269267;
/**
* Invalid rel type index
*
* @var string
*/
const INVALID_REL_INDEX_STR = 'Index "%s" for rel type "%s" is out of bounds';
/**
* Invalid rel type index
*
* @var int
*/
const INVALID_REL_INDEX = 1489268571;
/**
* Invalid alternate type
*
* @var string
*/
const INVALID_ALTERNATE_TYPE_STR = 'Alternate type "%s" is out of bounds';
/**
* Invalid alternate type
*
* @var int
*/
const INVALID_ALTERNATE_TYPE = 1489268753;
}

0 comments on commit a2e7326

Please sign in to comment.