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