Пример #1
0
 /**
  * Constructor set settings for encryption
  *
  * @param array $config array (
  *      'key' => string,
  *      'cipher' => MCRYPT_ciphername,
  *      'mode' => MCRYPT_MODE_modename
  * )
  * @return Encryption
  */
 public function __construct(array $config = array())
 {
     // Set general settings
     $this->key = ArrayUtils::arrayTarget('key', $config, 'mykey');
     $this->cipher = ArrayUtils::arrayTarget('cipher', $config, MCRYPT_RIJNDAEL_256);
     $this->mode = ArrayUtils::arrayTarget('mode', $config, MCRYPT_MODE_CFB);
     // Calculate IV Size
     $this->ivSize = mcrypt_get_iv_size($this->cipher, $this->mode);
 }
Пример #2
0
 public function testArrayTarget()
 {
     $testArray = array('suite' => array('test' => true, 'live' => false));
     $result = ArrayUtils::arrayTarget('suite', $testArray, false);
     $this->assertInternalType('array', $result);
     $result = ArrayUtils::arrayTarget('suite.live', $testArray, null);
     $this->assertEquals(null, $result);
     $result = ArrayUtils::arrayTarget('suite.non', $testArray, false);
     $this->assertEquals(false, $result);
     $result = ArrayUtils::arrayTarget('suite.test.live', $result, 'nothing');
     $this->assertEquals('nothing', $result);
 }
Пример #3
0
 /**
  * Create Request object from Raw Request
  *
  * @param string $string
  * @return Collection\Request | Collection\Response on error
  */
 public function createRequestFromRawRequest($string)
 {
     // Process through the layer before processing
     $string = $this->protocolLayerStack->handleRequest($string);
     $collection = new Collection\Request();
     try {
         // Decode the data
         $data = @json_decode($string, true);
         // No array means decoding failed
         if (is_array($data) === false) {
             throw new Exception\InvalidRequest('Parse error', static::PARSE_ERROR);
         }
         // Make it a batch request
         if (Common\ArrayUtils::isAssociative($data)) {
             $data = array($data);
         }
         foreach ($data as $requestData) {
             // Always hace request object
             $request = new Entity\Request();
             // Append the request object
             $collection->append($request);
             // Next checks expects an array
             if (is_array($requestData) === false) {
                 $requestData = array();
             }
             // Get the available arguments
             $jsonRpc = $this->getArrayItem('jsonrpc', $requestData, null);
             $method = $this->getArrayItem('method', $requestData, null);
             $params = $this->getArrayItem('params', $requestData, array());
             $id = $this->getArrayItem('id', $requestData, null);
             // Set the values on the request object
             $request->setJsonrpc($jsonRpc)->setId($id)->setMethod($method);
             // Set all the parameters
             foreach ($params as $offset => $value) {
                 $request->addParam($value, $offset);
             }
         }
     } catch (\Exception $e) {
         // Error occured and create
         $response = $this->createResponseFromException(new Entity\Request(), $e);
         // Create collection response object
         $responseCollection = new Collection\Response();
         // Attach the single response error (parse error);
         $responseCollection->append($response);
         // Return the response collection
         return $responseCollection;
     }
     return $collection;
 }