Server IP : 108.163.255.210 / Your IP : 3.145.106.176 Web Server : Apache System : Linux blossom.urlnameserver.com 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64 User : ( 1172) PHP Version : 7.2.34 Disable Function : eval,escapeshellarg,proc_close,proc_get_status,proc_nice,proc_open,symlink,system,pcntl_exec,getrusage,chown,chgp,closelog,openlog,syslog,define_syslog_variables,php_ini_loaded_file,getservbyname,getservbyport,posix_getgid,posix_getgrgid,proc_terminate,pfsockopen,apache_child_terminate,posix_mkfifo,posix_setpgid,posix_setuid,hypot,pg_host,pos,posix_access,posix_getcwd,posix_getservbyname,myshellexec,getpid,posix_getsid,posix_isatty,posix_kill,posix_mknod,posix_setgid,posix_setsid,posix_setuid,posix_times,posix_uname,ps_fill,posix_getpwuid,global,ini_restore,zip_open,zip_read,rar_open,bzopen,bzread,bzwrite,apache_get_modules,apache_get_version,phpversionphpinfo,php_ini_scanned_files,get_current_user,disk_total_space,diskfreespace,leak,imap_list,hypo,filedump,safe_mode,getmygid,apache_getenv,apache_setenv,bzread,bzwrite,bzopen,phpini,higlight_file,dos_conv,get_cwd,er_log,cmd,e_name,vdir,get_dir,only_read,ftok,ftpexec,posix_getpwnam,mysql_list_dbs,disk_free_space,session_save_path,confirm_phpdoc_compiled,zip_entry_rea,php_u,psockopen,crack_opendict,crack_getlastmessage,crack_closedict,crack_check,fpassthru,posix_get_last_error,posix_getlogin,posix_getgroups,posix_strerror,posix_getrlimit,posix_getpgrp,posix_getgrnam,pos,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/unilinki/public_html/alpai/app/razorpay-php/src/ |
Upload File : |
<?php namespace Razorpay\Api; use Razorpay\Api\Errors; class Entity extends Resource implements ArrayableInterface { protected $attributes = array(); protected function create($attributes = null) { $entityUrl = $this->getEntityUrl(); return $this->request('POST', $entityUrl, $attributes); } protected function fetch($id) { $entityUrl = $this->getEntityUrl(); $this->validateIdPresence($id); $relativeUrl = $entityUrl . $id; return $this->request('GET', $relativeUrl); } protected function validateIdPresence($id) { if ($id !== null) { return; } $path = explode('\\', get_class($this)); $class = strtolower(array_pop($path)); $message = 'The ' . $class . ' id provided is null'; $code = Errors\ErrorCode::BAD_REQUEST_ERROR; throw new Errors\BadRequestError($message, $code, 500); } protected function all($options = array()) { $entityUrl = $this->getEntityUrl(); return $this->request('GET', $entityUrl, $options); } protected function getEntityUrl() { $fullClassName = get_class($this); $pos = strrpos($fullClassName, '\\'); $className = substr($fullClassName, $pos + 1); $className = $this->snakeCase($className); return $className.'s/'; } protected function snakeCase($input) { $delimiter = '_'; $output = preg_replace('/\s+/u', '', ucwords($input)); $output = preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $output); $output = strtolower($output); return $output; } /** * Makes a HTTP request using Request class and assuming the API returns * formatted entity or collection result, wraps the returned JSON as entity * and returns. * * @param string $method * @param string $relativeUrl * @param array $data * * @return Entity */ protected function request($method, $relativeUrl, $data = null) { $request = new Request(); $response = $request->request($method, $relativeUrl, $data); if ((isset($response['entity'])) and ($response['entity'] == $this->getEntity())) { $this->fill($response); return $this; } else { return static::buildEntity($response); } } /** * Given the JSON response of an API call, wraps it to corresponding entity * class or a collection and returns the same. * * @param array $data * * @return Entity */ protected static function buildEntity($data) { $entities = static::getDefinedEntitiesArray(); if (isset($data['entity'])) { if (in_array($data['entity'], $entities)) { $class = static::getEntityClass($data['entity']); $entity = new $class; } else { $entity = new static; } } else { $entity = new static; } $entity->fill($data); return $entity; } protected static function getDefinedEntitiesArray() { return array( 'collection', 'payment', 'refund', 'order', 'customer', 'token', 'settlement'); } protected static function getEntityClass($name) { return __NAMESPACE__.'\\'.ucfirst($name); } protected function getEntity() { $class = get_class($this); $pos = strrpos($class, '\\'); $entity = strtolower(substr($class, $pos)); return $entity; } public function fill($data) { $attributes = array(); foreach ($data as $key => $value) { if (is_array($value)) { if (static::isAssocArray($value) === false) { $collection = array(); foreach ($value as $v) { if (is_array($v)) { $entity = static::buildEntity($v); array_push($collection, $entity); } else { array_push($collection, $v); } } $value = $collection; } else { $value = static::buildEntity($value); } } $attributes[$key] = $value; } $this->attributes = $attributes; } public static function isAssocArray($arr) { return array_keys($arr) !== range(0, count($arr) - 1); } public function toArray() { return $this->convertToArray($this->attributes); } protected function convertToArray($attributes) { $array = $attributes; foreach ($attributes as $key => $value) { if (is_object($value)) { $array[$key] = $value->toArray(); } else if (is_array($value) and self::isAssocArray($value) == false) { $array[$key] = $this->convertToArray($value); } } return $array; } }