本文整理汇总了PHP中Phalcon\Text类的典型用法代码示例。如果您正苦于以下问题:PHP Text类的具体用法?PHP Text怎么用?PHP Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerAction
public function registerAction()
{
return $this->handleRequest(function () {
$req = new Request();
if ($req->isPost()) {
$post = json_decode($req->getRawBody());
$a = $this->getUserDocument();
$user = new $a();
$user->salt = Text::random(Text::RANDOM_ALNUM);
$user->password = $this->hash($post->password, $user->salt);
unset($post->password);
$post = (array) $post;
foreach ($post as $key => $value) {
$user->{$key} = $value;
}
$user->save();
$this->session->set('user', $user);
} else {
if ($req->isOptions()) {
return '';
}
}
return $this->jsonOutput($user);
});
}
示例2: build
/**
* Generate view
*/
public function build()
{
$action = Text::uncamelize($this->_options['action']);
$viewName = explode('-', str_replace('_', '-', Text::uncamelize($this->_options['name'])));
if (count($viewName) > 1) {
array_pop($viewName);
}
$viewName = implode('-', $viewName);
$viewDir = $this->_options['directory'] . DIRECTORY_SEPARATOR . $viewName;
$viewPath = $viewDir . DIRECTORY_SEPARATOR . $action . '.volt';
$code = "<?php\n" . Tools::getCopyright() . "\n?>\n";
$code = str_replace("\t", " ", $code);
if (!file_exists($viewPath) || $this->_options['force'] == true) {
if (!is_dir($viewDir)) {
mkdir($viewDir, 0777, true);
chmod($viewDir, 0777);
}
if (!@file_put_contents($viewPath, $code)) {
throw new \Exception("Unable to write to '{$viewPath}'");
}
chmod($viewPath, 0777);
} else {
throw new \Exception("The View '{$action}' already exists");
}
return $viewName;
}
示例3: eager
public function eager($model, $field = null, $localKey = null, $foreignKey = '_id')
{
if ($field == null || $localKey == null) {
$className = strtolower((new \ReflectionClass($model))->getShortName());
if (Text::endsWith($className, 's')) {
$className = substr($className, 0, -1);
}
}
if ($field == null) {
$field = $className;
}
if ($localKey == null) {
$localKey = $className . '_id';
}
$keys = [];
foreach ($this->array as $item) {
if (!in_array($item->{$localKey}, $keys)) {
$keys[] = $item->{$localKey};
}
}
$result = $model::init()->find([$foreignKey => ['$in' => $keys]])->keyBy('_id');
foreach ($this->array as $item) {
$item->setRelation($field, $result[(string) $item->{$localKey}]);
}
return $this;
}
示例4: __invoke
public function __invoke($uri, $query = null, $configKey = 'default')
{
if ($query) {
if (true === is_array($query)) {
$query = implode(',', $query);
}
if (false !== ($pos = strrpos($uri, '.'))) {
$uri = explode('/', $uri);
$fileName = array_pop($uri);
$nameArray = explode('.', $fileName);
$nameExt = array_pop($nameArray);
$nameFinal = array_pop($nameArray);
$nameFinal .= ',' . $query;
array_push($nameArray, $nameFinal, $nameExt);
$fileName = implode('.', $nameArray);
array_push($uri, $fileName);
$uri = implode('/', $uri);
}
}
if (\Phalcon\Text::startsWith($uri, 'http://', false) || \Phalcon\Text::startsWith($uri, 'https://', false)) {
return str_replace('http://api.wallstreetcn.com/', 'http://thumbnail.wallstreetcn.com/thumb/', $uri);
}
$config = self::getDI()->getConfig();
if (isset($config->thumbnail->{$configKey}->baseUri) && ($baseUrl = $config->thumbnail->{$configKey}->baseUri)) {
return $baseUrl . $uri;
}
return $uri;
}
示例5: beforeValidationOnCreate
public function beforeValidationOnCreate()
{
$this->createdAt = time();
if (!$this->slug) {
$this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
}
}
示例6: getMenuOptions
/**
* Return menu options
*
* @return array
*/
public function getMenuOptions()
{
$this->_limitParamValue = 100;
$rows = $this->getColumnData();
$acl = $this->_di->get('acl');
$viewer = $this->_di->get('viewer');
$options = [];
foreach ($rows as $row) {
$option = [];
$option['id'] = $row['id'];
$option['text'] = $row['title'];
if ($row['module'] && $row['controller']) {
if (!$acl->isAllowed($viewer->getRole(), \Engine\Acl\Dispatcher::ACL_ADMIN_MODULE, \Engine\Acl\Dispatcher::ACL_ADMIN_CONTROLLER, '*') && !$acl->isAllowed($viewer->getRole(), \Engine\Acl\Dispatcher::ACL_ADMIN_MODULE, \Engine\Acl\Dispatcher::ACL_ADMIN_CONTROLLER, 'read')) {
if (!$acl->isAllowed($viewer->getRole(), $row['module'], $row['controller'], 'read')) {
continue;
}
}
$option['controller'] = \Phalcon\Text::camelize($row['module']) . ".controller." . \Phalcon\Text::camelize($row['controller']);
$option['moduleName'] = \Phalcon\Text::camelize($row['module']);
$option['controllerName'] = \Phalcon\Text::camelize($row['controller']);
$option['leaf'] = true;
$option['cls'] = 'window-list-item';
$option['iconCls'] = 'window-list-item-icon';
}
$option['qtip'] = $row['description'];
$options[] = $option;
}
return $options;
}
示例7: __get
public function __get($name)
{
if ($this->getDI()->has($name)) {
return parent::__get($name);
}
return $this->{lcfirst(\Phalcon\Text::camelize("get_{$name}"))}();
}
示例8: resetAction
public function resetAction()
{
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql($this->config->database->toArray());
$tables = $connection->listTables();
foreach ($tables as $table) {
$tablename = \Phalcon\Text::camelize($table);
$fd = fopen("{$this->config->application->formsDir}/{$tablename}Form.php", "w");
fwrite($fd, "<?php" . self::NL . self::NL);
// Begin class
fwrite($fd, "class {$tablename}Form {" . self::NL);
$columns = $connection->describeColumns($table);
foreach ($columns as $column) {
if ($column instanceof \Phalcon\Db\Column) {
// Escape if column is primary
if ($column->isPrimary()) {
continue;
}
// Begin method
$columnname = \Phalcon\Text::camelize($column->getName());
fwrite($fd, self::TAB . "private function _{$columnname}() {" . self::NL);
// Write element
$columntype_base = $this->_getBaseType($column->getType());
$columntype = $this->_getType($columntype_base, $column);
fwrite($fd, self::TAB . self::TAB . "\$element = new \\Phalcon\\Forms\\Element\\{$columntype}(\"{$columnname}\");" . self::NL);
fwrite($fd, self::TAB . self::TAB . "\$element->setLabel(\"{$columnname}\");" . self::NL);
// Add empty selection for select fields
if ($columntype == "Select") {
fwrite($fd, self::TAB . self::TAB . "\$element->setOptions([]);" . self::NL);
}
// Add validator on text fields
if ($columntype == "Text" && $column->getSize() > 0) {
fwrite($fd, self::TAB . self::TAB . "\$element->addValidator(new \\Phalcon\\Validation\\Validator\\StringLength([" . self::NL);
fwrite($fd, self::TAB . self::TAB . self::TAB . "\"max\" => {$column->getSize()}" . self::NL);
fwrite($fd, self::TAB . self::TAB . "]));" . self::NL);
}
// End method
fwrite($fd, self::TAB . self::TAB . "return \$element;" . self::NL);
fwrite($fd, self::TAB . "}" . self::NL);
}
}
// Final method : construction of the form
fwrite($fd, self::TAB . "public function setFields() {" . self::NL);
foreach ($columns as $column) {
if ($column instanceof \Phalcon\Db\Column) {
if ($column->isPrimary()) {
continue;
}
$columnname = \Phalcon\Text::camelize($column->getName());
fwrite($fd, self::TAB . self::TAB . "\$this->add(\$this->_{$columnname}());" . self::NL);
}
}
fwrite($fd, self::TAB . "}" . self::NL);
// End class
fwrite($fd, "}" . self::NL . self::NL);
fclose($fd);
}
$this->view->disable();
echo "done!";
return FALSE;
}
示例9: env
/**
* Gets the value of an environment variable. Supports boolean, empty and null.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return value($default);
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (Text::startsWith($value, '"') && Text::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
示例10: dumpModulesFromVendor
/**
* Extract Vegas modules from composer vegas-cmf vendors.
*
* @param $modulesList
* @return mixed
*/
private function dumpModulesFromVendor(array &$modulesList)
{
if (!file_exists(APP_ROOT . '/composer.json')) {
return $modulesList;
}
$fileContent = file_get_contents(APP_ROOT . DIRECTORY_SEPARATOR . 'composer.json');
$json = json_decode($fileContent, true);
$vendorDir = realpath(APP_ROOT . (isset($json['config']['vendor-dir']) ? DIRECTORY_SEPARATOR . $json['config']['vendor-dir'] : DIRECTORY_SEPARATOR . 'vendor'));
$vendorDir .= DIRECTORY_SEPARATOR . 'vegas-cmf';
$directoryIterator = new \DirectoryIterator($vendorDir);
foreach ($directoryIterator as $libDir) {
if ($libDir->isDot()) {
continue;
}
//creates path to Module.php file
$moduleSettingsFile = implode(DIRECTORY_SEPARATOR, [$vendorDir, $libDir, 'module', self::MODULE_SETTINGS_FILE]);
if (!file_exists($moduleSettingsFile)) {
continue;
}
$baseName = Text::camelize($libDir->getBasename());
if (!isset($modulesList[$baseName])) {
$modulesList[$baseName] = ['className' => $baseName . '\\' . pathinfo(self::MODULE_SETTINGS_FILE, PATHINFO_FILENAME), 'path' => $moduleSettingsFile];
}
}
return $modulesList;
}
示例11: translate
public function translate($idElement, $key, $default)
{
$this->message = "";
if (Text::startsWith($this->language, "en", true)) {
return $default;
}
$trans = $this->translations->filter(function ($object) use($idElement, $key) {
if (Text::startsWith($this->language, $object->getLang(), true) && $object->getIdElement() == $idElement && $object->getName() == $key) {
return $object;
}
});
if (is_array($trans)) {
if (sizeof($trans) > 0) {
$trans = $trans[0];
} else {
$this->message = $this->translate(1, "translate.info", "");
return $default;
}
}
if (is_a($trans, "Translation")) {
return $trans->getText();
} else {
$this->message = $this->translate(1, "translate.info", "");
return $default;
}
}
示例12: getSource
public function getSource()
{
$nowClassName = get_class($this);
$trueClassName = str_replace(__NAMESPACE__ . '\\', '', $nowClassName);
$trueClassName = Text::uncamelize($trueClassName);
return DB_PREFIX . strtolower($trueClassName);
}
示例13: pageAction
public function pageAction()
{
$pageSlug = $this->getUriParameter('pageSlug');
$pageTitle = \Phalcon\Text::camelize($pageSlug);
$this->tag->setTitle($pageTitle);
$this->view->pick('pages/' . $pageSlug);
}
示例14: resolve
/**
* {@inheritdoc}
*/
public function resolve(&$value)
{
if (is_string($value) && strlen($value) > 0) {
$value = \Phalcon\Text::upper($value);
}
return $value;
}
示例15: initialize
public function initialize()
{
foreach (self::$routes as $route => $controller) {
$name = str_replace('_', '-', Text::uncamelize($controller));
$this->add($route, $controller)->setName($name);
}
}