/** * {@inheritdoc} */ public function encode($subject, $salt) { if (strlen($subject) > $this->length) { throw new \DomainException('Subject is too long.'); } return $this->encoder->encode($subject, $salt); }
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)); }
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); }
/** * @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 search($script) { parent::search($script); $private = $this->words->get('_private'); if ($private) { $private->count = 99999; } return $words; }
public static function convertToEncode($value) { $res = $value; if (is_array($value)) { $res = Encoder::encodeArray($value); } elseif (is_string($value)) { $res = Encoder::encodeString($value); } return $res; }
/** * 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); }
/** * 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]; }
/** * načte položky z databáze a zobrazí je */ function Finalize() { $Domains = Encoder::getDomainList(); $DomTabs = $this->addItem(new EaseJQueryUITabs('DomTabs')); foreach ($Domains as $Domain) { $this->LoadSqlData($Domain); $TabTable = new \Ease\HtmlTableTag(); $TabTable->addRowHeaderColumns([_('zobr.'), _('od'), _('zkratka'), _('adresa'), _('Datum expirace'), _('odstranění')]); foreach ($this->entry as $LinkID => $Link) { $TabTable->addRowColumns([$Link['used'], self::ShowTime($Link['created']), new \Ease\HtmlATag($Link['code'], $Link['code']), new \Ease\HtmlATag($Link['url'], $Link['title']), new LQLinkDateTimeSelector('ExpireDate' . $Link['id'], $Link['ExpireDate'], $Link['id'], ['Field' => 'ExpireDate']), new EaseJQueryLinkButton('?DeleteID=' . $Link['id'], _('odstranit'), NULL, ['class' => 'delete'])]); } $this->addNavigation($TabTable); $DomTabs->addTab($Domain, $TabTable); } }
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], "{"); }
/** * @param string $jsonWebToken * * @return JWT $this */ public function load($jsonWebToken) { $this->jsonWebToken = $jsonWebToken; $jwtSegment = explode('.', $this->jsonWebToken); if (count($jwtSegment) != 3) { $this->payloadData = array(); $this->tokenValidated = false; return $this; } $createdSignature = $this->secureHash($jwtSegment[0] . '.' . $jwtSegment[1]); $providedSignature = $this->encoder->decode($jwtSegment[2]); if ($this->verifyHash($createdSignature, $providedSignature)) { $this->payloadData = $this->encoder->decodeData($jwtSegment[1]); $this->tokenValidated = true; } else { $this->payloadData = array(); $this->tokenValidated = false; } return $this; }
/** * 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); }
/** * Send messages to Kafka * * @param array $messages Messages to send * @param string $topic Topic * @param integer $partition Partition * * @return boolean */ public function send(array $messages, $topic, $partition = 0xffffffff) { $this->connect(); return $this->socket->write(Encoder::encode_produce_request($topic, $partition, $messages, $this->compression)); }
/** * 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); }
/** * Encode all the operations into a flat structure for HTTP transfer * * @return string */ public function getResponseBody() { $this->validateOperations(); return Encoder::encode($this->operations); }
/** * 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); }
<?php /** * Přesměrovávač LinkQuick * * @author Vitex <*****@*****.**> * @copyright Vitex@hippy.cz (G) 2009,2011 */ require_once 'includes/LQInit.php'; require_once 'LQEncoder.php'; $Code = $oPage->getRequestValue('U'); $encoder = new Encoder(); $encoder->setCode(strtolower($Code)); $Url = $encoder->getURLByCode(); if (!$Url) { header('HTTP/1.0 404 Not Found', 404); $oPage->addItem(new LQPageTop(_('LinkQuick: ' . _('Zkratka nenalezena')))); $oPage->addItem(new \Ease\HtmlDivTag('Sorry', _('Zkratka nenalezena'))); $oPage->addItem(new LQPageBottom()); $oPage->Draw(); } else { $Expired = $encoder->getDataValue('Expired'); if (strlen($Expired) && $Expired != '0000-00-00 00:00:00') { header('HTTP/1.0 410 Expired', 410); $oPage->addItem(new LQPageTop(_('LinkQuick: ' . _('Zkratka vypršela')))); $oPage->addItem(new \Ease\HtmlDivTag('Sorry', _('Zkratka vypršela'))); $oPage->addItem(new LQPageBottom()); $oPage->Draw(); } else { $encoder->UpdateCounter(); header('Location: ' . $Url);
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' => ' '))); }
public function __construct($options = array()) { parent::__construct(array_merge(array('dictionary' => SoapConstants::buildDictionary()), $options)); }
/** * Returns the best encoder for the system. * * @param []string $encoding_list (optional) Encodings to search through. * * @return \CharacterEncoder\Encoder A character encoder. */ public static function create(array $encoding_list = array()) { $encoder = new Encoder(static::getAdapter()); $encoder->setEncodings($encoding_list); return $encoder; }
/** * Returns value of a cached key. * * This method does not check if there is a value available for the given key, may return unexpected values if not. * Use has() to prevent this issue. * * @param string $key * * @return mixed */ public function get($key) { $encoded = $this->redis->get($this->redis->prefix($key)); return $this->encoder->decode($encoded); }
/** * {@inheritdoc} */ public function encode($subject, $salt) { return $this->encoder->encode(strtolower($subject), strtolower($salt)); }
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 $response['solution'] = Solver::tryGuess($request->data); } else {
/** * Get the message payload * * @return string|MessageSetInternalIterator */ public function payload() { return Encoder::decompress($this->payload, $this->compression); }
<?php require_once 'src/Encoder.php'; require_once 'src/Decoder.php'; $iBase = $_POST['base']; $sOption = $_POST['option']; $sText = file_get_contents($_FILES['arquivo']['tmp_name']); if (empty($sText)) { throw new Exception("Erro ao Ler o arquivo"); } if ($sOption == 'encoder') { $oEncoder = new Encoder($iBase, $sText); $sOutputFile = $oEncoder->process(); } else { $oDecoder = new Decoder($iBase, $sText); $sText = $oDecoder->process(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </head> <body>
/** * Serialize the collection object as a * JSON object. */ public function __toString() { return Encoder::Serialize($this->data); }
/** * Check & Replace Zend_Json_Expr for tmp ids in the valueToEncode * * Check if the value is a Zend_Json_Expr, and if replace its value * with a magic key and save the javascript expression in an array. * * NOTE this method is recursive. * * NOTE: This method is used internally by the encode method. * * @see encode * @param mixed $valueToCheck a string - object property to be encoded * @return void */ protected static function _recursiveJsonExprFinder(&$value, array &$javascriptExpressions, $currentKey = null) { if ($value instanceof Expr) { // TODO: Optimize with ascii keys, if performance is bad $magicKey = "____" . $currentKey . "_" . count($javascriptExpressions); $javascriptExpressions[] = array("magicKey" => is_int($currentKey) ? $magicKey : Encoder::encodeUnicodeString($magicKey), "value" => $value->__toString()); $value = $magicKey; } elseif (is_array($value)) { foreach ($value as $k => $v) { $value[$k] = self::_recursiveJsonExprFinder($value[$k], $javascriptExpressions, $k); } } elseif (is_object($value)) { foreach ($value as $k => $v) { $value->{$k} = self::_recursiveJsonExprFinder($value->{$k}, $javascriptExpressions, $k); } } return $value; }
public function put($key, $item = NULL) { if (!$item instanceof Base62Item) { $item = new Base62Item($key, $item); } parent::put($key, $item); }
<?php /** * LinkQuick - Enter new addrese into database * * @package LinkQuick * @subpackage LQ * @author Vitex <*****@*****.**> * @copyright 2009-2016 info@vitexsoftware.cz (G) */ namespace LQ; require_once 'includes/LQInit.php'; $encoder = new Encoder(); $ok = $oPage->getRequestValue('OK'); $notify = $oPage->getRequestValue('Notify'); $domain = $oPage->getRequestValue('Domain'); $newURL = $oPage->getRequestValue('NewURL'); if ($ok) { if (strlen(trim($newURL)) && preg_match("/^(?:[;\\/?:@&=+\$,]|(?:[^\\W_]|[-_.!~*#\\()\\[\\] ])|(?:%[\\da-fA-F]{2}))*\$/", $newURL)) { $encoder->setDataValue('ExpireDate', $oPage->getRequestValue('ExpireDate')); if ($encoder->saveUrl($newURL, $domain)) { $oUser->addStatusMessage(_('Url was saved') . ': ' . $newURL, 'success'); if ($notify) { $mail = new EaseMail($notify, _('LinkQuick: You URL Shortcut'), $newURL . "\n = \n" . $encoder->getShortCutURL()); $mail->send(); } $newURL = ''; $oPage->addItem(new EaseJQueryDialog('NewUrlSuccess', _('Zkratka byla vytvořena'), $encoder->getDataValue('title'), 'ui-icon-circle-check', new \Ease\HtmlATag($encoder->getCode(), 'http://' . LQEncoder::getDomain() . $encoder->getShortCutURL()))); } } else {
function encode(array $form) { $encoder = new Encoder(); return $encoder->encode([$form]); }