/** * {@inheritdoc} */ public function encode($subject, $salt) { if (strlen($subject) > $this->length) { throw new \DomainException('Subject is too long.'); } return $this->encoder->encode($subject, $salt); }
/** * Store a value for a given key in the cache. * * This method does not check if there is a value available for the given key, may cause unexpected behavior if not. * Use has() to prevent this issue. * * @param string $key * @param array $tags * @param mixed $data */ public function set($key, array $tags, $data) { $key = $this->redis->prefix($key); $this->redis->set($key, $this->encoder->encode($data)); if (is_int($this->expirationTime) && $this->expirationTime > 0) { $this->redis->expire($key, $this->expirationTime); } foreach ($tags as $tag) { $this->redis->sadd($this->redis->prefix($tag), $key); } }
public function testMixed() { $testText = "Hello world! 3.141592 is PI. A B C"; $encoder = new Encoder(); $this->assertEquals("Hotel Echo Lima Lima Oscar Whiskey Oscar Romeo Lima Delta! Three Point One Four One Five Niner Two India Sierra Papa India. Alfa Bravo Charlie", $encoder->encode($testText)); $testText2 = "I love 新世紀エヴァンゲリオン! It's very すけ. Je l'aimé."; $tolerantEncoder = new Encoder(); $tolerantEncoder->enableErrorsOnNonASCII(FALSE); $this->assertEquals("India Lima Oscar Victor Echo 新世紀エヴァンゲリオン! India Tango'Sierra Victor Echo Romeo Yankee すけ. Juliett Echo Lima'Alfa India Mikeé.", $tolerantEncoder->encode($testText2)); }
/** * Build the list of arguments used in a callback invocation * * @param array $params Callback parameters * @param array $localVars Known vars from the calling scope * @return string JavaScript code */ protected function buildCallbackArguments(array $params, array $localVars) { // Remove 'parser' as a parameter, since there's no such thing in JavaScript unset($params['parser']); // Add global vars to the list of vars in scope $localVars += ['logger' => 1, 'openTags' => 1, 'registeredVars' => 1]; $args = []; foreach ($params as $k => $v) { if (isset($v)) { // Param by value $args[] = $this->encoder->encode($v); } elseif (isset($localVars[$k])) { // Param by name that matches a local var $args[] = $k; } else { $args[] = 'registeredVars[' . json_encode($k) . ']'; } } return implode(',', $args); }
public function shrink($script = '') { $script = $this->encodeData($script); $this->blocks = array(); $script = $this->decodeBlocks($this->encodeBlocks($script), $this->ENCODED_BLOCK); unset($this->blocks); $this->count = 0; $this->script = $script; $shrunk = new Encoder(Shrinker::SHRUNK, array(&$this, '_varEncoder')); $script = $shrunk->encode($script); unset($this->script); return $this->decodeData($script); }
/** * @return JWT $this */ public function sign() { if (empty($this->key)) { throw new \InvalidArgumentException('Secret key needs to be used.'); } $headerData = array('typ' => 'JWT', 'alg' => $this->algorithm); $jwtSegment[0] = $this->encoder->encodeData($headerData); $jwtSegment[1] = $this->encoder->encodeData($this->payloadData); $signature = $this->secureHash(implode('.', $jwtSegment)); $jwtSegment[2] = $this->encoder->encode($signature); $this->jsonWebToken = implode('.', $jwtSegment); $this->tokenValidated = true; return $this; }
/** * Record a given config object as a ConfigValue instance * * @param array|Code|Dictionary $object Original object * @return ConfigValue Stored ConfigValue instance */ protected function recordObject($object) { $js = $this->encoder->encode($object); $varName = $this->getVarName($js); if ($this->isIterable($object)) { $object = $this->recordObjectContent($object); } if (!isset($this->configValues[$varName])) { $this->configValues[$varName] = new ConfigValue($object, $varName); $this->jsLengths[$varName] = strlen($js); } $this->configValues[$varName]->incrementUseCount(); return $this->configValues[$varName]; }
/** * @covers \Magento\Framework\Url\Encoder::encode * @covers \Magento\Framework\Url\Decoder::decode */ public function testDecode() { $urlBuilderMock = $this->getMock('Magento\\Framework\\UrlInterface', [], [], '', false); /** @var $urlBuilderMock \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ $decoder = new Decoder($urlBuilderMock); $encoder = new Encoder(); $data = uniqid(); $result = $encoder->encode($data); $urlBuilderMock->expects($this->once())->method('sessionUrlVar')->with($this->equalTo($data))->will($this->returnValue($result)); $this->assertNotContains('&', $result); $this->assertNotContains('%', $result); $this->assertNotContains('+', $result); $this->assertNotContains('=', $result); $this->assertEquals($result, $decoder->decode($result)); }
public function testListEncode() { // valid empty GGON list $this->assertEquals(Encoder::encode(["length" => "0"]), "[]"); // valid GGON list $this->assertEquals(Encoder::encode(["length" => "2", "0" => "a", "1" => "b"]), "[a,b]"); $encoded = Encoder::encode(["length" => "a", "0" => "a", "1" => "b"]); // length is invalid, not valid GGON list $this->assertEquals($encoded[0], "{"); $encoded = Encoder::encode(["length" => "3", "0" => "a", "1" => "b"]); // length is wrong, also not valid GGON list $this->assertEquals($encoded[0], "{"); $encoded = Encoder::encode(["length" => "3", "0" => "a", "2" => "c"]); // sparse, not a valid GGON list $this->assertEquals($encoded[0], "{"); }
/** * Encode the mixed $valueToEncode into the JSON format * * Encodes using ext/json's json_encode() if available. * * NOTE: Object should not contain cycles; the JSON format * does not allow object reference. * * NOTE: Only public variables will be encoded * * NOTE: Encoding native javascript expressions are possible using Zend_Json_Expr. * You can enable this by setting $options['enableJsonExprFinder'] = true * * @see Zend_Json_Expr * * @param mixed $valueToEncode * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default * @param array $options Additional options used during encoding * @return string JSON encoded object */ public static function encode($valueToEncode, $cycleCheck = false, $options = array()) { if (is_object($valueToEncode) && method_exists($valueToEncode, 'toJson')) { return $valueToEncode->toJson(); } // Pre-encoding look for Zend_Json_Expr objects and replacing by tmp ids $javascriptExpressions = array(); if (isset($options['enableJsonExprFinder']) && $options['enableJsonExprFinder'] == true) { $valueToEncode = self::_recursiveJsonExprFinder($valueToEncode, $javascriptExpressions); } // Encoding if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) { $encodedResult = json_encode($valueToEncode); } else { $encodedResult = Encoder::encode($valueToEncode, $cycleCheck, $options); } //only do post-proccessing to revert back the Zend_Json_Expr if any. if (count($javascriptExpressions) > 0) { $count = count($javascriptExpressions); for ($i = 0; $i < $count; $i++) { $magicKey = $javascriptExpressions[$i]['magicKey']; $value = $javascriptExpressions[$i]['value']; $encodedResult = str_replace('"' . $magicKey . '"', $value, $encodedResult); } } return $encodedResult; }
/** * {@inheritdoc} */ public function encode($subject, $salt) { return $this->encoder->encode(strtolower($subject), strtolower($salt)); }
protected function assertEncoding($expected, $data) { $encoder = new Encoder(); $actual = $encoder->encode($data); $this->assertEquals($expected, $actual); }
/** * @param $value * @param int $options * @param int $depth * @return string */ public static function encode($value, $options = 0, $depth = 512) { $encoder = new Encoder($options, $depth); return $encoder->encode($value); }
/** * Returns the NEON representation of a value. * @param mixed * @param int * @return string */ public static function encode($var, int $options = NULL) : string { $encoder = new Encoder(); return $encoder->encode($var, $options); }
/** * Encode a value into a bencode encoded string * * @param mixed $value The value to encode. * @return string Returns a bencode encoded string. */ public static function encode($value) { return Encoder::encode($value); }
/** * returns the NEON representation of a value * * @param mixed * @param int * * @return string */ public static function encode($var, $options = null) { $encoder = new Encoder(); return $encoder->encode($var, $options); }
public function testFull() { $expected = "<?xml version=\"1.0\"?>\n" . "<User>\n" . " <Name>Joby Walker</Name>\n" . " <HasSkills>false</HasSkills>\n" . " <Locations>\n" . " <Location>\n" . " <Type>work</Type>\n" . " <City>Seattle</City>\n" . " </Location>\n" . " <Location>\n" . " <Type>home</Type>\n" . " <City>Seattle</City>\n" . " <Cats>2</Cats>\n" . " <Dogs/>\n" . " </Location>\n" . " </Locations>\n" . "</User>"; $test = (object) array('Name' => 'Joby Walker', 'HasSkills' => false, 'Talent' => new \Imperium\JSON\Undefined(), 'Locations' => (object) array('Location' => array((object) array('Type' => 'work', 'City' => 'Seattle'), (object) array('Type' => 'home', 'City' => 'Seattle', 'Cats' => 2, 'Dogs' => null)))); $this->assertEquals($expected, Encoder::encode($test, 'User', array('declare' => true, 'offset' => ' '))); }
/** * Encode all the operations into a flat structure for HTTP transfer * * @return string */ public function getResponseBody() { $this->validateOperations(); return Encoder::encode($this->operations); }
function encode(array $form) { $encoder = new Encoder(); return $encoder->encode([$form]); }
/** * Returns the NEON representation of a value. * @param mixed * @param int * @return string */ public static function encode($var, $options = NULL) { $encoder = new Encoder; return $encoder->encode($var, $options); }
session_start(); include_once 'classes.php'; /* * Proceeding request data */ if (isset($_POST['data'])) { // Clearing string to avoid javascript from external requests $json = trim(strip_tags($_POST['data'])); $request = json_decode($json); // Preparing response array $response = array(); if (isset($request->action) && isset($request->data) && isset($request->rot)) { if ($request->action === 'encode') { // Receiving encoded text $response['data'] = Encoder::encode($request->data, (int) $request->rot); // Receiving input frequency $response['frequency'] = Encoder::getFrequency($request->data); // Setting success status $response['status'] = 'success'; // Setting solution attempt $response['solution'] = Solver::tryGuess($request->data); } else { if ($request->action === 'decode') { // Receiving decoded text $response['data'] = Decoder::decode($request->data, (int) $request->rot); // Setting success status $response['frequency'] = Decoder::getFrequency($request->data); // Setting success status $response['status'] = 'success'; // Setting solution attempt