Since: 1.0
Author: Antonio Ramirez (amigo.cobos@gmail.com)
Esempio n. 1
1
 /**
  * Checks whether the policy and sig
  * @param ApiUser $user
  * @return bool
  * @throws EApiError
  */
 public function isSignatureMatched($user)
 {
     $requestArray = Yii::app()->getController()->getJsonInputAsArray();
     if (empty($requestArray)) {
         throw new EApiError(HHttp::ERROR_BADREQUEST, HHttp::getErrorMessage(HHttp::ERROR_BADREQUEST));
     }
     $signature = ArrayX::pop($requestArray, 'signature');
     $expires = ArrayX::pop($requestArray, 'expiration');
     if (!$signature || !$expires) {
         throw new EApiError(HHttp::ERROR_BADREQUEST, HHttp::getErrorMessage(HHttp::ERROR_BADREQUEST));
     }
     // check time
     if (strtotime($expires) < time()) {
         throw new EApiError(HHttp::ERROR_INTERNAL_504, HHttp::getErrorMessage(HHttp::ERROR_INTERNAL_504));
     }
     // set back the expiration time to recreate the policy and make a handshake
     $requestArray['ttd'] = $expires;
     $requestData = new RequestData($requestArray);
     $requestData->prepareData($user->api_secret);
     // use secret to create signature
     return strcmp($requestData->getSignature(), $signature) === 0;
 }
Esempio n. 2
0
 /**
  * Reads the configuration settings from the file
  * @return array|mixed
  * @throws \Exception
  */
 public static function settings()
 {
     if (null === self::$_settings) {
         self::$_settings = file_exists(self::getConfigurationDirectoryPath() . '/settings.php') ? require_once self::getConfigurationDirectoryPath() . '/settings.php' : array();
         self::$_settings['envlock'] = file_exists(self::getEnvironmentLockFilePath());
         if (($customSettings = ArrayX::get(self::$_settings, 'custom.path')) !== null && file_exists($customSettings)) {
             self::$_settings = ArrayX::merge(self::$_settings, require_once $customSettings);
         }
     }
     if (empty(self::$_settings)) {
         throw new \Exception('Unable to find Yiinitialzr settings file!');
     }
     return self::$_settings;
 }
Esempio n. 3
0
 /**
  * @param $directory
  * @param $files  array of configuration files to merge
  * @return array
  */
 public static function build($directory, $files)
 {
     $result = array();
     if (!is_array($files)) {
         $files = array($files);
     }
     foreach ($files as $file) {
         $config = file_exists($file) && is_file($file) ? require $file : (is_string($file) && file_exists($directory . '/' . $file . '.php') ? require $directory . '/' . $file . '.php' : array());
         if (is_array($config)) {
             $result = ArrayX::merge($result, $config);
         }
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Returns a value of the array
  * @param $value
  * @return mixed | null if no key is found
  */
 public static function value($value)
 {
     return ArrayX::get(self::settings(), $value);
 }