本文整理汇总了PHP中String::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP String::insert方法的具体用法?PHP String::insert怎么用?PHP String::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
function install()
{
if (empty($this->args)) {
return $this->main();
}
$args = $this->args;
if (!empty($args[0]) && $args[0] == 'all') {
$this->_getFiles();
$args = $this->files;
}
if (!empty($this->params['f'])) {
$this->args = $args;
$this->uninstall();
}
foreach ($args as $arg) {
if ($sql = $this->_getFile($arg)) {
$sql = String::insert($sql, array('prefix' => $this->Db->tablePrefix), array('before' => '{', 'after' => '}', 'clean' => true));
$this->Db->query($sql);
$this->out('OK: ' . $arg . ' created');
} else {
$this->out($arg . ' not found');
}
}
$this->out('... done');
}
示例2: _html
protected static function _html($params)
{
$params['message'] = nl2br($params['message']);
$params['trace'] = nl2br($params['trace']);
$error = String::insert(__d('ninja', '<h3>Unexpected Exception::class</h3><p><hr /><strong>:message</strong><hr /><br />:file at line :line</p><h4>Stack Trace:</h4><p>:trace</p>', true), $params);
return $error;
}
示例3: database
/**
* Step 1: database
*
* @return void
*/
public function database()
{
$this->pageTitle = __('Step 1: Database', true);
if (!empty($this->data)) {
// test database connection
if (mysql_connect($this->data['Install']['host'], $this->data['Install']['login'], $this->data['Install']['password']) && mysql_select_db($this->data['Install']['database'])) {
// rename database.php.install
rename(APP . 'config' . DS . 'database.php.install', APP . 'config' . DS . 'database.php');
// open database.php file
App::import('Core', 'File');
$file = new File(APP . 'config' . DS . 'database.php', true);
$content = $file->read();
// write database.php file
if (!class_exists('String')) {
App::import('Core', 'String');
}
$this->data['Install']['prefix'] = '';
//disabled
$content = String::insert($content, $this->data['Install'], array('before' => '{default_', 'after' => '}'));
if ($file->write($content)) {
$this->redirect(array('action' => 'data'));
} else {
$this->Session->setFlash(__('Could not write database.php file.', true));
}
} else {
$this->Session->setFlash(__('Could not connect to database.', true));
}
}
}
示例4: particularidade
/**
* particularidade() Faz em tempo de execução mudanças que sejam imprescindíveis
* para a geração correta do código de barras
* Particularmente para o Banrisul, ele acrescenta ao array OB::$Data, que
* guarda as variáveis que geram o código de barras, uma nova variável
* $DuploDigito, específica desse banco
*
* @version 0.1 28/05/2011 Initial
*/
public function particularidade($object)
{
$codigo = String::insert('21:Agencia:CodigoCedente:NossoNumero041', $object->Data);
$dv1 = Math::Mod10($codigo);
$dv2 = Math::Mod11($codigo . $dv1);
return $object->Data['DuploDigito'] = self::DuploDigito($codigo);
}
示例5: __construct
/**
* http://www.paypalobjects.com/de_DE/html/IntegrationCenter/ic_std-variable-reference.html
* Setup the config based on Config settings
*/
public function __construct(View $View, $settings = array())
{
$this->settings = $this->_defaults;
if ($x = Configure::read('Localization.decimalPoint')) {
$this->settings['dec'] = $x;
}
if ($x = Configure::read('Localization.thousandsSeparator')) {
$this->settings['sep'] = $x;
}
$this->settings = array_merge($this->settings, (array) Configure::read('PayPal'));
if ($this->settings['live']) {
$this->formOptions['server'] = 'https://www.paypal.com';
} else {
$this->formOptions['server'] = 'https://www.sandbox.paypal.com';
}
$data = array('HTTP_HOST' => HTTP_HOST, 'HTTP_BASE' => HTTP_BASE);
$this->formOptions['notify_url'] = String::insert($this->settings['notify_url'], $data, array('before' => '{', 'after' => '}', 'clean' => true));
$this->formOptions['business'] = $this->settings['email'];
$this->formOptions['lc'] = $this->settings['locale'];
$this->formOptions['amount'] = $this->settings['amount'];
$this->formOptions['no_shipping'] = (int) (!$this->settings['shipping']);
$this->formOptions['currency_code'] = $this->settings['currency_code'];
if ($this->settings['cancel_return']) {
$this->formOptions['cancel_return'] = Router::url(null, true);
}
//pr($this->formOptions); die();
parent::__construct($View, $settings);
}
示例6: slug
/**
* Returns a string with all spaces converted to $replacement and non word characters removed.
*
* @param string $string
* @param string $replacement
* @return string
* @static
*/
static function slug($string, $replacement = '-')
{
$string = trim($string);
$map = array('/à|á|å|â|ä/' => 'a', '/è|é|ê|ẽ|ë/' => 'e', '/ì|í|î/' => 'i', '/ò|ó|ô|ø/' => 'o', '/ù|ú|ů|û/' => 'u', '/ç|č/' => 'c', '/ñ|ň/' => 'n', '/ľ/' => 'l', '/ý/' => 'y', '/ť/' => 't', '/ž/' => 'z', '/š/' => 's', '/æ/' => 'ae', '/ö/' => 'oe', '/ü/' => 'ue', '/Ä/' => 'Ae', '/Ü/' => 'Ue', '/Ö/' => 'Oe', '/ß/' => 'ss', '/[^\\w\\s]/' => ' ', '/\\s+/' => $replacement, String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '');
$string = preg_replace(array_keys($map), array_values($map), $string);
return low($string);
}
示例7: read
/**
* read
*
* Bespoke read method to read the api of an external translations api
*
* @param Model $model
* @param array $queryData
* @param mixed $recursive
* @return void
*/
public function read(Model $model, $queryData = array(), $recursive = null)
{
$class = get_class($model);
$config = $class::config();
$url = String::insert($this->config['host'], $queryData['conditions'] + $config);
$result = $this->execute($url);
if (!$result) {
return $result;
}
if ($queryData['fields'] === 'COUNT(*) AS count') {
return count(current($result));
}
$defaults = array_intersect_key($queryData['conditions'] + $config, array_flip(array('domain', 'category', 'locale')));
$return = array();
foreach (current($result) as $key => $value) {
if (is_array($value)) {
foreach ($value as $case => $val) {
$return[] = array($model->alias => array('key' => $key, 'value' => $val, 'plural_case' => $case) + $defaults);
}
} else {
$return[] = array($model->alias => array('key' => $key, 'value' => $value, 'plural_case' => null) + $defaults);
}
}
return $return;
}
示例8: tableEnd
public function tableEnd($data = [], $options = [])
{
$this->mergeOptions('table', $options);
$this->insertData($options, $data);
$this->insertData($options, $options);
return String::insert("</:tag>", $options);
}
示例9: render
/**
* Render one (or more) hidden links.
*
* @param integer $num Number of random and unique links to create.
* @return string Hidden links HTML.
*/
public function render($num = 1)
{
if (!($lnk = Common::read('Security.HttpBL.honeyPot', $this->settings['honeyPot']))) {
return;
}
$all = $this->settings['links'];
$len = rand(4, 16);
$min = array(48, 65, 97);
$max = array(57, 90, 122);
$txt = '';
$res = array();
while (strlen($txt) < $len) {
$rnd = rand(0, 2);
$txt .= chr(rand($min[$rnd], $max[$rnd]));
}
if ($num > count($all)) {
$num = count($all);
}
if (0 == $num) {
return;
}
$rnd = array_rand($all, $num);
foreach ((array) $rnd as $key) {
$res[] = String::insert($all[$key], compact('lnk', 'str'));
}
return implode(' ', $res);
}
示例10: __construct
/**
* Extends model construction
*
* ### Extended functionality:
* - allows use of :ALIAS: in virtual field definitions to be replaced with the
* model's alias
*
* @param mixed $id Sets the model's id on startup
* @param string $table The name of the database table to use
* @param string $ds The datasource connection name
* @see Model::__construct()
*/
public function __construct($id = false, $table = null, $ds = null)
{
parent::__construct($id, $table, $ds);
foreach ($this->virtualFields as &$virtualField) {
$virtualField = String::insert($virtualField, array('ALIAS' => $this->alias), array('after' => ':'));
}
$this->order = String::insert($this->order, array('ALIAS' => $this->alias), array('after' => ':'));
}
示例11: shouldBeWritable
private function shouldBeWritable()
{
foreach ($this->_writableDirectories() as $key => $directory) {
if (is_writable($directory)) {
$this->errors[$key]['message'] = String::insert(__('Warning: :directory is not writable', true), compact('directory'));
$this->errors[$key]['solution'] = String::insert(__('Solution: change :directory permissions to 775', true), compact('directory'));
}
}
}
示例12: run
/**
* Interpolates a string by substituting tokens in a string
*
* Default interpolations:
* - `:webroot` Path to the webroot folder
* - `:model` The current model e.g images
* - `:field` The database field
* - `:filename` The filename
* - `:extension` The extension of the file e.g png
* - `:id` The record id
* - `:style` The current style e.g thumb
* - `:hash` Generates a hash based on the filename
*
* @param string $string The string to be interpolated with data.
* @param string $name The name of the model e.g. Image
* @param int $id The id of the record e.g 1
* @param string $field The name of the database field e.g file
* @param string $style The style to use. Should be specified in the behavior settings.
* @param array $options You can override the default interpolations by passing an array of key/value
* pairs or add extra interpolations. For example, if you wanted to change the hash method
* you could pass `array('hash' => sha1($id . Configure::read('Security.salt')))`
* @return array Settings array containing interpolated strings along with the other settings for the field.
*/
public static function run($string, $name, $id, $field, $filename, $style = 'original', $data = array())
{
$info = new SplFileInfo($filename);
$data += array('webroot' => preg_replace('/\\/$/', '', WWW_ROOT), 'model' => Inflector::tableize($name), 'field' => strtolower($field), 'filename' => $info->getBasename($info->getExtension()), 'extension' => $info->getExtension(), 'id' => $id, 'style' => $style, 'hash' => md5($info->getFilename() . Configure::read('Security.salt')));
foreach (static::$_interpolations as $name => $closure) {
$data[$name] = $closure($info);
}
return String::insert($string, $data);
}
示例13: _results
/**
* Prints calculated results
*
* @param array $times Array of time values
*
* @return void
*/
protected function _results($times)
{
$duration = array_sum($times);
$requests = count($times);
$this->out(String::insert(__d('debug_kit', 'Total Requests made: :requests'), compact('requests')));
$this->out(String::insert(__d('debug_kit', 'Total Time elapsed: :duration (seconds)'), compact('duration')));
$this->out("");
$this->out(String::insert(__d('debug_kit', 'Requests/Second: :rps req/sec'), array('rps' => round($requests / $duration, 3))));
$this->out(String::insert(__d('debug_kit', 'Average request time: :average-time seconds'), array('average-time' => round($duration / $requests, 3))));
$this->out(String::insert(__d('debug_kit', 'Standard deviation of average request time: :std-dev'), array('std-dev' => round($this->_deviation($times, true), 3))));
$this->out(String::insert(__d('debug_kit', 'Longest/shortest request: :longest sec/:shortest sec'), array('longest' => round(max($times), 3), 'shortest' => round(min($times), 3))));
$this->out("");
}
示例14: setUp
public function setUp()
{
parent::setUp();
if (!CakePlugin::loaded('Common')) {
CakePlugin::load('Common');
}
$this->CakeRequest = $this->getMock('CakeRequest', array('is'));
$this->Controller = $this->getMock('TestCommonController', array('redirect', 'referer', 'set'), array($this->CakeRequest, new CakeResponse()));
$this->Controller->Components = $this->getMock('ComponentCollection', array('init'));
$this->Controller->eventManager = $this->getMock('CommonEventManager', array('listPlugins'));
$this->Controller->eventManager->expects($this->any())->method('listPlugins')->will($this->returnValue(array()));
$this->Controller->Session = $this->getMock('SessionComponent', array('setFlash'), array($this->Controller->Components));
$this->Controller->constructClasses();
$this->flashMessage = String::insert($this->Controller->alertMessages['delete.success']['message'], array('modelName' => 'Test'), array('clean' => true));
}
示例15: install
function install($url, $name)
{
$this->formattedOut(String::insert(__d('plugin', "Instalando [u]:plugin[/u]...", true), array('plugin' => $url)));
// $this->_create($name);
$path = $this->params['working'] . DS . 'plugins' . DS . $name;
if ($this->_install($url, $path, $name)) {
$this->formattedOut(__d('plugin', '[fg=black][bg=green] OK [/bg][/fg]', true));
$this->_createUrlFile($url, $path);
$this->_runInstallHook($name);
return true;
} else {
$this->formattedOut(__d('plugin', '[fg=black][bg=red] ERRO [/bg][/fg]', true));
}
return false;
}