| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-10-11)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace MGProvision\Proxmox\v2\models;
- use MGProvision\Proxmox\v2\Api;
- /**
- * Description of AbstractObject
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- abstract class AbstractObject
- {
- protected $api;
- public function setAttributes($attributes)
- {
- foreach ($attributes as $name => $attValue)
- {
- $methodName = 'set' . ucfirst($name);
- if (method_exists($this, $methodName))
- $this->{$methodName}($attValue);
- }
- return $this;
- }
- public function setApi($api)
- {
- $this->api = $api;
- return $this;
- }
- /**
- *
- * @return \MGProvision\Proxmox\v2\Api
- */
- protected function api()
- {
- if ($this->api !== null)
- return $this->api;
- return $this->api = \MGProvision\Proxmox\v2\Api::getInstance();
- }
- /**
- * @return Api
- */
- public function getApi(){
- return $this->api;
- }
- public static function asArray($proxmoxConfig)
- {
- $result = array();
- $config = explode(",", $proxmoxConfig);
- foreach ($config as $c)
- {
- list($key, $val) = explode("=", $c);
- $result[$key] = $val;
- }
- return $result;
- }
- public function toArray()
- {
- if (method_exists($this, 'getAttributes'))
- {
- return $this->getAttributes();
- }
- $fields = get_class_vars(get_called_class());
- $data = array();
- foreach ($fields as $name => $defult)
- {
- $methodName = 'get' . ucfirst($name);
- if (method_exists($this, $methodName))
- {
- $data[$name] = $this->{$methodName}();
- }
- }
- return $data;
- }
- public function toConfig($fields, &$config)
- {
- foreach ($fields as $field)
- {
- $methodName = 'get' . ucfirst($field);
- if (method_exists($this, $methodName) && ( $this->{$methodName}() || $this->{$methodName}() ===0 || $this->{$methodName}() ==="0") )
- {
- $config[] = "{$field}=" . $this->{$methodName}();
- }
- }
- }
- public function toString()
- {
- return print_r($this->getAttributes(), true);
- }
- public function getHashCode()
- {
- return hash('ripemd160',$this->toString());
- }
- }
|