API/library/Deals.php

45 lines
1.1 KiB
PHP
Raw Normal View History

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;
}
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
}