本文整理汇总了PHP中SplFileInfo::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getRealPath方法的具体用法?PHP SplFileInfo::getRealPath怎么用?PHP SplFileInfo::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getRealPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove
public function remove($filename)
{
if (empty($filename)) {
throw new \LogicException('File name can not be empty string.');
}
$this->fs->remove($this->uploadDir->getRealPath() . '/' . $filename);
}
示例2: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$namespace = false;
$classyName = null;
$classyIndex = 0;
foreach ($tokens as $index => $token) {
if ($token->isGivenKind(T_NAMESPACE)) {
if (false !== $namespace) {
return;
}
$namespace = true;
} elseif ($token->isClassy()) {
if (null !== $classyName) {
return;
}
$classyIndex = $tokens->getNextMeaningfulToken($index);
$classyName = $tokens[$classyIndex]->getContent();
}
}
if (null === $classyName) {
return;
}
if (false !== $namespace) {
$filename = basename(str_replace('\\', '/', $file->getRealPath()), '.php');
if ($classyName !== $filename) {
$tokens[$classyIndex]->setContent($filename);
}
} else {
$normClass = str_replace('_', '/', $classyName);
$filename = substr(str_replace('\\', '/', $file->getRealPath()), -strlen($normClass) - 4, -4);
if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
$tokens[$classyIndex]->setContent(str_replace('/', '_', $filename));
}
}
}
示例3: installFilesystem
/**
* installFilesystem
*
* Install's
*
* @param SiteInterface $site
*/
public function installFilesystem(SiteInterface $site)
{
if (!$site->getId()) {
$this->getSiteManager()->save($site);
}
if ($site->getAliasOf()) {
return $this->installFilesystem($site->getAliasOf());
}
$baseDir = new \SplFileInfo($this->getKernel()->getRootDir() . '/../');
$skelDir = $baseDir->getRealPath() . '/skeleton/site';
$skelWebDir = $baseDir->getRealPath() . '/skeleton/site/web';
$vhostDir = $baseDir->getRealPath() . '/vhosts';
$templateDir = $baseDir->getRealPath() . '/templates';
$siteDir = $vhostDir . '/' . preg_replace('/^www\\./', '', $site->getDomain());
$siteWebDir = $siteDir . '/web';
$siteTemplateDir = $siteDir . '/templates';
$site->setRootDir($siteDir)->setWebDir($siteWebDir)->setTemplateDir($siteTemplateDir);
if (!file_exists($siteDir)) {
$process = new Process(sprintf('cp -r %s %s', $skelDir, $siteDir));
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
file_put_contents($siteWebDir . '/config.php', str_replace(array('[id]', '[domain]'), array($site->getId(), $site->getDomain()), file_get_contents($skelWebDir . '/config.php')));
$this->getSiteManager()->save($site);
}
示例4: upload
/**
* Upload an image to local server then return new image path after upload success
*
* @param array $file [tmp_name, name, error, type, size]
* @param string image path for saving (this may constain filename)
* @param string image filename for saving
* @return string Image path after uploaded
* @throws Exception If upload failed
*/
public function upload($file, $newImagePath = '.', $newImageName = NULL)
{
if (!empty($file['error'])) {
$this->_throwException(':method: Upload error. Number: :number', array(':method' => __METHOD__, ':number' => $file['error']));
}
if (getimagesize($file['tmp_name']) === FALSE) {
$this->_throwException(':method: The file is not an image file.', array(':method' => __METHOD__));
}
$fileInfo = new \SplFileInfo($newImagePath);
if (!$fileInfo->getRealPath() or !$fileInfo->isDir()) {
$this->_throwException(':method: The ":dir" must be a directory.', array(':method' => __METHOD__, ':dir' => $newImagePath));
}
$defaultExtension = '.jpg';
if (empty($newImageName)) {
if (!in_array($fileInfo->getBasename(), array('.', '..')) and $fileInfo->getExtension()) {
$newImageName = $fileInfo->getBasename();
} else {
$newImageName = uniqid() . $defaultExtension;
}
}
if (!$fileInfo->isWritable()) {
$this->_throwException(':method: Directory ":dir" is not writeable.', array(':method' => __METHOD__, ':dir' => $fileInfo->getRealPath()));
}
$destination = $fileInfo->getRealPath() . DIRECTORY_SEPARATOR . $newImageName;
if (move_uploaded_file($file['tmp_name'], $destination)) {
return $destination;
} else {
$this->_throwException(':method: Cannot move uploaded file to :path', array(':method' => __METHOD__, ':path' => $fileInfo->getRealPath()));
}
}
示例5: export
public function export()
{
$zipFile = PHPFOX_DIR_FILE . 'static/' . uniqid() . '.zip';
$zipArchive = new \ZipArchive();
if (!$zipArchive->open($zipFile, \ZIPARCHIVE::OVERWRITE)) {
throw new \Exception('Unable to create ZIP archive.');
}
$exclude = array('.git');
$filter = function ($file, $key, $iterator) use($exclude) {
if ($file->getFileName() == 'app.lock' || $file->getFileName() == 'composer.phar') {
return false;
}
if ($iterator->hasChildren() && !in_array($file->getFilename(), $exclude)) {
return true;
}
return $file->isFile();
};
$directory = new \SplFileInfo($this->path);
$innerIterator = new \RecursiveDirectoryIterator($directory->getRealPath(), \RecursiveDirectoryIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator(new \RecursiveCallbackFilterIterator($innerIterator, $filter));
foreach ($files as $name => $file) {
if ($file instanceof \SplFileInfo) {
$filePath = $file->getRealPath();
$name = str_replace($directory->getRealPath(), '', $filePath);
$zipArchive->addFile($filePath, $name);
}
}
$zipArchive->close();
$name = \Phpfox_Parse_Input::instance()->cleanFileName($this->id);
$name .= '-v' . $this->version;
\Phpfox_File::instance()->forceDownload($zipFile, 'phpfox-app-' . $name . '.zip');
return $zipFile;
}
示例6: getRealPath
/**
* @return string
*/
public function getRealPath()
{
$SplFileInfo = new \SplFileInfo($this->Instance->getLocation());
if (!$SplFileInfo->getRealPath()) {
$SplFileInfo = new \SplFileInfo($_SERVER['DOCUMENT_ROOT'] . $this->Instance->getLocation());
}
return $SplFileInfo->getRealPath() ? $SplFileInfo->getRealPath() : '';
}
示例7: __construct
public function __construct($filename)
{
$file = new \SplFileInfo($filename);
$this->filename = $filename;
if (file_exists($file->getRealPath())) {
@unlink($file->getRealPath());
}
$this->phar = new \Phar($file->getPathname(), 0, $file->getFilename());
}
示例8: __construct
/**
* Hash constructor.
* creates a new hash set from a list of files
*
* @constructor
* @access public
* @param array $fileList
*/
public function __construct(array $fileList)
{
$this->fileList = $fileList;
foreach ($this->fileList as $filePath) {
$file = new \SplFileInfo($filePath);
// hash the file path, size and CTime using murmur
$this->hashSet[$file->getRealPath()] = murmurhash3($file->getRealPath() . $file->getSize() . $file->getCTime());
}
}
示例9: __construct
/**
* Class constructor
*
* @param \SplFileInfo $set_info Set file info
*/
public function __construct(\SplFileInfo $set_info)
{
parent::__construct();
$this->set_path = $set_info->getRealPath();
$this->name = $set_info->getFilename();
$this->files()->in($set_info->getRealPath())->ignoreDotFiles(true);
foreach ($this->allowed_ext as $ext) {
$this->name(sprintf('/%s$/i', $ext));
}
}
示例10: load
/**
*
* @param string $filename
*
* @return \CSanquer\FakeryGenerator\Model\Config
*
* @throws \InvalidArgumentException
*/
public function load($filename)
{
$file = new \SplFileInfo($filename);
if (!in_array($file->getExtension(), ['json', 'xml'])) {
throw new \InvalidArgumentException('The config file must be an XML or a JSON file.');
}
if (!file_exists($file->getRealPath())) {
throw new \InvalidArgumentException('The config file must exist.');
}
return $this->serializer->deserialize(file_get_contents($file->getRealPath()), 'CSanquer\\FakeryGenerator\\Model\\Config', $file->getExtension());
}
示例11: parse
public function parse(\SplFileInfo $file)
{
$namespaceExtractor = new NamespaceExtractor();
$classNameExtractor = new ClassNameExtractor();
$useDeclarationExtractor = new UseDeclarationsExtractor();
$content = file_get_contents($file->getRealPath());
$tokens = Tokens::fromCode($content);
$classNamespace = $namespaceExtractor->extract($tokens);
$className = $classNameExtractor->extract($tokens);
$classFullName = sprintf('%s\\%s', $classNamespace, $className);
$useDeclarations = $useDeclarationExtractor->extract($tokens);
return new Node($useDeclarations, $classFullName, $file->getRealPath(), NodeInterface::TYPE_PHP_USE);
}
示例12: __construct
protected function __construct($path, $fn, $delimiter)
{
$this->delimiter = $delimiter;
if (substr($path, -1) != DIRECTORY_SEPARATOR) {
$path .= DIRECTORY_SEPARATOR;
}
$conf_file = new \SplFileInfo($path . $fn);
if (!$conf_file->isReadable()) {
$conf_file = new \SplFileInfo($path . $fn . '.dist');
if (!$conf_file->isReadable()) {
throw new UnreadableConfigException($conf_file->getRealPath());
}
}
$this->data = Yaml::parse(file_get_contents($conf_file->getRealPath()));
}
示例13: get
/**
* Get a stored value
* @param string $group
* @param string $name
* @param mixed $default
* @return mixed
*/
public function get($group, $name, $default = NULL)
{
// explode on separator
$parts = explode($this->params['separator'], $name);
// add group to front
array_unshift($parts, $group);
// last part is filename
$filename = array_pop($parts) . '.cache';
// get directory
$directory = $this->dir->getRealPath() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR;
// get file
$file = new \SplFileInfo($directory . $filename);
if (!$file->isFile()) {
// file doesnt exist: return default
return $default;
} else {
// get time created
$created = $file->getMTime();
// get data handle
$data = $file->openFile();
// lifetime is the first line
$lifetime = $data->fgets();
if ($data->eof()) {
// end of file: cache is corrupted: delete it and return default
unlink($file->getRealPath());
return $default;
}
// read data lines
$cache = '';
while ($data->eof() === FALSE) {
$cache .= $data->fgets();
}
if ($created + (int) $lifetime < time()) {
// Expired: delete the file & return default
unlink($file->getRealPath());
return $default;
} else {
try {
$unserialized = unserialize($cache);
} catch (Exception $e) {
// Failed to unserialize: delete file and return default
unlink($file->getRealPath());
$unserialized = $default;
}
return $unserialized;
}
}
}
示例14: createTransferAction
protected function createTransferAction(\SplFileInfo $file)
{
// Open the file for reading
$filename = $file->getRealPath() ?: $file->getPathName();
if (!($resource = fopen($filename, 'r'))) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Could not open ' . $file->getPathname() . ' for reading');
// @codeCoverageIgnoreEnd
}
$key = $this->options['source_converter']->convert($filename);
$body = EntityBody::factory($resource);
// Determine how the ACL should be applied
if ($acl = $this->options['acl']) {
$aclType = is_string($this->options['acl']) ? 'ACL' : 'ACP';
} else {
$acl = 'private';
$aclType = 'ACL';
}
// Use a multi-part upload if the file is larger than the cutoff size and is a regular file
if ($body->getWrapper() == 'plainfile' && $file->getSize() >= $this->options['multipart_upload_size']) {
$builder = UploadBuilder::newInstance()->setBucket($this->options['bucket'])->setKey($key)->setMinPartSize($this->options['multipart_upload_size'])->setOption($aclType, $acl)->setClient($this->options['client'])->setSource($body)->setConcurrency($this->options['concurrency']);
$this->dispatch(self::BEFORE_MULTIPART_BUILD, array('builder' => $builder, 'file' => $file));
return $builder->build();
}
return $this->options['client']->getCommand('PutObject', array('Bucket' => $this->options['bucket'], 'Key' => $key, 'Body' => $body, $aclType => $acl));
}
示例15: getHash
public function getHash()
{
if (!$this->isReadable()) {
throw new InvalidConfigurationException('Cannot read from file ' . $this->file);
}
return md5_file($this->file->getRealPath());
}