2016-08-20 23:02:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Shikiryu\LBCReposter;
|
|
|
|
|
|
|
|
class Deals extends \ArrayObject
|
|
|
|
{
|
|
|
|
protected $account;
|
|
|
|
|
|
|
|
private function parseArray(array $array = [])
|
|
|
|
{
|
|
|
|
if (count($array) == 1) {
|
|
|
|
return Deal::fromURL($this->account, current(array_values($array)));
|
|
|
|
}
|
|
|
|
$deal = new Deal();
|
|
|
|
foreach ($array as $name => $value) {
|
|
|
|
$method = sprintf('set%s', ucfirst($name));
|
|
|
|
$deal->$method($value);
|
|
|
|
}
|
|
|
|
return $deal;
|
|
|
|
}
|
|
|
|
|
2016-08-24 23:37:29 +02:00
|
|
|
/**
|
|
|
|
* Deals constructor.
|
|
|
|
*
|
|
|
|
* @param Account $account
|
|
|
|
* @param array|Deal $input
|
|
|
|
*/
|
2016-08-20 23:02:05 +02:00
|
|
|
public function __construct(Account $account, $input)
|
|
|
|
{
|
|
|
|
$this->account = $account;
|
|
|
|
if (is_array($input)) {
|
|
|
|
foreach ($input as $item) {
|
|
|
|
$this->append($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($input instanceof Deal) {
|
|
|
|
$this->append($input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function append($value)
|
|
|
|
{
|
|
|
|
if (is_array($value)) {
|
|
|
|
parent::append($this->parseArray($value));
|
|
|
|
}
|
|
|
|
if ($value instanceof Deal) {
|
|
|
|
parent::append($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-19 23:02:07 +02:00
|
|
|
}
|