本文整理汇总了PHP中Str::ends_with方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::ends_with方法的具体用法?PHP Str::ends_with怎么用?PHP Str::ends_with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::ends_with方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
public function view()
{
$owners = [];
foreach (Owner::find() as $id => $owner) {
if (count($owner['pets']) > 0) {
$owners[$id] = $owner;
$owners[$id]['active'] = Str::ends_with($_SERVER['REQUEST_URI'], 'pets/' . $owner['_id']);
}
}
$this->set('owners', $owners);
}
示例2: run
public function run($fonts = null)
{
if (\Cli::option('help', \Cli::option('h', false)) or empty($fonts)) {
empty($fonts) and \Cli::error(\Cli::color('No font given.', 'red'));
return static::help();
}
$pdf = new \TCPDF();
$type = \Cli::option('type', \Cli::option('t', ''));
$enc = \Cli::option('enc', \Cli::option('e', ''));
$flags = \Cli::option('flags', \Cli::option('f', 32));
$outpath = \Cli::option('outpath', \Cli::option('o', K_PATH_FONTS));
$platid = \Cli::option('platid', \Cli::option('p', 3));
$encid = \Cli::option('encid', \Cli::option('n', 1));
$addcbbox = \Cli::option('addcbbox', \Cli::option('b', false));
$link = \Cli::option('link', \Cli::option('l', false));
$path = \Cli::option('path', \Cli::option('p'));
if (!is_null($path) and !\Str::ends_with($path, DS)) {
$path .= DS;
}
$fonts = explode(',', $fonts);
foreach ($fonts as $font) {
if (strpos($font, DS) === false and !is_null($path)) {
$font = $path . $font;
}
$fontfile = realpath($font);
$fontname = \TCPDF_FONTS::addTTFfont($fontfile, $type, $enc, $flags, $outpath, $platid, $encid, $addcbbox, $link);
if ($fontname == false) {
$errors = true;
\Cli::error(\Cli::color($font . ' cannot be added.', 'red'));
} else {
\Cli::write(\Cli::color($font . ' added.', 'green'));
}
}
if (!empty($errors)) {
\Cli::error(\Cli::color('Process finished with errors.', 'red'));
} else {
\Cli::write(\Cli::color('Process successfully finished.', 'green'));
}
}
示例3: call_user_func
$body = call_user_func($callback, $body);
}
}
}
$is_truncated = false;
if (!$options['is_detail']) {
if ($options['line']) {
list($body, $is_truncated4line) = Util_string::truncate4line($body, $options['line'], '', $options['is_rtrim'], $options['encoding']);
}
if ($options['width']) {
list($body, $is_truncated4count) = Util_string::truncate($body, $options['width'], '', true);
}
$is_truncated = $is_truncated4line || $is_truncated4count;
}
if ($is_truncated && $options['trimmarker']) {
if (!Str::ends_with($body, "\n")) {
$body .= ' ';
}
$body .= $options['trimmarker'];
}
?>
<div><?php
echo $body;
?>
</div>
<?php
if ($is_truncated && $options['read_more_uri']) {
?>
<div class="bodyMore"><?php
echo Html::anchor($options['read_more_uri'], 'もっとみる');
?>
示例4: package
public static function package($args, $build = true)
{
$name = str_replace(array('/', '_', '-'), '', \Str::lower(array_shift($args)));
$class_name = ucfirst($name);
$vcs = \Cli::option('vcs', \Cli::option('v', false));
$path = \Cli::option('path', \Cli::option('p', PKGPATH));
$drivers = \Cli::option('drivers', \Cli::option('d', ''));
if (empty($name)) {
throw new \Exception('No package name has been provided.');
}
if (!in_array($path, \Config::get('package_paths')) and !in_array(realpath($path), \Config::get('package_paths'))) {
throw new \Exception('Given path is not a valid package path.');
}
\Str::ends_with($path, DS) or $path .= DS;
$path .= $name . DS;
if (is_dir($path)) {
throw new \Exception('Package already exists.');
}
if ($vcs) {
$output = <<<COMPOSER
{
\t"name": "fuel/{$name}",
\t"type": "fuel-package",
\t"description": "{$class_name} package",
\t"keywords": [""],
\t"homepage": "http://fuelphp.com",
\t"license": "MIT",
\t"authors": [
\t\t{
\t\t\t"name": "AUTHOR",
\t\t\t"email": "AUTHOR@example.com"
\t\t}
\t],
\t"require": {
\t\t"composer/installers": "~1.0"
\t},
\t"extra": {
\t\t"installer-name": "{$name}"
\t}
}
COMPOSER;
static::create($path . 'composer.json', $output);
$output = <<<README
# {$class_name} package
Here comes some description
README;
static::create($path . 'README.md', $output);
}
if (!empty($drivers)) {
$drivers === true or $drivers = explode(',', $drivers);
$output = <<<CLASS
<?php
namespace {$class_name};
class {$class_name}Exception extends \\FuelException {}
class {$class_name}
{
\t/**
\t * loaded instance
\t */
\tprotected static \$_instance = null;
\t/**
\t * array of loaded instances
\t */
\tprotected static \$_instances = array();
\t/**
\t * Default config
\t * @var array
\t */
\tprotected static \$_defaults = array();
\t/**
\t * Init
\t */
\tpublic static function _init()
\t{
\t\t\\Config::load('{$name}', true);
\t}
\t/**
\t * {$class_name} driver forge.
\t *
\t * @param\tstring\t\t\t\$instance\t\tInstance name
\t * @param\tarray\t\t\t\$config\t\tExtra config array
\t * @return {$class_name} instance
\t */
\tpublic static function forge(\$instance = 'default', \$config = array())
\t{
\t\tis_array(\$config) or \$config = array('driver' => \$config);
\t\t\$config = \\Arr::merge(static::\$_defaults, \\Config::get('{$name}', array()), \$config);
\t\t\$class = '\\{$class_name}\\{$class_name}_' . ucfirst(strtolower(\$config['driver']));
//.........这里部分代码省略.........
示例5: truncate4line
public static function truncate4line($body, $line, $trimmarker = '...', $is_rtrim = true, $encoding = null)
{
$encoding or $encoding = \Fuel::$encoding;
$is_truncated = false;
if (!$line) {
return array($body, $is_truncated);
}
if (!($pos = Util_string::mb_strpos_n($body, "\n", $line, $encoding))) {
return array($body, $is_truncated);
}
$is_truncated = $pos < mb_strlen($body, $encoding);
$body = mb_substr($body, 0, $pos, $encoding);
if ($is_truncated) {
if ($is_rtrim) {
$body = rtrim($body);
}
if ($trimmarker) {
if (!Str::ends_with($body, "\n")) {
$body .= ' ';
}
$body .= $trimmarker;
}
}
return array($body, $is_truncated);
}
示例6: test_ends_with
/**
* Test for Str::ends_with()
*
* @test
*/
public function test_ends_with()
{
$string = 'HELLO WORLD';
$output = Str::ends_with($string, 'WORLD');
$this->assertTrue($output);
$output = Str::ends_with($string, 'world');
$this->assertFalse($output);
$output = Str::ends_with($string, 'world', true);
$this->assertTrue($output);
}
示例7: process_migration
protected static function process_migration($scaffold, $module, $module_path)
{
/*
* Migration files are a special case because the
* original and destination file names are not
* constant. Depending on the existing migrations
* files, we could have to move the
* 003_create_category.php migration file from the
* application to the 002_create_category.php
* migration file in the module.
* Moreover, we don't need to do any replacements
* here.
*/
$app_migrations_path = APPPATH . 'migrations';
$module_migrations_path = $module_path . 'migrations';
// Getting the list of migrations files in the
// application.
$app_migrations = \File::read_dir($app_migrations_path);
// If the migration directory doesn't exists in the
// module, we create it.
if (!file_exists($module_migrations_path)) {
mkdir($module_migrations_path, static::$folder_permissions, true);
}
$migration_filename_end = '_create_' . \Inflector::pluralize($scaffold) . '.php';
$module_migrations = \File::read_dir($module_migrations_path);
// Searching if the migration file already exists
$module_migration_filename = null;
$already_exists = false;
foreach ($module_migrations as $module_migration) {
if (\Str::ends_with($module_migration, $migration_filename_end)) {
$module_migration_filename = $module_migration;
$already_exists = true;
break;
}
}
// If it doesn't, the migration file name generated
if (is_null($module_migration_filename)) {
// Finding the destination migration file name.
$nb_module_migrations = count($module_migrations);
$module_migration_number = str_pad($nb_module_migrations + 1, 3, '0', STR_PAD_LEFT);
$module_migration_filename = $module_migration_number . $migration_filename_end;
}
// Finding the original migration file
foreach ($app_migrations as $app_migration) {
if (\Str::ends_with($app_migration, $migration_filename_end)) {
// Moving it to the destination file.
$migration_from = $app_migrations_path . DS . $app_migration;
$migration_to = $module_migrations_path . DS . $module_migration_filename;
/*
* If it already exists, the migration is
* not overriden except if the force option
* is set.
*/
if (!$already_exists || static::$force) {
\Cli::write("\tCreating migration: " . $migration_to, 'green');
file_put_contents($migration_to, file_get_contents($migration_from));
}
\Cli::write("\tDeleting migration: " . $migration_from, 'green');
\File::delete($migration_from);
break;
}
}
}
示例8: addFileToZip
/**
* Add file to zip
*
* @param string $filename
* @param string|null $localname Where will be added to the file in the zip
*
* @return bool
*/
private function addFileToZip($filename, $localname = null)
{
if ($localname === null) {
$localname . basename($filename);
}
if (empty($localname)) {
$localname = basename($filename);
} elseif (!empty($localname) && !\Str::ends_with($localname, '/')) {
$localname .= '/' . basename($filename);
}
$result = $this->_zip_archive->addFile($filename, $localname);
return $result;
}