本文整理汇总了PHP中TYPO3\CMS\Core\Utility\PathUtility类的典型用法代码示例。如果您正苦于以下问题:PHP PathUtility类的具体用法?PHP PathUtility怎么用?PHP PathUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
* Unset all additional properties of test classes to help PHP
* garbage collection. This reduces memory footprint with lots
* of tests.
*
* If owerwriting tearDown() in test classes, please call
* parent::tearDown() at the end. Unsetting of own properties
* is not needed this way.
*
* @throws \RuntimeException
* @return void
*/
protected function tearDown()
{
// Unset properties of test classes to safe memory
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
$declaringClass = $property->getDeclaringClass()->getName();
if (!$property->isStatic() && $declaringClass !== \TYPO3\CMS\Core\Tests\UnitTestCase::class && $declaringClass !== \TYPO3\CMS\Core\Tests\BaseTestCase::class && strpos($property->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
$propertyName = $property->getName();
unset($this->{$propertyName});
}
}
unset($reflection);
// Delete registered test files and directories
foreach ($this->testFilesToDelete as $absoluteFileName) {
$absoluteFileName = GeneralUtility::fixWindowsFilePath(PathUtility::getCanonicalPath($absoluteFileName));
if (!GeneralUtility::validPathStr($absoluteFileName)) {
throw new \RuntimeException('tearDown() cleanup: Filename contains illegal characters', 1410633087);
}
if (!StringUtility::beginsWith($absoluteFileName, PATH_site . 'typo3temp/')) {
throw new \RuntimeException('tearDown() cleanup: Files to delete must be within typo3temp/', 1410633412);
}
// file_exists returns false for links pointing to not existing targets, so handle links before next check.
if (@is_link($absoluteFileName) || @is_file($absoluteFileName)) {
unlink($absoluteFileName);
} elseif (@is_dir($absoluteFileName)) {
GeneralUtility::rmdir($absoluteFileName, true);
} else {
throw new \RuntimeException('tearDown() cleanup: File, link or directory does not exist', 1410633510);
}
}
$this->testFilesToDelete = array();
}
示例2: compressJsFile
/**
* Compresses and minifies a javascript file
*
* @param string $filename Source filename, relative to requested page
* @return string Filename of the compressed file, relative to requested page
*/
public function compressJsFile($filename)
{
// generate the unique name of the file
$filenameAbsolute = GeneralUtility::resolveBackPath($this->rootPath . $this->getFilenameFromMainDir($filename));
if (@file_exists($filenameAbsolute)) {
$fileStatus = stat($filenameAbsolute);
$unique = $filenameAbsolute . $fileStatus['mtime'] . $fileStatus['size'];
} else {
$unique = $filenameAbsolute;
}
$pathinfo = PathUtility::pathinfo($filename);
$targetFile = $this->targetDirectory . $pathinfo['filename'] . '-' . md5($unique) . '.js';
// only create it, if it doesn't exist, yet
if (!file_exists(PATH_site . $targetFile) || $this->createGzipped && !file_exists(PATH_site . $targetFile . '.gzip')) {
$contents = file_get_contents($filenameAbsolute);
try {
$minifiedContents = Minifier::minify($contents);
} catch (\Exception $e) {
// Log error and use un-minified content as fallback
/** @var $logger Logger */
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->error($e->getMessage(), ['filename' => $filename]);
$minifiedContents = $contents;
}
$this->writeFileAndCompressed($targetFile, $minifiedContents);
}
return $this->relativePath . $this->returnFileReference($targetFile);
}
示例3: addData
/**
* Initialize new row with default values from various sources
*
* @param array $result
* @return array
* @todo: Should not implode valid values with | again, container & elements should work
* @todo: with the array as it was done for select items
* @throws \UnexpectedValueException
*/
public function addData(array $result)
{
foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'group' || empty($fieldConfig['config']['internal_type'])) {
continue;
}
$databaseRowFieldContent = '';
if (!empty($result['databaseRow'][$fieldName])) {
$databaseRowFieldContent = (string) $result['databaseRow'][$fieldName];
}
$internalType = $fieldConfig['config']['internal_type'];
if ($internalType === 'file_reference' || $internalType === 'file') {
$files = array();
// Simple list of files
$fileList = GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
foreach ($fileList as $file) {
if ($file) {
$files[] = rawurlencode($file) . '|' . rawurlencode(PathUtility::basename($file));
}
}
$result['databaseRow'][$fieldName] = implode(',', $files);
} elseif ($internalType === 'db') {
/** @var $relationHandler RelationHandler */
$relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
$relationHandler->start($databaseRowFieldContent, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $result['databaseRow']['uid'], $result['tableName'], $fieldConfig['config']);
$relationHandler->getFromDB();
$result['databaseRow'][$fieldName] = $relationHandler->readyForInterface();
} else {
// @todo: "folder" is a valid internal_type, too.
throw new \UnexpectedValueException('TCA internal_type of field "' . $fieldName . '" in table ' . $result['tableName'] . ' must be set to either "db", "file" or "file_reference"', 1438780511);
}
}
return $result;
}
示例4: prepareLoader
/**
* Get all the complex data for the loader.
* This return value will be cached and stored in the database
* There is no file monitoring for this cache
*
* @param Loader $autoLoader
* @param int $type
*
* @return array
*/
public function prepareLoader(Loader $autoLoader, $type)
{
$languageOverride = [];
if ($type === LoaderInterface::EXT_TABLES) {
return $languageOverride;
}
$languageOverridePath = ExtensionManagementUtility::extPath($autoLoader->getExtensionKey()) . 'Resources/Private/Language/Overrides/';
if (!is_dir($languageOverridePath)) {
return $languageOverride;
}
$files = GeneralUtility::getAllFilesAndFoldersInPath([], $languageOverridePath, 'xlf,php,xml', false, 99);
foreach ($files as $file) {
$file = str_replace($languageOverridePath, '', $file);
$parts = GeneralUtility::trimExplode('/', $file, true);
$extension = GeneralUtility::camelCaseToLowerCaseUnderscored($parts[0]);
unset($parts[0]);
$parts = array_values($parts);
// language
$language = 'default';
$fileParts = GeneralUtility::trimExplode('.', PathUtility::basename($file), true);
if (strlen($fileParts[0]) === 2) {
$language = $fileParts[0];
unset($fileParts[0]);
$parts[sizeof($parts) - 1] = implode('.', $fileParts);
}
$languageOverride[] = ['language' => $language, 'original' => 'EXT:' . $extension . '/' . implode('/', $parts), 'override' => 'EXT:' . $autoLoader->getExtensionKey() . '/Resources/Private/Language/Overrides/' . $file];
}
return $languageOverride;
}
示例5: prepareLoader
/**
* Get all the complex data for the loader.
* This return value will be cached and stored in the database
* There is no file monitoring for this cache
*
* @param Loader $loader
* @param int $type
*
* @return array
*/
public function prepareLoader(Loader $loader, $type)
{
$icons = [];
if (!class_exists('TYPO3\\CMS\\Core\\Imaging\\IconRegistry')) {
return $icons;
}
$iconFolder = 'Resources/Public/Icon/';
$folder = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . $iconFolder;
$extensionPath = ExtensionManagementUtility::extPath($loader->getExtensionKey());
$files = GeneralUtility::getAllFilesAndFoldersInPath([], $folder, '', false, true);
if (!sizeof($files)) {
return $icons;
}
foreach ($files as $path) {
$provider = 'TYPO3\\CMS\\Core\\Imaging\\IconProvider\\BitmapIconProvider';
if (substr(strtolower($path), -3) === 'svg') {
$provider = 'TYPO3\\CMS\\Core\\Imaging\\IconProvider\\SvgIconProvider';
}
$relativePath = str_replace($extensionPath, '', $path);
$iconPath = str_replace($iconFolder, '', $relativePath);
$pathElements = PathUtility::pathinfo(strtolower(str_replace('/', '-', $iconPath)));
$icons[] = ['provider' => $provider, 'path' => 'EXT:' . $loader->getExtensionKey() . '/' . $relativePath, 'identifier' => str_replace('_', '-', $loader->getExtensionKey()) . '-' . $pathElements['filename']];
}
return $icons;
}
示例6: prepareLoader
/**
* Get all the complex data for the loader.
* This return value will be cached and stored in the database
* There is no file monitoring for this cache
*
* @param Loader $loader
* @param int $type
*
* @return array
*/
public function prepareLoader(Loader $loader, $type)
{
$grids = [];
if (!ExtensionManagementUtility::isLoaded('gridelements')) {
return $grids;
}
$commandPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Resources/Private/Grids/';
$files = FileUtility::getBaseFilesWithExtensionInDir($commandPath, 'ts,txt');
foreach ($files as $file) {
$pathInfo = PathUtility::pathinfo($file);
$iconPath = 'EXT:' . $loader->getExtensionKey() . '/Resources/Public/Icons/Grids/' . $pathInfo['filename'] . '.';
$extension = IconUtility::getIconFileExtension(GeneralUtility::getFileAbsFileName($iconPath));
$translationKey = 'grid.' . $pathInfo['filename'];
if ($type === LoaderInterface::EXT_TABLES) {
TranslateUtility::assureLabel($translationKey, $loader->getExtensionKey(), $pathInfo['filename']);
}
$path = 'EXT:' . $loader->getExtensionKey() . '/Resources/Private/Grids/' . $file;
$icon = $extension ? $iconPath . $extension : false;
$label = TranslateUtility::getLllString($translationKey, $loader->getExtensionKey());
$content = GeneralUtility::getUrl(GeneralUtility::getFileAbsFileName($path));
$flexForm = 'EXT:' . $loader->getExtensionKey() . '/Configuration/FlexForms/Grids/' . $pathInfo['filename'] . '.xml';
$flexFormFile = GeneralUtility::getFileAbsFileName($flexForm);
$flexFormContent = is_file($flexFormFile) ? GeneralUtility::getUrl($flexFormFile) : false;
$grids[] = $this->getPageTsConfig($pathInfo['filename'], $label, $content, $icon, $flexFormContent);
}
return $grids;
}
示例7: setFileInformations
/**
* collect all fileinformations of given file and
* save them to the global fileinformation array
*
* @param string $file
* @return boolean is valid file?
*/
protected function setFileInformations($file)
{
$this->fileInfo = array();
// reset previously information to have a cleaned object
$this->file = $file instanceof \TYPO3\CMS\Core\Resource\File ? $file : NULL;
if (is_string($file) && !empty($file)) {
$this->fileInfo = TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($file);
$this->fileInfo['mtime'] = filemtime($file);
$this->fileInfo['atime'] = fileatime($file);
$this->fileInfo['owner'] = fileowner($file);
$this->fileInfo['group'] = filegroup($file);
$this->fileInfo['size'] = filesize($file);
$this->fileInfo['type'] = filetype($file);
$this->fileInfo['perms'] = fileperms($file);
$this->fileInfo['is_dir'] = is_dir($file);
$this->fileInfo['is_file'] = is_file($file);
$this->fileInfo['is_link'] = is_link($file);
$this->fileInfo['is_readable'] = is_readable($file);
$this->fileInfo['is_uploaded'] = is_uploaded_file($file);
$this->fileInfo['is_writeable'] = is_writeable($file);
}
if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
$pathInfo = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($file->getName());
$this->fileInfo = array('file' => $file->getName(), 'filebody' => $file->getNameWithoutExtension(), 'fileext' => $file->getExtension(), 'realFileext' => $pathInfo['extension'], 'atime' => $file->getCreationTime(), 'mtime' => $file->getModificationTime(), 'owner' => '', 'group' => '', 'size' => $file->getSize(), 'type' => 'file', 'perms' => '', 'is_dir' => FALSE, 'is_file' => $file->getStorage()->getDriverType() === 'Local' ? is_file($file->getForLocalProcessing(FALSE)) : TRUE, 'is_link' => $file->getStorage()->getDriverType() === 'Local' ? is_link($file->getForLocalProcessing(FALSE)) : FALSE, 'is_readable' => TRUE, 'is_uploaded' => FALSE, 'is_writeable' => FALSE);
}
return $this->fileInfo !== array();
}
示例8: render
/**
* @param array|NULL $backendUser
* @param int $size
* @param bool $showIcon
* @return string
*/
public function render(array $backendUser = NULL, $size = 32, $showIcon = FALSE)
{
$size = (int) $size;
if (!is_array($backendUser)) {
$backendUser = $this->getBackendUser()->user;
}
$image = parent::render($backendUser, $size, $showIcon);
if (!StringUtility::beginsWith($image, '<span class="avatar"><span class="avatar-image"></span>') || empty($backendUser['email'])) {
return $image;
}
$cachedFilePath = PATH_site . 'typo3temp/t3gravatar/';
$cachedFileName = sha1($backendUser['email'] . $size) . '.jpg';
if (!file_exists($cachedFilePath . $cachedFileName)) {
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower($backendUser['email'])) . '?s=' . $size . '&d=404';
$gravatarImage = GeneralUtility::getUrl($gravatar);
if (empty($gravatarImage)) {
return $image;
}
GeneralUtility::writeFileToTypo3tempDir($cachedFileName, $gravatarImage);
}
// Icon
$icon = '';
if ($showIcon) {
$icon = '<span class="avatar-icon">' . IconUtility::getSpriteIconForRecord('be_users', $backendUser) . '</span>';
}
$relativeFilePath = PathUtility::getRelativePath(PATH_typo3, $cachedFilePath);
return '<span class="avatar"><span class="avatar-image">' . '<img src="' . $relativeFilePath . $cachedFileName . '" width="' . $size . '" height="' . $size . '" /></span>' . $icon . '</span>';
}
示例9: index
/**
* Index action shows install tool / step installer or redirect to action to enable install tool
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function index(ServerRequestInterface $request, ResponseInterface $response)
{
/** @var EnableFileService $enableFileService */
$enableFileService = GeneralUtility::makeInstance(EnableFileService::class);
/** @var AbstractFormProtection $formProtection */
$formProtection = FormProtectionFactory::get();
if ($enableFileService->checkInstallToolEnableFile()) {
// Install tool is open and valid, redirect to it
$response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
} elseif ($request->getMethod() === 'POST' && $request->getParsedBody()['action'] === 'enableInstallTool') {
// Request to open the install tool
$installToolEnableToken = $request->getParsedBody()['installToolEnableToken'];
if (!$formProtection->validateToken($installToolEnableToken, 'installTool')) {
throw new \RuntimeException('Given form token was not valid', 1369161225);
}
$enableFileService->createInstallToolEnableFile();
// Install tool is open and valid, redirect to it
$response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
} else {
// Show the "create enable install tool" button
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html'));
$token = $formProtection->generateToken('installTool');
$view->assign('installToolEnableToken', $token);
/** @var ModuleTemplate $moduleTemplate */
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$cssFile = 'EXT:install/Resources/Public/Css/BackendModule/ShowEnableInstallToolButton.css';
$cssFile = GeneralUtility::getFileAbsFileName($cssFile);
$moduleTemplate->getPageRenderer()->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
$moduleTemplate->setContent($view->render());
$response->getBody()->write($moduleTemplate->renderContent());
}
return $response;
}
示例10: render
/**
* @param string $identifier
*
* @return string
*/
public function render($identifier = '')
{
$basePath = 'sysext/t3skin/images/icons/';
$nameParts = GeneralUtility::trimExplode('-', $identifier);
$folder = array_shift($nameParts);
$basePath .= $folder . '/' . implode('-', $nameParts) . '.png';
return '<img src="' . PathUtility::getAbsoluteWebPath($basePath) . '" />';
}
示例11: getRelativePath
/**
* Return a public path pointing to a resource.
*
* @param string $resource
* @return string
*/
public static function getRelativePath($resource)
{
// If file is not found, resolve the path
if (!is_file(PATH_site . $resource)) {
$resource = substr(self::resolvePath($resource), strlen(PATH_site));
}
return PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $resource)) . PathUtility::basename($resource);
}
示例12: isValidFileExtension
/**
* Check if the given path or extension is valid for the focuspoint
*
* @param $pathOrExtension
* @return bool
*/
public static function isValidFileExtension($pathOrExtension)
{
$pathOrExtension = strtolower($pathOrExtension);
$validExtensions = self::getAllowedFileExtensions();
if (in_array($pathOrExtension, $validExtensions)) {
return true;
}
return in_array(PathUtility::pathinfo($pathOrExtension, PATHINFO_EXTENSION), $validExtensions);
}
示例13: getUrl
/**
* Get url
*
* @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all.
* @return string
*/
public function getUrl($relativeToCurrentScript = false)
{
$url = $this->url;
if ($relativeToCurrentScript && !GeneralUtility::isValidUrl($url)) {
$absolutePathToContainingFolder = PathUtility::dirname(PATH_site . $url);
$pathPart = PathUtility::getRelativePathTo($absolutePathToContainingFolder);
$filePart = substr(PATH_site . $url, strlen($absolutePathToContainingFolder) + 1);
$url = $pathPart . $filePart;
}
return $url;
}
示例14: loadByCorePageRender
/**
* @param array $asset
* @return void
*/
protected function loadByCorePageRender(array $asset)
{
$file = $this->resolveFileForApplicationContext($asset);
$fileNameAndPath = GeneralUtility::getFileAbsFileName($file);
$fileNameAndPath = PathUtility::stripPathSitePrefix($fileNameAndPath);
if ($asset['type'] === 'js') {
$this->getPageRenderer()->addJsFooterFile($fileNameAndPath);
} elseif ($asset['type'] === 'css') {
$this->getPageRenderer()->addCssFile($fileNameAndPath);
}
}
示例15: generateMarkup
/**
* @param Icon $icon
* @param array $options
* @return string
* @throws \InvalidArgumentException
*/
protected function generateMarkup(Icon $icon, array $options)
{
if (empty($options['source'])) {
throw new \InvalidArgumentException('[' . $icon->getIdentifier() . '] The option "source" is required and must not be empty', 1440754980);
}
$source = $options['source'];
if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
$source = GeneralUtility::getFileAbsFileName($source);
}
$source = PathUtility::getAbsoluteWebPath($source);
return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
}