Récupère une annonce existante
This commit is contained in:
@@ -1,8 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Shikiryu\LBCReposter;
|
||||
|
||||
class Deals
|
||||
{
|
||||
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user