This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'weierophinney/feature/view-layer'
- Loading branch information
39 parents
9d05e5f
+
547433c
+
0c9ce04
+
a76e26a
+
2914396
+
7ca3746
+
f1b292d
+
406112f
+
5a9edd3
+
f65c9f6
+
c54156c
+
5e55e82
+
352e42b
+
fa459f5
+
3eff137
+
3648ab6
+
4096125
+
0037391
+
9bdfcd9
+
6cd1498
+
ecac99d
+
199ed75
+
b8507f7
+
ef400bd
+
decb6ae
+
860b39d
+
243eca6
+
d56af72
+
1aaf7f9
+
26b27a9
+
40cd50e
+
986898b
+
d2780b7
+
49abb1d
+
cb5a738
+
21d3bef
+
4748875
+
3331086
+
b0773cc
commit 1d15f7c
Showing
2 changed files
with
185 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,40 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Feed | ||
* @subpackage Writer | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Feed\Writer\Exception; | ||
|
||
use Zend\Feed\Writer\Exception; | ||
|
||
/** | ||
* Feed exceptions | ||
* | ||
* Class to represent exceptions that occur during Feed operations. | ||
* | ||
* @category Zend | ||
* @package Zend_Feed | ||
* @subpackage Writer | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
class InvalidArgumentException | ||
extends \InvalidArgumentException | ||
implements Exception | ||
{} |
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,145 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Feed | ||
* @subpackage Writer | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\Feed\Writer; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Feed | ||
* @subpackage Writer | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
abstract class FeedFactory | ||
{ | ||
/** | ||
* Create and return a Feed basd on data provided. | ||
* | ||
* @param array|Traversable $data | ||
* @return Feed | ||
*/ | ||
public static function factory($data) | ||
{ | ||
if (!is_array($data) && !$data instanceof Traversable) { | ||
throw Exception\InvalidArgumentException(sprintf( | ||
'%s expects an array or Traversable argument; received "%s"', | ||
__METHOD__, | ||
(is_object($data) ? get_class($data) : gettype($data)) | ||
)); | ||
} | ||
|
||
$feed = new Feed(); | ||
|
||
foreach ($data as $key => $value) { | ||
// Setters | ||
$key = static::convertKey($key); | ||
$method = 'set' . $key; | ||
if (method_exists($feed, $method)) { | ||
switch ($method) { | ||
case 'setfeedlink': | ||
if (!is_array($value)) { | ||
// Need an array | ||
break; | ||
} | ||
if (!array_key_exists('link', $value) || !array_key_exists('type', $value)) { | ||
// Need both keys to set this correctly | ||
break; | ||
} | ||
$feed->setFeedLink($value['link'], $value['type']); | ||
break; | ||
default: | ||
$feed->$method($value); | ||
break; | ||
} | ||
continue; | ||
} | ||
|
||
// Entries | ||
if ('entries' == $key) { | ||
static::createEntries($value, $feed); | ||
continue; | ||
} | ||
} | ||
|
||
return $feed; | ||
} | ||
|
||
/** | ||
* Normalize a key | ||
* | ||
* @param string $key | ||
* @return void | ||
*/ | ||
protected static function convertKey($key) | ||
{ | ||
$key = str_replace('_', '', strtolower($key)); | ||
return $key; | ||
} | ||
|
||
/** | ||
* Create and attach entries to a feed | ||
* | ||
* @param array|Traversable $entries | ||
* @param Feed $feed | ||
* @return void | ||
*/ | ||
protected static function createEntries($entries, Feed $feed) | ||
{ | ||
if (!is_array($entries) && !$entries instanceof Traversable) { | ||
throw new Exception\InvalidArgumentException(sprintf( | ||
'%s::factory expects the "entries" value to be an array or Traversable; received "%s"', | ||
get_called_class(), | ||
(is_object($entries) ? get_class($entries) : gettype($entries)) | ||
)); | ||
} | ||
|
||
foreach ($entries as $data) { | ||
if (!is_array($data) && !$data instanceof Traversable && !$data instanceof Entry) { | ||
throw Exception\InvalidArgumentException(sprintf( | ||
'%s expects an array, Traversable, or Zend\Feed\Writer\Entry argument; received "%s"', | ||
__METHOD__, | ||
(is_object($data) ? get_class($data) : gettype($data)) | ||
)); | ||
} | ||
|
||
// Use case 1: Entry item | ||
if ($data instanceof Entry) { | ||
$feed->addEntry($data); | ||
continue; | ||
} | ||
|
||
// Use case 2: iterate item and populate entry | ||
$entry = $feed->createEntry(); | ||
foreach ($data as $key => $value) { | ||
$key = static::convertKey($key); | ||
$method = 'set' . $key; | ||
if (!method_exists($entry, $method)) { | ||
continue; | ||
} | ||
$entry->$method($value); | ||
} | ||
$feed->addEntry($entry); | ||
} | ||
} | ||
} |