本文整理匯總了PHP中Illuminate\Support\Facades\File::glob方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::glob方法的具體用法?PHP File::glob怎麽用?PHP File::glob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Facades\File
的用法示例。
在下文中一共展示了File::glob方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getMigrationCurrentName
/**
* If the file exist retrieve the same name
*
* @param $name
* @return null
*/
private function getMigrationCurrentName($name)
{
$base = database_path('migrations/****_**_**_******_' . $name . '.php');
$source = File::glob($base);
if ($source) {
return basename($source[0], ".php");
}
return null;
}
示例2: testDeleteMigrations
/**
* Publish migrations for testing
* @depends testItHasMigrated
*/
public function testDeleteMigrations()
{
$base = database_path('migrations/****_**_**_******_create_countries_table.php');
$source = File::glob($base);
$route = $source[0];
File::delete($route);
$success = File::exists($route);
$this->assertFalse($success);
}
示例3: findFiles
/**
* @param $path
* @param $fileName
* @return array
*/
public function findFiles($path, $fileName)
{
if ($path == '') {
$path = base_path();
}
if (File::isDirectory($path)) {
$path = str_finish($path, '/');
}
$path .= $fileName;
return File::glob($path);
}
示例4: handle
/**
* Execute the command.
*/
public function handle()
{
// Get the compiled files
$compiledFiles = File::glob(base_path('scaffolder-config/cache/*.scf'));
// Start progress bar
$this->output->progressStart(count($compiledFiles));
foreach ($compiledFiles as $compiledFile) {
File::delete($compiledFile);
// Advance progress
$this->output->progressAdvance();
}
// Finish progress
$this->output->progressFinish();
$this->info('Cache cleared');
}
示例5: checkFiles
/**
* @param Request $request
*/
private function checkFiles(Request $request)
{
$fileNameWithoutExt = str_random(32);
$fileName = $fileNameWithoutExt . '.' . $request->file('file')->getClientOriginalExtension();
$directory = public_path() . '/resources/uploads/';
$request->file('file')->move($directory, $fileName);
$zipper = new Zipper();
File::makeDirectory($directory . $fileNameWithoutExt);
$zipper->make($directory . $fileName)->extractTo($directory . $fileNameWithoutExt);
$createdProductCategories = [];
$dataTransferResultErrors = ['productCategories' => array(), 'productLines' => array(), 'products' => array(), 'otherErrors' => array()];
$dataTransferResultWarnings = ['productCategories' => array(), 'productLines' => array(), 'products' => array()];
$findResults = File::glob($directory . $fileNameWithoutExt . '/img/');
if (count($findResults) == 0) {
array_push($dataTransferResultErrors['otherErrors'], 'отсутствует папка с изображениями img');
}
$findResults = File::glob($directory . $fileNameWithoutExt . '/products.xlsx');
if (count($findResults) == 0) {
array_push($dataTransferResultErrors['otherErrors'], 'отсутствует файл Excel версии 2007 и выше. Убедитесь, что структура архива соотвествует образцу. Обратите внимание, что папка img и файл Excel находятся в корне архива, а не в папке, которая находится в корне архива');
}
if (count($dataTransferResultErrors['otherErrors'])) {
Session::put('dataTransferResult.Errors', $dataTransferResultErrors);
Session::put('dataTransferResult.Warnings', $dataTransferResultWarnings);
File::delete($directory . $fileName);
File::deleteDirectory($directory . $fileNameWithoutExt);
return;
}
Excel::selectSheets('Категории')->load($directory . $fileNameWithoutExt . '/products.xlsx', function ($reader) use($directory, $fileNameWithoutExt, $createdProductCategories, $dataTransferResultErrors, $dataTransferResultWarnings, $fileName, $request) {
$productCategories = [];
foreach ($reader->toArray() as $row) {
if ($row['nomer'] == null) {
continue;
}
array_push($productCategories, $row['nomer']);
$imagePattern = '/img/product-category-' . $row['nomer'];
$findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*');
if (count($findResults) == 0) {
$dataTransferResultErrors['productCategories'][$row['nomer']] = 'У категории с номером ' . $row['nomer'] . ' отсутствует изображение: ' . $imagePattern;
}
if ($row['nomer'] <= ProductCategory::max('id')) {
$dataTransferResultErrors['productCategories'][$row['nomer'] . ' дублирование данных (категория)'] = 'Категория с номером ' . $row['nomer'] . ' возможно уже присутствует в базe. Проверьте условие минимальности номера категории';
}
}
Excel::selectSheets('Линейки продукции')->load($directory . $fileNameWithoutExt . '/products.xlsx', function ($reader) use($directory, $fileNameWithoutExt, $createdProductCategories, $dataTransferResultErrors, $dataTransferResultWarnings, $fileName, $productCategories, $request) {
$productLines = [];
foreach ($reader->toArray() as $row) {
if ($row['nomer'] == null) {
continue;
}
array_push($productLines, $row['nomer']);
if (!in_array($row['kategoriya'], $productCategories) && ProductCategory::find($row['kategoriya']) == null) {
$dataTransferResultErrors['productLines'][$row['nomer'] . ' целостость данных (категория)'] = 'У линейки продукции указана несущестующая категория: ' . $row['kategoriya'];
}
$imagePattern = '/img/product-line-' . $row['nomer'];
$findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*');
if (count($findResults) == 0) {
$dataTransferResultErrors['productLines'][$row['nomer']] = 'У линейки продукции с номером ' . $row['nomer'] . ' отсутствует изображение: ' . $imagePattern;
}
if ($row['nomer'] <= ProductLine::max('id')) {
$dataTransferResultErrors['productLines'][$row['nomer'] . ' дублирование данных (линейка продукции)'] = 'Линейка продукции с номером ' . $row['nomer'] . ' возможно уже присутствует в базe. Проверьте условие минимальности номера линейки продукции';
}
}
Excel::selectSheets('Продукция')->load($directory . $fileNameWithoutExt . '/products.xlsx', function ($reader) use($directory, $fileNameWithoutExt, $createdProductCategories, $dataTransferResultErrors, $dataTransferResultWarnings, $fileName, $productLines, $productCategories, $request) {
foreach ($reader->toArray() as $row) {
if ($row['nomer'] == null) {
continue;
}
if ($row['kategoriya'] == null && $row['lineyka_produktsii'] == null) {
$dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (нет привязки)'] = 'У продукции должна быть либо категория либо линейка продукции';
}
if ($row['kategoriya'] != null && $row['lineyka_produktsii'] != null) {
$dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (плохая привязка)'] = 'У продукции не может быть одновременно категории и линейка продукции';
}
if ($row['kategoriya'] != null && !in_array($row['kategoriya'], $productCategories) && ProductCategory::find($row['kategoriya']) == null) {
$dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (категория)'] = 'У продукции указана несущестующая категория: ' . $row['kategoriya'];
}
if ($row['lineyka_produktsii'] != null && !in_array($row['lineyka_produktsii'], $productLines) && ProductLine::find($row['lineyka_produktsii']) == null) {
$dataTransferResultErrors['products'][$row['nomer'] . ' целостость данных (категория)'] = 'У продукции указана несущестующая категория: ' . $row['lineyka_produktsii'];
}
$imagePattern = '/img/product-' . $row['nomer'];
$findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*');
if (count($findResults) == 0) {
$dataTransferResultErrors['products'][$row['nomer']] = 'У продукции с номером ' . $row['nomer'] . ' отсутсвует основное изображение: ' . $imagePattern;
}
$imagePattern = '/img/product-' . $row['nomer'] . '-color-';
$findResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*');
$notFoundProductColorImages = [];
foreach ($findResults as $findResult) {
$colorNumber = substr($findResult, strpos($findResult, 'color') + 6, strpos($findResult, '.') - strpos($findResult, 'color') - 6);
$imagePattern = '/img/product-' . $row['nomer'] . '-image-' . $colorNumber;
$findProductColorImageResults = File::glob($directory . $fileNameWithoutExt . $imagePattern . '*');
if (count($findProductColorImageResults) == 0) {
array_push($notFoundProductColorImages, $imagePattern);
}
}
if (count($notFoundProductColorImages) > 0) {
$dataTransferResultWarnings['products'][$row['nomer'] . ' предупреждение об изображении для палитры'] = 'У продукции с номером ' . $row['nomer'] . ' отсутсвуют изображения продукта для цветовой палитры: ';
//.........這裏部分代碼省略.........
示例6: restoreDatabase
public function restoreDatabase(Request $request)
{
// TODO: put this in the constants file
$path = storage_path() . "/app/Backups/";
$password = $request->password;
$serial_num = sprintf('%08d', $request->serial_num);
if (Hash::check($password, Auth::user()->password)) {
// Search for the required file. Returns matching files.
$sqldump = File::glob($path . $serial_num . '_*.sql');
// Surround the expression with quotes for Shell execution
$formattedString = escapeshellarg($sqldump[0]);
if ($sqldump == false) {
abort(404);
} else {
// TODO: Remove the comment and change the DB before deploying.
// THIS LINE IS DANGEROUS. THEREFORE IT REMAINS COMMENTED DURING PRODUCTION.
// AlSO THE DB THE FILE RESTORES IS DIFFERENT FROM THE PRODUCTION DB.
shell_exec('mysql -u' . env('DB_USERNAME') . ' -p' . env('DB_PASSWORD') . ' TEST < ' . $formattedString);
return redirect('get_backup')->with('status', 'Database successfully restored.');
}
} else {
return redirect('get_backup')->with('wrong_pass', 'Incorrect password! Database restore aborted.');
}
}
示例7: upload
/**
* @return Collection
*/
protected function upload()
{
/** @var UploadedFile[] $input */
$input = $this->request->file('files');
$storageDir = $this->request->get('storagedir');
$files = new Collection();
if ($input) {
foreach ($input as $file) {
if ($file->isValid()) {
$name = str_slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
$extension = $file->getClientOriginalExtension();
$path = public_path() . $storageDir;
if (File::exists($path . $name . '.' . $extension)) {
$num = 2;
foreach (File::glob($path . $name . '-*.' . $extension) as $existing) {
$existing = pathinfo($existing)['filename'];
if (preg_match('/-(\\d+)$/', $existing, $matches)) {
$num = max($num, (int) $matches[1] + 1);
}
}
$name .= '-' . $num;
}
$file_name = $name . '.' . $extension;
$file->move($path, $file_name);
$files[$file_name] = $storageDir . $file_name;
}
}
}
return $files;
}
示例8: getController
public function getController($config = array(), $controller_path = '', $controller_suffix = '', $str_namespace = '')
{
if (empty($config)) {
$config = $this->config;
}
$this->createTableRole($config['AUTH_TABLE']);
$this->createTableResource($config['AUTH_TABLE']);
$controller_path = empty($controller_path) ? app_path() . '/Http/Controllers' : rtrim($controller_path, '/');
$controller_suffix = empty($controller_suffix) ? 'Controller' : $controller_suffix;
if ($str_namespace) {
$str_namespace = "\\" . trim($str_namespace, "\\") . "\\";
}
$return_data = array();
if (File::isDirectory($controller_path)) {
foreach (File::glob($controller_path . '/*' . $controller_suffix . '.php') as $filename) {
$class_name = basename($filename, '.php');
$controller = str_replace($controller_suffix, '', $class_name);
$class_obj_name = $str_namespace ? $str_namespace . $class_name : $class_name;
$class_methods = get_class_methods($class_obj_name);
if (is_array($class_methods)) {
foreach ($class_methods as $action) {
//過濾魔術方法
if (substr($action, 0, 2) != '__' && !in_array($action, $config['AUTH_FILTER_METHOD'])) {
$return_data[$controller][$action] = -1;
}
}
}
}
}
if ($return_data) {
foreach ($return_data as $key => $value) {
$data = $condition = array();
$data[$config['AUTH_TABLE']['resource']['field']['pid']] = 0;
$condition[] = array($config['AUTH_TABLE']['resource']['field']['pid'] => 0);
$data[$config['AUTH_TABLE']['resource']['field']['operate']] = $key;
$condition[] = array($config['AUTH_TABLE']['resource']['field']['operate'] => $key);
$db_res = DB::table($config['AUTH_TABLE']['resource']['name']);
if ($condition) {
foreach ($condition as $k1 => $v1) {
foreach ($v1 as $k2 => $v2) {
$db_res->where($k2, '=', $v2);
}
}
}
$info = $db_res->first();
if (empty($info)) {
$pid = DB::table($config['AUTH_TABLE']['resource']['name'])->insertGetId($data);
} else {
$pid = $info[$config['AUTH_TABLE']['resource']['field']['id']];
}
if (is_array($value)) {
foreach ($value as $k2 => $v2) {
$data = $condition = array();
$data[$config['AUTH_TABLE']['resource']['field']['pid']] = $pid;
$condition[] = array($config['AUTH_TABLE']['resource']['field']['pid'] => $pid);
$data[$config['AUTH_TABLE']['resource']['field']['operate']] = $k2;
$condition[] = array($config['AUTH_TABLE']['resource']['field']['operate'] => $k2);
$db_res = DB::table($config['AUTH_TABLE']['resource']['name']);
if ($condition) {
foreach ($condition as $k1 => $v1) {
foreach ($v1 as $k2 => $v2) {
$db_res->where($k2, '=', $v2);
}
}
}
$info = $db_res->first();
if (empty($info)) {
DB::table($config['AUTH_TABLE']['resource']['name'])->insertGetId($data);
}
}
}
}
}
return $return_data;
}