本文整理汇总了PHP中CM_Params::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP CM_Params::encode方法的具体用法?PHP CM_Params::encode怎么用?PHP CM_Params::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CM_Params
的用法示例。
在下文中一共展示了CM_Params::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _processView
protected function _processView(array $output)
{
$success = array();
$form = $this->_getView();
$className = get_class($form);
if (!$form instanceof CM_Form_Abstract) {
throw new CM_Exception_Invalid('`' . $className . '`is not `CM_Form_Abstract` instance');
}
$query = $this->_request->getQuery();
$actionName = (string) $query['actionName'];
$data = (array) $query['data'];
$this->_setStringRepresentation($className . '::' . $actionName);
$success['data'] = CM_Params::encode($form->process($data, $actionName, $this));
if (!empty($this->errors)) {
$success['errors'] = $this->errors;
}
$jsCode = $this->getRender()->getGlobalResponse()->getJs();
if (!empty($jsCode)) {
$success['exec'] = $jsCode;
}
if (!empty($this->messages)) {
$success['messages'] = $this->messages;
}
$output['success'] = $success;
return $output;
}
示例2: debug
/**
* @param mixed $varList
*/
public function debug($varList)
{
foreach ($varList as &$var) {
$var = CM_Params::encode($var, true);
}
$this->_operations[] = 'this.message(' . implode(', ', $varList) . ');';
}
示例3: _processView
protected function _processView(array $output)
{
$success = array();
$query = $this->_request->getQuery();
if (!isset($query['method'])) {
throw new CM_Exception_Invalid('No method specified', CM_Exception::WARN);
}
if (!preg_match('/^[\\w_]+$/i', $query['method'])) {
throw new CM_Exception_Invalid('Illegal method', CM_Exception::WARN, ['method' => $query['method']]);
}
if (!isset($query['params']) || !is_array($query['params'])) {
throw new CM_Exception_Invalid('Illegal params', CM_Exception::WARN);
}
$view = $this->_getView();
if ($view instanceof CM_View_CheckAccessibleInterface) {
$view->checkAccessible($this->getRender()->getEnvironment());
}
$ajaxMethodName = 'ajax_' . $query['method'];
$params = CM_Params::factory($query['params'], true);
$componentHandler = new CM_Frontend_JavascriptContainer_View();
$this->_setStringRepresentation(get_class($view) . '::' . $ajaxMethodName);
if (!method_exists($view, $ajaxMethodName)) {
throw new CM_Exception_Invalid('Method not found', CM_Exception::WARN, ['method' => $ajaxMethodName]);
}
$data = $view->{$ajaxMethodName}($params, $componentHandler, $this);
$success['data'] = CM_Params::encode($data);
$frontend = $this->getRender()->getGlobalResponse();
$frontend->getOnloadReadyJs()->append($componentHandler->compile('this'));
$jsCode = $frontend->getJs();
if (strlen($jsCode)) {
$success['exec'] = $jsCode;
}
$output['success'] = $success;
return $output;
}
示例4: publish
/**
* @param string $channel
* @param string $event
* @param mixed|null $data
*/
public function publish($channel, $event, $data = null)
{
if (!$this->getEnabled()) {
return;
}
$this->getAdapter()->publish($channel, $event, CM_Params::encode($data));
}
示例5: __construct
/**
* @param CM_Model_Language $language
*/
public function __construct(CM_Model_Language $language)
{
$translations = array();
foreach (new CM_Paging_Translation_Language($language, null, null, null, true) as $translation) {
$translations[$translation['key']] = $language->getTranslation($translation['key']);
}
$this->_content = 'cm.language.setAll(' . CM_Params::encode($translations, true) . ');';
}
示例6: __construct
/**
* @param CM_Site_Abstract $site
* @param bool|null $debug
* @param CM_Model_Language $language
*/
public function __construct(CM_Site_Abstract $site, $debug = null, CM_Model_Language $language)
{
parent::__construct($site, $debug);
$translations = array();
foreach ($language->getTranslations(true) as $translation) {
$translations[$translation['key']] = $language->getTranslation($translation['key']);
}
$this->_js->append('cm.language.setAll(' . CM_Params::encode($translations, true) . ');');
}
示例7: testProcessHostRedirect_parameter
public function testProcessHostRedirect_parameter()
{
$site = CM_Site_Abstract::factory();
$location = CMTest_TH::createLocation();
$locationEncoded = CM_Params::encode($location, true);
$query = http_build_query(['location' => $locationEncoded]);
$response = CMTest_TH::createResponsePage('/mock5?' . $query, array('host' => 'incorrect-host.org'));
$response->process();
$siteUrl = 'http://' . $site->getHost();
$this->assertContains('Location: ' . $siteUrl . '/mock5?' . $query, $response->getHeaders());
}
示例8: testJsonSerialize
public function testJsonSerialize()
{
$obj = new CM_Frontend_JsonSerializable();
$this->assertEquals('[]', json_encode($obj));
$this->assertSame(['_class' => 'CM_Frontend_JsonSerializable'], CM_Params::encode($obj));
$obj->setData(['foo' => 1]);
$this->assertEquals('{"foo":1}', json_encode($obj));
$this->assertSame(['_class' => 'CM_Frontend_JsonSerializable', 'foo' => 1], CM_Params::encode($obj));
$obj->setData(['bar' => new CM_Frontend_JsonSerializable(['foo' => 1])]);
$this->assertEquals('{"bar":{"foo":1}}', json_encode($obj));
$this->assertSame(['_class' => 'CM_Frontend_JsonSerializable', 'bar' => ['_class' => 'CM_Frontend_JsonSerializable', 'foo' => 1]], CM_Params::encode($obj));
}
示例9: testProcessLanguageRedirect_parameter
public function testProcessLanguageRedirect_parameter()
{
CMTest_TH::createLanguage('en');
$viewer = CMTest_TH::createUser();
$location = CMTest_TH::createLocation();
$locationEncoded = CM_Params::encode($location, true);
$query = http_build_query(['location' => $locationEncoded]);
$site = CM_Site_Abstract::factory();
$request = new CM_Http_Request_Get('/en/mock5?' . $query, ['host' => $site->getHost()], null, $viewer);
$response = CM_Http_Response_Page::createFromRequest($request, $site, $this->getServiceManager());
$response->process();
$siteUrl = $response->getSite()->getUrl();
$this->assertContains('Location: ' . $siteUrl . '/mock5?' . $query, $response->getHeaders());
}
示例10: fetch
/**
* @return string
*/
public function fetch()
{
$page = $this->_getPage();
$layout = $this->_getLayout();
$page->checkAccessible($this->getRender()->getEnvironment());
$frontend = $this->getRender()->getGlobalResponse();
$viewResponse = new CM_Frontend_ViewResponse($layout);
$viewResponse->setTemplateName('default');
$layout->prepare($this->getRender()->getEnvironment(), $viewResponse);
$viewResponse->set('viewResponse', $viewResponse);
$viewResponse->set('page', $page);
$viewResponse->set('pageTitle', $this->fetchTitle());
$viewResponse->set('pageDescription', $this->fetchDescription());
$viewResponse->set('pageKeywords', $this->fetchKeywords());
$viewResponse->set('renderAdapter', $this);
$environmentDefault = new CM_Frontend_Environment($this->getRender()->getEnvironment()->getSite());
$renderDefault = new CM_Frontend_Render($environmentDefault);
$viewResponse->set('renderDefault', $renderDefault);
$viewResponse->set('languageList', new CM_Paging_Language_Enabled());
$serviceManager = CM_Service_Manager::getInstance();
$options = array();
$options['deployVersion'] = CM_App::getInstance()->getDeployVersion();
$options['renderStamp'] = floor(microtime(true) * 1000);
$options['site'] = CM_Params::encode($this->getRender()->getSite());
$options['url'] = $this->getRender()->getSite()->getUrl();
$options['urlCdn'] = $this->getRender()->getSite()->getUrlCdn();
$options['urlUserContentList'] = $serviceManager->getUserContent()->getUrlList();
$options['language'] = $this->getRender()->getLanguage();
$options['debug'] = CM_Bootloader::getInstance()->isDebug();
$options['stream'] = $serviceManager->getStreamMessage()->getClientOptions();
if ($viewer = $this->getRender()->getViewer()) {
$options['stream']['channel']['key'] = CM_Model_StreamChannel_Message_User::getKeyByUser($viewer);
$options['stream']['channel']['type'] = CM_Model_StreamChannel_Message_User::getTypeStatic();
}
$frontend->getOnloadHeaderJs()->append('cm.options = ' . CM_Params::encode($options, true));
if ($viewer = $this->getRender()->getViewer()) {
$frontend->getOnloadHeaderJs()->append('cm.viewer = ' . CM_Params::encode($viewer, true));
}
$frontend->treeExpand($viewResponse);
$frontend->getOnloadReadyJs()->append('cm.getLayout()._ready();');
$frontend->getOnloadHeaderJs()->append('cm.ready();');
$html = $this->getRender()->fetchViewResponse($viewResponse);
$frontend->treeCollapse();
return $html;
}
示例11: generateConfigInternal
public function generateConfigInternal()
{
$indentation = ' ';
$indent = function ($content) use($indentation) {
return preg_replace('/(:?^|[\\n])/', '$1' . $indentation, $content);
};
$generator = new CM_Config_Generator();
$classTypesConfig = $generator->getConfigClassTypes()->exportAsString('$config');
$actionVerbsConfig = $generator->getConfigActionVerbs()->exportAsString('$config');
foreach ($generator->getClassTypesRemoved() as $classRemoved) {
$this->_getStreamOutput()->writeln('Removed `' . $classRemoved . '`');
}
foreach ($generator->getClassTypesAdded() as $type => $classAdded) {
$this->_getStreamOutput()->writeln('Added `' . $classAdded . '` with type `' . $type . '`');
}
// Create model class types and action verbs config PHP
$configPhp = new CM_File(DIR_ROOT . 'resources/config/internal.php');
$configPhp->ensureParentDirectory();
$configPhp->truncate();
$configPhp->appendLine('<?php');
$configPhp->appendLine('// This is autogenerated config file. You should not change it manually.');
$configPhp->appendLine();
$configPhp->appendLine('return function (CM_Config_Node $config) {');
$configPhp->appendLine($indent($classTypesConfig));
$configPhp->appendLine($indent($actionVerbsConfig));
$configPhp->appendLine('};');
$this->_getStreamOutput()->writeln('Created `' . $configPhp->getPath() . '`');
// Create model class types and action verbs config JS
$configJs = new CM_File(DIR_ROOT . 'resources/config/js/internal.js');
$configJs->ensureParentDirectory();
$configJs->truncate();
$classTypes = $generator->getNamespaceTypes();
$configJs->appendLine('cm.model.types = ' . CM_Params::encode(array_flip($classTypes['CM_Model_Abstract']), true) . ';');
$configJs->appendLine('cm.action.types = ' . CM_Params::encode(array_flip($classTypes['CM_Action_Abstract']), true) . ';');
$this->_getStreamOutput()->writeln('Created `' . $configJs->getPath() . '`');
}
示例12: _getOptions
/**
* @return array
*/
private function _getOptions()
{
$serviceManager = CM_Service_Manager::getInstance();
$options = array();
$options['name'] = CM_App::getInstance()->getName();
$options['deployVersion'] = CM_App::getInstance()->getDeployVersion();
$options['renderStamp'] = floor(microtime(true) * 1000);
$options['site'] = CM_Params::encode($this->getRender()->getSite());
$options['url'] = $this->getRender()->getSite()->getUrl();
$options['urlBase'] = $this->getRender()->getSite()->getUrlBase();
$options['urlCdn'] = $this->getRender()->getSite()->getUrlCdn();
$options['urlUserContentList'] = $serviceManager->getUserContent()->getUrlList();
$options['urlServiceWorker'] = $this->getRender()->getUrlServiceWorker();
if ($this->getRender()->getLanguageRewrite()) {
$options['urlLanguage'] = $this->getRender()->getLanguage();
}
$options['debug'] = CM_Bootloader::getInstance()->isDebug();
$options['stream'] = $serviceManager->getStreamMessage()->getClientOptions();
if ($viewer = $this->getRender()->getViewer()) {
$options['stream']['channel']['key'] = CM_Model_StreamChannel_Message_User::getKeyByUser($viewer);
$options['stream']['channel']['type'] = CM_Model_StreamChannel_Message_User::getTypeStatic();
}
return $options;
}
示例13: _appendConfig
protected function _appendConfig()
{
$config = ['site' => $this->_site];
$this->_js->append('var config = ' . CM_Params::encode($config, true) . ';');
}
示例14: createRequest
/**
* @param string $url
* @param array|null $query
* @param array|null $headers
* @param CM_Frontend_ViewResponse|null $scopeView
* @param CM_Frontend_ViewResponse|null $scopeComponent
* @return CM_Http_Request_Post|\Mocka\AbstractClassTrait
* @throws Mocka\Exception
*/
public function createRequest($url, array $query = null, array $headers = null, CM_Frontend_ViewResponse $scopeView = null, CM_Frontend_ViewResponse $scopeComponent = null)
{
$url = (string) $url;
$query = (array) $query;
if (!$headers) {
$site = CM_Site_Abstract::factory();
$headers = array('host' => $site->getHost());
}
$getViewInfo = function (CM_Frontend_ViewResponse $viewResponse) {
/**
* Simulate sending view-params to client and back (remove any objects)
*/
$viewParams = $viewResponse->getView()->getParams()->getParamsDecoded();
$viewParams = CM_Params::decode(CM_Params::encode($viewParams, true), true);
return array('id' => $viewResponse->getAutoId(), 'className' => get_class($viewResponse->getView()), 'params' => $viewParams);
};
$viewInfoList = array_map($getViewInfo, array_filter(['CM_View_Abstract' => $scopeView, 'CM_Component_Abstract' => $scopeComponent]));
if ($viewInfoList) {
$query['viewInfoList'] = $viewInfoList;
}
$mockClass = $this->mockClass('CM_Http_Request_Post');
$mockClass->mockMethod('getQuery')->set(function () use($query) {
return $query;
});
$mockClass->mockMethod('getIp')->set(function () {
return '16909060';
});
return $mockClass->newInstance([$url, $headers]);
}
示例15: link
/**
* @param string $path
* @param array $params Query parameters
* @param string|null $fragment
* @return string
*/
public static function link($path, array $params = null, $fragment = null)
{
$path = (string) $path;
$fragment = (string) $fragment;
$link = $path;
if (!empty($params)) {
$params = CM_Params::encode($params);
$query = http_build_query($params);
if (strlen($query) > 0) {
$link .= '?' . $query;
}
}
if ('' !== $fragment) {
$link .= '#' . $fragment;
}
return $link;
}