本文整理汇总了PHP中Patchwork\Utf8::wrapPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Utf8::wrapPath方法的具体用法?PHP Utf8::wrapPath怎么用?PHP Utf8::wrapPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Patchwork\Utf8
的用法示例。
在下文中一共展示了Utf8::wrapPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$start = time();
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$dispatcher = $this->getContainer()->get('event_dispatcher');
/* @var $rep StorageRepository */
$rep = $em->getRepository('AnimeDbCatalogBundle:Storage');
$progress = $this->getProgress($input, $output);
$lazywrite = new LazyWrite($output);
$lazywrite->setLazyWrite(!$input->getOption('no-progress'));
// get list storages
if ($id = $input->getArgument('storage')) {
$storage = $rep->find($id);
if (!$storage instanceof Storage) {
throw new \InvalidArgumentException('Not found the storage with id: ' . $id);
}
if (!$storage->isWritable()) {
throw new \InvalidArgumentException('Storage "' . $storage->getName() . '" can not be scanned');
}
$storages = [$storage];
} else {
$storages = $rep->getList(Storage::getTypesWritable());
}
/* @var $storage Storage */
foreach ($storages as $storage) {
$output->writeln('Scan storage <info>' . $storage->getName() . '</info>:');
$path = $storage->getPath();
$path = Utf8::wrapPath($path);
// wrap path for current fs
if (!file_exists($path)) {
$output->writeln('Storage is not available');
continue;
}
// check storage id
$owner = $this->checkStorageId($path, $storage, $rep);
if ($owner instanceof Storage) {
$output->writeln('Path <info>' . $storage->getPath() . '</info> reserved storage <info>' . $owner->getName() . '</info>');
continue;
}
// storage not modified
if (!$input->getOption('force') && $storage->getFileModified() && filemtime($path) == $storage->getFileModified()->getTimestamp()) {
$output->writeln('Storage is not modified');
continue;
}
$files = $this->getFilesByPath($path);
$total = $files->count();
// total files +1% for check of delete files
$progress->start(ceil($total + $total * 0.01));
$progress->display();
/* @var $file SplFileInfo */
foreach ($files as $file) {
// ignore not supported files
if ($file->isFile() && !$this->isAllowFile($file)) {
$progress->advance();
continue;
}
// item is exists and modified
if ($item = $this->getItemFromFile($storage, $file)) {
if ($item->getDateUpdate()->getTimestamp() < $file->getPathInfo()->getMTime()) {
$dispatcher->dispatch(StoreEvents::UPDATE_ITEM_FILES, new UpdateItemFiles($item));
$lazywrite->writeln('Changes are detected in files of item <info>' . $item->getName() . '</info>');
}
} else {
// remove wrap prefix
list(, $file) = explode('://', $file->getPathname(), 2);
$file = new SplFileInfo($file, '', '');
// it is a new item
$name = $this->getContainer()->get('anime_db.storage.filename_cleaner')->clean($file);
$dispatcher->dispatch(StoreEvents::DETECTED_NEW_FILES, new DetectedNewFiles($storage, $file, $name));
$lazywrite->writeln('Detected files for new item <info>' . $file->getFilename() . '</info>');
}
$progress->advance();
}
$em->refresh($storage);
// check of delete file for item
foreach ($this->getItemsOfDeletedFiles($storage, $files) as $item) {
$dispatcher->dispatch(StoreEvents::DELETE_ITEM_FILES, new DeleteItemFiles($item));
$lazywrite->writeln('<error>Files for item "' . $item->getName() . '" is not found</error>');
}
$progress->advance();
$progress->finish();
$lazywrite->writeAll();
// update date modified
$storage->setFileModified(new \DateTime(date('Y-m-d H:i:s', filemtime($path))));
$em->persist($storage);
$output->writeln('');
}
$em->flush();
$output->writeln('Time: <info>' . (time() - $start) . '</info> s.');
}
示例2: scandir
/**
* List files and directories inside the specified path.
*
* @param string $path
* @param int $filter
* @param int $order
*
* @return array
*/
public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
{
if (!$filter || ($filter & self::FILE) != self::FILE && ($filter & self::DIRECTORY) != self::DIRECTORY) {
$filter = self::FILE | self::DIRECTORY;
}
// add slash if need
$path = self::getRealPath($path);
// wrap path for current fs
$wrap = Utf8::wrapPath($path);
// scan directory
$folders = [];
foreach (new \DirectoryIterator($wrap) as $file) {
/* @var $file \SplFileInfo */
try {
if ($file->getFilename()[0] != '.' && substr($file->getFilename(), -1) != '~' && $file->getFilename() != 'pagefile.sys' && $file->isReadable() && (($filter & self::FILE) == self::FILE && $file->isFile() || ($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())) {
$folders[$file->getFilename()] = ['name' => $file->getFilename(), 'path' => $path . $file->getFilename() . DIRECTORY_SEPARATOR];
}
} catch (\Exception $e) {
// ignore all errors
}
}
// order files
if ($order == SCANDIR_SORT_ASCENDING) {
ksort($folders);
} elseif ($order == SCANDIR_SORT_DESCENDING) {
ksort($folders);
$folders = array_reverse($folders);
}
// add link on parent folder
if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
$pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
array_unshift($folders, ['name' => '..', 'path' => substr($path, 0, $pos)]);
}
return array_values($folders);
}