45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
} |