1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<?php
namespace OpenCloud\LoadBalancer\Resource;
use Guzzle\Http\Exception\ClientErrorResponseException;
use OpenCloud\Common\Resource\PersistentResource;
abstract class AbstractResource extends PersistentResource
{
public function refresh($id = null, $url = null)
{
if (!isset($this->id)) {
return false;
}
try {
return parent::refresh($id, $url);
} catch (ClientErrorResponseException $e) {
return false;
}
}
protected function createJson()
{
$object = new \stdClass;
foreach ($this->createKeys as $item) {
$object->$item = $this->$item;
}
if ($top = $this->jsonName()) {
$object = array($top => $object);
}
return $object;
}
protected function updateJson($params = array())
{
return $this->createJson();
}
public function name()
{
$classArray = explode('\\', get_class($this));
return method_exists($this->getParent(), 'id')
? sprintf('%s-%s', end($classArray), $this->getParent()->id())
: parent::name();
}
}