本文整理汇总了PHP中Illuminate\Support\Str::endsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::endsWith方法的具体用法?PHP Str::endsWith怎么用?PHP Str::endsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::endsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeTrailingSlash
protected function removeTrailingSlash($path)
{
if (Str::endsWith($path, '/') && $path != '/') {
unset($path[strlen($path) - 1]);
}
return $path;
}
示例2: 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 (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
示例3: getConfigPathFile
public final function getConfigPathFile($file)
{
if (!Str::endsWith($file, '.php')) {
$file = $file . '.php';
}
return config_path($this->getConfigShortPath() . '/' . $file);
}
示例4: postProcessRules
/**
* @param array $rules
*
* @return callable[]
* @throws Exception
*/
public function postProcessRules(array &$rules)
{
$postProcessors = [];
$hasArrayRule = false;
foreach ($rules as $attribute => &$attributeRules) {
foreach ($attributeRules as $ruleIndex => &$ruleData) {
list($ruleName, $ruleParams) = $this->parseRule($ruleData);
if ('array' == $ruleName) {
$hasArrayRule = true;
}
if (!Str::endsWith($ruleName, '[]')) {
continue;
}
$ruleName = substr($ruleName, 0, -2);
if (Str::endsWith($ruleName, '[]')) {
throw new Exception("Error in rule '{$ruleName}' for attribute '{$attribute}'. Multidimensional arrays are not currently supported");
}
if ($hasArrayRule) {
unset($attributeRules[$ruleIndex]);
} else {
$ruleData = ['array', []];
}
$postProcessors[] = function (Validator $validator) use($attribute, $ruleName, $ruleParams) {
$validator->each($attribute, [$ruleName . ':' . implode(', ', $ruleParams)]);
};
}
}
return $postProcessors;
}
示例5: replaceParagraphsByBr
private function replaceParagraphsByBr($html)
{
$html = preg_replace("/<p[^>]*?>/", "", $html);
$html = trim(str_replace("</p>", "<br />", $html));
if (Str::endsWith($html, "<br />")) {
$html = substr($html, 0, strlen($html) - strlen("<br />"));
}
return $html;
}
示例6: purge
/**
* Purges confirmation fields from the attributes.
*
* @return void
*/
public function purge()
{
foreach ($this->attributes as $k => $attr) {
// If the attribute ends in "_confirmation"
if (Str::endsWith($k, '_confirmation')) {
// We unset the value
unset($this->attributes[$k]);
}
}
}
示例7: get
/**
* Get unique random filename with $extenstion within $path directory
* @param string $path
* @param string $extension
* @return string
*/
public static function get($path, $extension)
{
if (!Str::endsWith($path, '/')) {
$path .= '/';
}
do {
$name = Str::random(10) . '.' . $extension;
} while (file_exists($path . $name));
return $name;
}
示例8: loadFilesRecursively
protected function loadFilesRecursively($path)
{
foreach ($this->files->files($path) as $file) {
if (Str::endsWith($file, '.php')) {
require_once $file;
}
}
foreach ($this->files->directories($path) as $directory) {
$this->loadFilesRecursively($directory);
}
}
示例9: bladeDirective
public function bladeDirective($name, $class, $method)
{
$this->getBlade()->directive($name, function ($expression) use($class, $method) {
// for Laravel 5.2 and lower
$expression = isset($expression) ? $expression : '()';
if (Str::startsWith($expression, '(') && Str::endsWith($expression, ')')) {
$expression = mb_substr($expression, 1, -1, 'UTF-8');
}
return "<?=app({$class}::class)->{$method}({$expression});?>";
});
}
示例10: isAcademicEmail
private static function isAcademicEmail($mail)
{
//TODO add academic domains
$acdomains = array('auth.gr');
$email = explode('@', $mail);
$domain = $email[1];
if (Str::endsWith($domain, $acdomains)) {
return true;
}
return false;
}
示例11: register
/**
* Registers specified class as a validation rule to Laravel Validator
*
* @param $className
*/
public static function register($className)
{
$ruleName = Str::snake(class_basename($className));
if (Str::endsWith($ruleName, self::RULE_NAME_SUFFIX)) {
$ruleName = substr($ruleName, 0, -strlen(self::RULE_NAME_SUFFIX));
}
static::$registry[$ruleName] = $className;
/** @var Factory $validatorFactory */
$validatorFactory = Application::getInstance()->make(Factory::class);
$validatorFactory->extend($ruleName, $className . '@validate');
$validatorFactory->replacer($ruleName, $className . '@replace');
}
示例12: testStringEndsWith
public function testStringEndsWith()
{
$str = 'Laravel is really awesome';
$result = Str::endsWith($str, 'awesome');
$this->assertEquals($result, true);
$str = 'Laravel is really awesome';
$result = Str::endsWith($str, 'Awesome');
$this->assertEquals($result, false);
$str = 'Laravel is really awesome';
$result = Str::endsWith($str, ['Awesome', 'awesome']);
$this->assertEquals($result, true);
}
示例13: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$packageName = 'laravel-deploy';
$basePath = \Config::get("{$packageName}::base-path");
$appName = \Config::get("{$packageName}::application-name");
$basePath = \Config::get("{$packageName}::base-path");
$branch = \Config::get("{$packageName}::branch");
$gitUrl = \Config::get("{$packageName}::git");
$ownership = \Config::get("{$packageName}::ownership");
$remoteEnv = \Config::get("{$packageName}::remote-env", "production");
if (!$appName) {
$this->error("Please configure application-name inside configuration file. Use `php artisan config:publish quiborgue/{$packageName}` to create it.");
return;
}
if (!$gitUrl) {
$this->error("Please configure git inside configuration file. Use `php artisan config:publish quiborgue/{$packageName}` to create it.");
return;
}
$release = Carbon::now()->getTimestamp();
$appPath = "{$basePath}/{$appName}";
$releasePath = "{$appPath}/releases/{$release}";
$writables = array();
$shareds = array('app/storage/sessions/', 'app/storage/logs/', 'app/database/production.sqlite');
$commandList = array();
$commandList[] = "export LARAVEL_ENV={$remoteEnv}";
$commandList[] = "mkdir -p {$releasePath}";
$commandList[] = "git clone --depth 1 -b {$branch} \"{$gitUrl}\" {$releasePath}";
$commandList[] = "cd {$releasePath}";
$commandList[] = "composer install --no-interaction --no-dev --prefer-dist";
foreach ($shareds as $shared) {
$sharedPath = "{$appPath}/shared/{$shared}";
if (Str::endsWith($shared, "/")) {
$sharedPath = rtrim($sharedPath, "/");
$shared = rtrim($shared, "/");
$commandList[] = "mkdir -p {$sharedPath}";
} else {
$sharedDirPath = dirname($sharedPath);
$commandList[] = "mkdir -p {$sharedDirPath}";
// $commandList[] = "touch $sharedPath";
}
$commandList[] = "rm -rf {$releasePath}/{$shared}";
$commandList[] = "ln -s {$sharedPath} {$releasePath}/{$shared}";
}
foreach ($writables as $writable) {
$commandList[] = "chmod -R 755 {$releasePath}/{$writable}";
$commandList[] = "chmod -R g+s {$releasePath}/{$writable}";
$commandList[] = "chown -R {$ownership} {$releasePath}/{$writable}";
}
$commandList[] = "rm -f {$appPath}/current";
$commandList[] = "ln -s {$releasePath} {$appPath}/current";
$commandList[] = "php artisan migrate --force";
$this->runCommandList($commandList);
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string $target_field
* @param string $source_field
* @param string $pattern
* @return mixed
*/
public function handle($request, Closure $next, $target_field, $source_field = null, $pattern = '/\\s*([\\t\\v]|\\s*,\\s*)+\\s*/')
{
//Commas can’t be used by \Illuminate\Pipeline\Pipeline::parsePipeString
$pattern = str_replace('COMMA', ',', $pattern);
if (!Str::startsWith($pattern, '/') or !Str::endsWith($pattern, '/') or $pattern == '/') {
$pattern = '/' . preg_quote($pattern, '/') . '/';
}
if (empty($source_field)) {
$source_field = $target_field;
}
$this->setRequestInput($request, $target_field, preg_split($pattern, $request->input($source_field)));
return $next($request);
}
示例15: addFolder
public function addFolder()
{
$folder = Input::get('name');
$path = Input::get('path');
if (Media::checkPath($path)) {
if (Str::endsWith($path, "/")) {
$newFolder = $path . $folder;
} else {
$newFolder = $path . "/" . $folder;
}
return response()->json(mkdir($newFolder));
}
return response()->json(false);
}