Overview
  • Namespace
  • Class

Namespaces

  • rpf
    • api
      • module
    • extension
      • module
    • system
      • module

Classes

  • rpf\api\api
  • rpf\api\apiModule
  • rpf\api\bbRpc
  • rpf\api\module\bbCustomer_getFreeOrdNr
  • rpf\api\module\bbCustomer_readAddress
  • rpf\api\module\bbCustomer_readDiscount
  • rpf\api\module\bbCustomer_readEntry
  • rpf\api\module\bbCustomer_readPayment
  • rpf\api\module\bbCustomer_readTitle
  • rpf\api\module\bbCustomer_saveAdress
  • rpf\api\module\bbCustomer_validateAddress
  • rpf\api\module\bbCustomer_validateEntry
  • rpf\api\module\bbCustomer_validatePayinfo
  • rpf\api\module\bbDomain_readEntry
  • rpf\api\module\bbDomain_readFrontpage
  • rpf\api\module\bbDomain_readHandles
  • rpf\api\module\bbDomain_readPhpini
  • rpf\api\module\bbDomain_readSettings
  • rpf\api\module\bbDomain_readSubdomain
  • rpf\api\module\bbDomain_readWebalizerSettings
  • rpf\api\module\bbDomain_searchEntry
  • rpf\api\module\bbEmail_readAccount
  • rpf\api\module\bbMysql_inuseEntry
  • rpf\api\module\bbMysql_makeBackup
  • rpf\api\module\bbMysql_readEntry
  • rpf\api\module\bbOrder_readAccountAddress
  • rpf\api\module\bbOrder_readAccountEntry
  • rpf\api\module\bbOrder_readDisposition
  • rpf\api\module\bbOrder_readEntry
  • rpf\api\module\bbQuota_readEntry
  • rpf\api\module\customer
  • rpf\api\module\email
  • rpf\api\module\order
  • rpf\api\module\placeholder
  • rpf\api\module\user
  • rpf\extension\extension
  • rpf\extension\extensionModule
  • rpf\extension\invoiceTextExport
  • rpf\extension\mailExport
  • rpf\extension\module\domainExport
  • rpf\extension\module\index
  • rpf\extension\module\mgntRatioExport
  • rpf\system\module
  • rpf\system\module\log
  • rpf\system\module\moduleManager
  • rpf\system\rpf

Exceptions

  • rpf\system\module\exception
  1 <?php
  2 
  3 namespace rpf\api;
  4 use rpf\system\module;
  5 
  6 /**
  7  * RPF API-Module-Class
  8  *
  9  * @author Andreas Doebeling <ad@1601.com>
 10  * @copyright 1601.production siegler&thuemmler ohg
 11  * @link https://github.com/ADoebeling/RP2-Framework
 12  * @link https://xing-ad.1601.com
 13  * @link https://www.1601.com
 14  */
 15 class apiModule extends module
 16 {
 17     /**
 18      * Name of the RPC-Methode
 19      * @var string
 20      */
 21     protected $rpcMethod = 'UNDEFINED';
 22 
 23     /**
 24      * @var array call-params (filter, return, format, ...)
 25      */
 26     private $rpcParams = array();
 27 
 28     /**
 29      * @var array ['requestString' => $result]
 30      */
 31     private $rpcCache = array();
 32 
 33 
 34       /**
 35      * @param string $name
 36      * @param mixed $value
 37      * @return $this
 38      */
 39     protected function addParam($name, $value)
 40     {
 41         $this->rpcParams[(string) $name] = $value;
 42         return $this;
 43     }
 44 
 45     /**
 46      * Get result of api-request
 47      *
 48      * @param bool|string $cache (false, true = runtime, memcache)
 49      * @return array|bool
 50      */
 51     public function get($cache = true)
 52     {
 53         return $this->getRpcResponse($this->rpcMethod, $this->rpcParams, null, $cache);
 54     }
 55 
 56     /**
 57      * Wrapper for all api-calls with build-in caching
 58      *
 59      * @param $sMethod
 60      * @param array $hArgs
 61      * @param null $hPlaceholders
 62      * @param bool|string $cache
 63      * @return null
 64      * @throws \Exception
 65      */
 66     private function getRpcResponse($sMethod, $hArgs=array(), $hPlaceholders=null, $cache = true)
 67     {
 68         $requestString = '';
 69         foreach ($this->rpcParams as $name => $value)
 70         {
 71             /*if (!is_string($value) && !is_bool($value))
 72             {
 73                 throw new module\exception("Sorry, Params can't be ".\gettype($value));
 74             }*/
 75             $requestString .= empty($requestString) ? $sMethod.'(' : ',';
 76             $requestString .= "'$name' => '$value'";
 77         }
 78         $requestString .= ')';
 79 
 80 
 81 
 82         if ($cache === true && isset($this->rpcCache[$requestString]))
 83         {
 84             module\log::debug('Getting RPC-Response from runtime-cache', __METHOD__ . "($requestString)");
 85             return $this->rpcCache[$requestString];
 86         }
 87         else if ($cache === 'memcache')
 88         {
 89             throw new module\exception('Sorry, memcach is not implemented yet');
 90         }
 91         else
 92         {
 93             $duration = microtime(1);
 94             global $_BBRPC_Msgs;
 95             $this->rpcCache[$requestString] = bbRpc::call($sMethod,$hArgs,$hPlaceholders);
 96             $duration = round(microtime(1)-$duration, 3);
 97             $resultCounter = count($this->rpcCache[$requestString]);
 98             module\log::debug("Performing RPC-Request within $duration sec.", __METHOD__);
 99             module\log::debug("Getting $resultCounter rows ", $requestString);
100             $this->fetchRpcLog();
101         }
102         return $this->rpcCache[$requestString];
103     }
104 
105     /**
106      * @todo fix me, seems like I'm broken
107      */
108     protected function fetchRpcLog()
109     {
110         // I realy don't like the way of fetching RPC-Error-Messages...
111         //$hLoglvl = array("error"=>0, "warn"=>1, "notice"=>2, "ok"=>3, "debug"=>4);
112         global $_BBRPC_Msgs;
113 
114         if (is_array($_BBRPC_Msgs))
115         {
116             foreach ($_BBRPC_Msgs as $key => &$hMsg)
117             {
118                 switch ($hMsg["typ"])
119                 {
120                     case 0:
121                         module\log::error("RPC-Msg.: $hMsg", __METHOD__);
122                         break;
123                     case 1:
124                         module\log::warning("RPC-Msg.: $hMsg", __METHOD__);
125                         break;
126                     case 2:
127                         module\log::info("RPC-Msg.: $hMsg", __METHOD__);
128                         break;
129                     case 3:
130                         module\log::debug("RPC-Msg.: OK! $hMsg", __METHOD__);
131                         break;
132                     case 4:
133                         module\log::debug("RPC-Msg.: $hMsg", __METHOD__);
134                         break;
135                 }
136                 unset($_BBRPC_Msgs[$key]);
137             }
138         }
139     }
140 }
API documentation generated by ApiGen