本文整理匯總了PHP中Illuminate\Support\Str::lower方法的典型用法代碼示例。如果您正苦於以下問題:PHP Str::lower方法的具體用法?PHP Str::lower怎麽用?PHP Str::lower使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::lower方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fireCity
/**
* Execute for city
*/
private function fireCity()
{
$this->info('** In progress: cities **');
\DB::table('cities')->truncate();
$filename = realpath(dirname(__FILE__) . '/../../../data/france.csv');
$this->info('Filename: ' . $filename);
$fs = new Filesystem();
if (!$fs->exists($filename)) {
$this->error("Data file not found", 1);
return;
}
$resource = @fopen($filename, 'r');
if (!$resource) {
$this->error(error_get_last(), 1);
return;
}
$headers = fgets($resource);
$csv = array();
$now = \Carbon\Carbon::now();
while (null != ($line = fgetcsv($resource, null, ',', '"'))) {
if (array(null) === $line) {
continue;
}
// 0:code postal, 1:insee, 2:article, 3:ville, 4:ARTICLE, 5:VILLE, 6:libelle,
// 7:region, 8:nom region, 9:dep, 10:nom dep, 11:latitude, 12:longitude,
// 13:soundex, 14:metaphone
$csv[] = ['postcode' => $line[0], 'insee' => $line[1], 'article' => $line[2], 'name' => $line[3], 'article_up' => $line[4], 'name_up' => $line[5], 'slug' => Str::slug($line[3]), 'clean' => $line[6], 'region' => Str::lower($line[8]), 'region_code' => $line[7], 'department' => Str::lower($line[10]), 'department_code' => $line[9], 'longitude' => $line[12], 'latitude' => $line[11], 'created_at' => $now, 'updated_at' => $now];
}
$this->info('Number of cities to import: ' . count($csv));
do {
$max = count($csv) > $this->max_per_request ? $this->max_per_request : count($csv);
$slice = array_splice($csv, 0, $max);
\DB::table('cities')->insert($slice);
} while (count($csv));
}
示例2: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->max_per_request = $this->option('max-per-request');
\DB::table('villes')->truncate();
$filename = realpath(dirname(__FILE__) . '/../../../data/france.csv');
$this->info('Filename: ' . $filename);
$fs = new Filesystem();
if (!$fs->exists($filename)) {
$this->error("Data file not found", 1);
return;
}
$resource = @fopen($filename, 'r');
if (!$resource) {
$this->error(error_get_last(), 1);
return;
}
$headers = fgets($resource);
$csv = array();
$now = \Carbon\Carbon::now();
while (null != ($line = fgets($resource))) {
$line = preg_replace('/"/', '', $line);
$line = explode(',', $line);
$csv[] = ['postcode' => $line[0], 'insee' => $line[1], 'name' => $line[3], 'slug' => Str::lower($line[5]), 'region' => Str::lower($line[8]), 'region_code' => $line[7], 'department' => Str::lower($line[10]), 'department_code' => $line[9], 'longitude' => $line[12], 'latitude' => $line[11], 'created_at' => $now, 'updated_at' => $now];
}
$this->info('Nombre de villes a importer: ' . count($csv));
do {
$max = count($csv) > $this->max_per_request ? $this->max_per_request : count($csv);
$slice = array_splice($csv, 0, $max);
\DB::table('villes')->insert($slice);
} while (count($csv));
}
示例3: CleanString
/**
* Limpa a string informada removendo todos os acentos.
*
* @link http://blog.thiagobelem.net/removendo-acentos-de-uma-string-urls-amigaveis
*
* @param string $str
* @param string $slug
*
* @return string
*/
public static function CleanString($str, $slug = false)
{
$str = \Illuminate\Support\Str::lower($str);
/* Códigos de substituição */
$codes = array();
$codes['a'] = array('à', 'á', 'ã', 'â', 'ä');
$codes['e'] = array('è', 'é', 'ê', 'ë');
$codes['i'] = array('ì', 'í', 'î', 'ï');
$codes['o'] = array('ò', 'ó', 'õ', 'ô', 'ö');
$codes['u'] = array('ù', 'ú', 'û', 'ü');
$codes['c'] = array('ç');
$codes['n'] = array('ñ');
$codes['y'] = array('ý', 'ÿ');
/* Substituo os caracteres da string */
foreach ($codes as $key => $values) {
$str = str_replace($values, $key, $str);
}
if ($slug) {
/* Troca tudo que não for letra ou número por um caractere ($slug) */
$str = preg_replace("/[^a-z0-9]/i", $slug, $str);
/* Tira os caracteres ($slug) repetidos */
$str = preg_replace("/" . $slug . "{2,}/i", $slug, $str);
/* Remove os caracteres ($slug) do início/fim da string */
$str = trim($str, $slug);
}
return $str;
}
示例4: handle
/**
* @param UploadAvatar $command
* @return \Flarum\Core\User
* @throws \Flarum\Core\Exception\PermissionDeniedException
*/
public function handle(UploadAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
if ($actor->id !== $user->id) {
$this->assertCan($actor, 'edit', $user);
}
$tmpFile = tempnam($this->app->storagePath() . '/tmp', 'avatar');
$command->file->moveTo($tmpFile);
$file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true);
$this->validator->assertValid(['avatar' => $file]);
$manager = new ImageManager();
$manager->make($tmpFile)->fit(100, 100)->save();
$this->events->fire(new AvatarWillBeSaved($user, $actor, $tmpFile));
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
$mount->delete($file);
}
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$user->changeAvatarPath($uploadName);
$mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$user->save();
$this->dispatchEventsFor($user, $actor);
return $user;
}
示例5: generateCasts
public function generateCasts()
{
$casts = [];
foreach ($this->commandData->inputFields as $field) {
switch ($field['fieldType']) {
case 'integer':
$rule = '"' . Str::lower($field['fieldName']) . '" => "integer"';
break;
case 'double':
$rule = '"' . Str::lower($field['fieldName']) . '" => "double"';
break;
case 'float':
$rule = '"' . Str::lower($field['fieldName']) . '" => "float"';
break;
case 'boolean':
$rule = '"' . Str::lower($field['fieldName']) . '" => "boolean"';
break;
case 'string':
case 'char':
case 'text':
$rule = '"' . Str::lower($field['fieldName']) . '" => "string"';
break;
default:
$rule = '';
break;
}
if (!empty($rule)) {
$casts[] = $rule;
}
}
return $casts;
}
示例6: uploadFile
/**
* Upload provided file and create matching FileRecord object
*
* @param UploadedFile $file
* @param $clientIp
* @return FileRecord
*/
public function uploadFile(UploadedFile $file, $clientIp)
{
$extension = Str::lower($file->getClientOriginalExtension());
$generatedName = $this->generateName($extension);
// Create SHA-256 hash of file
$fileHash = hash_file('sha256', $file->getPathname());
// Check if file already exists
$existingFile = FileRecord::where('hash', '=', $fileHash)->first();
if ($existingFile) {
return $existingFile;
}
// Query previous scans in VirusTotal for this file
if (config('virustotal.enabled') === true) {
$this->checkVirusTotalForHash($fileHash);
}
// Get filesize
$filesize = $file->getSize();
// Check max upload size
$maxUploadSize = config('upload.max_size');
if ($filesize > $maxUploadSize) {
throw new MaxUploadSizeException();
}
// Move the file
$uploadDirectory = config('upload.directory');
$file->move($uploadDirectory, $generatedName);
// Create the record
/** @var FileRecord $record */
$record = FileRecord::create(['client_name' => $file->getClientOriginalName(), 'generated_name' => $generatedName, 'filesize' => $filesize, 'hash' => $fileHash, 'uploaded_by_ip' => $clientIp]);
return $record;
}
示例7: handle
/**
* @param UploadAvatar $command
* @return \Flarum\Core\Users\User
* @throws \Flarum\Core\Exceptions\PermissionDeniedException
*/
public function handle(UploadAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
// Make sure the current user is allowed to edit the user profile.
// This will let admins and the user themselves pass through, and
// throw an exception otherwise.
if ($actor->id !== $user->id) {
$user->assertCan($actor, 'edit');
}
$tmpFile = tempnam(sys_get_temp_dir(), 'avatar');
$command->file->moveTo($tmpFile);
$manager = new ImageManager();
$manager->make($tmpFile)->fit(100, 100)->save();
event(new AvatarWillBeSaved($user, $actor, $tmpFile));
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
$mount->delete($file);
}
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$user->changeAvatarPath($uploadName);
$mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$user->save();
$this->dispatchEventsFor($user);
return $user;
}
示例8: scopeOfType
public function scopeOfType($query, $type)
{
if ($type === null) {
return false;
}
return $query->whereRaw('lower(`type`) like ?', array(Str::lower($type)));
}
示例9: data
/**
* {@inheritdoc}
*/
public function data(ServerRequestInterface $request, Document $document)
{
$this->assertAdmin($request->getAttribute('actor'));
$file = array_get($request->getUploadedFiles(), 'favicon');
$tmpFile = tempnam($this->app->storagePath() . '/tmp', 'favicon');
$file->moveTo($tmpFile);
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
if ($extension !== 'ico') {
$manager = new ImageManager();
$encodedImage = $manager->make($tmpFile)->resize(64, 64, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('png');
file_put_contents($tmpFile, $encodedImage);
$extension = 'png';
}
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath() . '/assets'))]);
if (($path = $this->settings->get('favicon_path')) && $mount->has($file = "target://{$path}")) {
$mount->delete($file);
}
$uploadName = 'favicon-' . Str::lower(Str::quickRandom(8)) . '.' . $extension;
$mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$this->settings->set('favicon_path', $uploadName);
return parent::data($request, $document);
}
示例10: show
/**
* Display the specified Concept.
* GET|HEAD /concepts/{id}
*
* @param Request $request
* @param int $id
* @return Response
*/
public function show(Request $request, $id)
{
$this->conceptRepository->setPresenter(ConceptPresenter::class);
$concept = $this->conceptRepository->apiFindOrFail($id);
//concept has to be transformed
$response = $this->response();
//todo: move this to middleware in order to handle content negotiation
$format = Str::lower($request->get('format', 'json'));
$item = $response->item($concept, new ConceptTransformer());
$resource = new Item($concept, new ConceptTransformer());
$properties = [];
//make sure we're sending utf-8
//sendResponse always sends json
if ('json' == $format) {
foreach ($concept->Properties as $conceptProperty) {
if ($conceptProperty->profileProperty->has_language) {
$properties[$conceptProperty->language][$conceptProperty->ProfileProperty->name] = $conceptProperty->object;
} else {
$properties[$conceptProperty->ProfileProperty->name] = $conceptProperty->object;
}
}
$result = ['uri' => $concept->uri, 'properties' => $properties];
return $this->sendResponse($result, "Concept retrieved successfully");
} else {
//todo: move this to a formatter
foreach ($concept->Properties as $conceptProperty) {
$properties[$conceptProperty->ProfileProperty->name . '.' . $conceptProperty->language] = $conceptProperty;
}
ksort($properties, SORT_NATURAL | SORT_FLAG_CASE);
//build the xml
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><response/>');
$xml->registerXPathNamespace('xml', 'http://www.w3.org/XML/1998/namespace');
$data = $xml->addChild('data');
$data->addAttribute('uri', $concept->uri);
$status = $data->addChild('status', $concept->status->display_name);
$status->addAttribute('uri', $concept->status->uri);
foreach ($properties as $conceptProperty) {
$key = $conceptProperty->ProfileProperty->name;
if ($conceptProperty->profileProperty->has_language) {
$property = $data->addChild($key, $conceptProperty->object);
$property->addAttribute('xml:lang', $conceptProperty->language, 'xml');
} else {
try {
$relatedConcept = $this->conceptRepository->apiFindOrFail($conceptProperty->related_concept_id);
} catch (HttpException $e) {
}
$relatedProperties = [];
foreach ($relatedConcept->Properties as $relConceptProperty) {
$relatedProperties[$relConceptProperty->ProfileProperty->name . '.' . $relConceptProperty->language] = $relConceptProperty;
}
$relKey = array_key_exists('prefLabel.en', $relatedProperties) ? 'prefLabel.en' : 'prefLabel.';
$property = $data->addChild($key, $relatedProperties[$relKey]->object);
$property->addAttribute('uri', $conceptProperty->object);
}
}
$message = $xml->addChild('message', "Concept retrieved successfully");
return Response::make($xml->asXML(), 200)->header('Content-Type', 'application/xml');
}
}
示例11: saveImage
public function saveImage($tmpFile)
{
$dir = date('Ym/d');
$mount = new MountManager(['source' => new Filesystem(new LocalFS(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new LocalFS(public_path('assets/uploads')))]);
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$dir}/{$uploadName}");
return $this->config['urlPrefix'] . 'uploads/' . $dir . '/' . $uploadName;
}
示例12: filterColumns
protected function filterColumns($filters)
{
foreach ($filters as $key => $filter) {
$this->collection = $this->collection->filter(function ($row) use($key, $filter) {
return strpos(Str::lower($row[$key]), Str::lower($filter)) !== false;
});
}
}
示例13: show
/**
* Display the specified resource.
*
* @param $link
* @return \Illuminate\Http\Response
* @internal param int $id
*/
public function show($link)
{
$client = new Client();
$baseUrl = 'https://www.youmagine.com/';
$response = $client->get($baseUrl . 'designs/' . $link);
$code = $response->getBody();
$xs = Selector::loadHTML($code);
// Scrape Youmagine thing information from DOM
try {
$name = $xs->find('/html/body/div[2]/div/h1')->extract();
$description = $xs->find('//*[@id="information"]/div[2]')->extract();
$files = $xs->findAll('//*[@id="documents"]/div/ul/li[*]/div[3]/div[1]/a')->map(function ($node) {
return $node->find('@href')->extract();
});
} catch (NodeNotFoundException $e) {
return response()->view('thing.none');
}
// Get files
$downloadLinks = [];
foreach ($files as $file) {
$response = $client->get($baseUrl . $file, ['allow_redirects' => false]);
$code = $response->getBody();
preg_match('/"(.*?)"/', $code, $downloadLinkMatch);
$downloadLinks[] = $downloadLinkMatch[1];
}
// Get access token
$response = $client->request('POST', 'https://developer.api.autodesk.com/authentication/v1/authenticate', ['form_params' => ['client_id' => env('AUTODESK_CLIENT_ID', ''), 'client_secret' => env('AUTODESK_CLIENT_SECRET', ''), 'grant_type' => 'client_credentials']]);
$authToken = json_decode($response->getBody())->access_token;
// Create a bucket
$bucketKey = Str::lower(Str::random(16));
$response = $client->request('POST', 'https://developer.api.autodesk.com/oss/v2/buckets', ['json' => ['bucketKey' => $bucketKey, 'policyKey' => 'transient'], 'headers' => ['Authorization' => 'Bearer ' . $authToken]]);
$bucketKey = json_decode($response->getBody())->bucketKey;
// Upload to bucket
$bucket = [];
foreach ($downloadLinks as $downloadLink) {
$fileName = pathinfo($downloadLink)['basename'];
$file = fopen(base_path('public/cache/' . $fileName), 'w');
/** @noinspection PhpUnusedLocalVariableInspection */
$response = $client->get($downloadLink, ['sink' => $file]);
$file = fopen(base_path('public/cache/' . $fileName), 'r');
$response = $client->request('PUT', 'https://developer.api.autodesk.com/oss/v2/buckets/' . $bucketKey . '/objects/' . $fileName, ['body' => $file, 'headers' => ['Authorization' => 'Bearer ' . $authToken]]);
$body = json_decode($response->getBody());
$bucket[] = ['filename' => $body->objectKey, 'urn' => $body->objectId];
}
// Set up references
$references = ['master' => $bucket[0]['urn'], 'dependencies' => []];
foreach ($bucket as $file) {
if ($file['filename'] === $bucket[0]['filename']) {
continue;
}
$references['dependencies'][] = ['file' => $file['urn'], 'metadata' => ['childPath' => $file['filename'], 'parentPath' => $bucket[0]['filename']]];
}
$response = $client->post('https://developer.api.autodesk.com/references/v1/setreference', ['json' => $references, 'headers' => ['Authorization' => 'Bearer ' . $authToken]]);
// Register data with the viewing services
$urn = base64_encode($bucket[0]['urn']);
$response = $client->post('https://developer.api.autodesk.com/viewingservice/v1/register', ['json' => ['urn' => $urn], 'headers' => ['Authorization' => 'Bearer ' . $authToken]]);
return response()->view('thing.show', compact('name', 'description', 'urn', 'authToken') + ['pollUrl' => 'https://developer.api.autodesk.com/viewingservice/v1/' . $urn, 'dl' => $downloadLinks[0]]);
}
示例14: check
/**
* @param $value
* @return bool
*/
public function check($value)
{
$store = $this->session->get('captcha');
if ($this->sensitive) {
$value = $this->str->lower($value);
$store = $this->str->lower($store);
}
return $this->hasher->check($value, $store);
}
示例15: check
/**
*
* @param $value
* @return bool
*/
public function check($value)
{
$store = $this->session->get('captcha' . (Input::has('captcha_id') ? '_' . Input::get('captcha_id') : ''));
if ($this->sensitive) {
$value = $this->str->lower($value);
$store = $this->str->lower($store);
}
return $this->hasher->check($value, $store);
}