本文整理汇总了PHP中SplFileObject::getPathname方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::getPathname方法的具体用法?PHP SplFileObject::getPathname怎么用?PHP SplFileObject::getPathname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::getPathname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param \SplFileObject $post Post source file
*/
public function __construct(\SplFileObject $post)
{
$this->source = $post;
if (!preg_match('/[\\d]{4}\\/[\\d]{2}\\/(.+)$/', $post->getPathname())) {
throw new \Exception(sprintf('%s is not a valid post', $post->getPathname()));
}
$paths = explode(DIRECTORY_SEPARATOR, $post->getPath());
$this->month = $paths[count($paths) - 1];
$this->year = $paths[count($paths) - 2];
$this->slug = $post->getBasename('.' . $post->getExtension());
}
示例2: _clearDirectory
/**
* Clears a directory of cached files with the correct header.
*
* @return void
*/
protected function _clearDirectory($path)
{
$dir = new DirectoryIterator($path);
foreach ($dir as $file) {
$fileInfo = new SplFileObject($file->getPathname());
$line = $fileInfo->fgets();
if (preg_match('#^/\\* asset_compress \\d+ \\*/$#', $line)) {
$this->out('Deleting ' . $fileInfo->getPathname());
unlink($fileInfo->getPathname());
}
}
}
示例3: start
/**
* @inheritdoc
*/
public function start()
{
if (!$this->file) {
throw new \LogicException('Set a file first');
}
if ($this->writer) {
throw new \LogicException('Writer already started');
}
$this->writer = new BaseXmlWriter();
$this->writer->openUri($this->file->getPathname());
$this->writer->setIndent($this->indent);
$this->writer->startDocument('1.0', 'UTF-8');
$this->write(sprintf('<%s>', $this->rootNode));
}
示例4: _setKey
/**
* Sets the current cache key this class is managing, and creates a writable SplFileObject
* for the cache file the key is referring to.
*
* @param string $key The key
* @param bool $createKey Whether the key should be created if it doesn't exists, or not
* @return bool true if the cache key could be set, false otherwise
*/
protected function _setKey($key, $createKey = false)
{
$groups = null;
if (!empty($this->_groupPrefix)) {
$groups = vsprintf($this->_groupPrefix, $this->groups());
}
$dir = $this->_config['path'] . $groups;
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
$path = new \SplFileInfo($dir . $key);
if (!$createKey && !$path->isFile()) {
return false;
}
if (empty($this->_File) || $this->_File->getBasename() !== $key) {
$exists = file_exists($path->getPathname());
try {
$this->_File = $path->openFile('c+');
} catch (Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
return false;
}
unset($path);
if (!$exists && !chmod($this->_File->getPathname(), (int) $this->_config['mask'])) {
trigger_error(sprintf('Could not apply permission mask "%s" on cache file "%s"', $this->_File->getPathname(), $this->_config['mask']), E_USER_WARNING);
}
}
return true;
}
示例5: _openFile
protected function _openFile($key, $createKey = false)
{
$dir = $this->settings['path'];
//create dir if needed
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$path = new SplFileInfo($dir . $key);
if (!$createKey && !$path->isFile()) {
return false;
}
if (empty($this->file) || $this->file->getBaseName() !== $key) {
$exists = file_exists($path->getPathname());
try {
$this->file = $path->openFile('c+');
} catch (Exception $e) {
if (!$this->settings['suppress_errors']) {
trigger_error($e->getMessage(), E_USER_WARNING);
}
return false;
}
unset($path);
if (!$exists && !chmod($this->file->getPathname(), (int) $this->settings['mask'])) {
if (!$this->settings['suppress_errors']) {
trigger_error('Could not apply permission mask on cache file ' . $this->file->getPathname(), E_USER_WARNING);
}
}
}
return true;
}
示例6: __construct
/**
* @param \SplFileObject $file File
* @param string $sheet Sheet title (optional)
* @param string $type Excel file type (defaults to Excel2007)
* @param bool $prependHeaderRow
*/
public function __construct(\SplFileObject $file, $sheet = null, $type = 'Excel2007', $prependHeaderRow = false)
{
$this->filename = $file->getPathname();
$this->sheet = $sheet;
$this->type = $type;
$this->prependHeaderRow = $prependHeaderRow;
}
示例7: __construct
public function __construct(\SplFileObject $file, $xpath = null)
{
$this->filename = $file->getPathname();
if (!is_null($xpath) && !is_string($xpath)) {
throw new \InvalidArgumentException('xpath must be null or a string');
}
$this->xpath = $xpath;
}
示例8: testInit
/**
* @return void
*/
public function testInit()
{
$filePath = __DIR__ . '/example_read.txt';
$fileObject = new FileReader($filePath, 'r', true);
$this->assertEquals($filePath, $fileObject->getPathname());
$this->assertTrue($fileObject->isReadable());
$fileObject = new \SplFileObject($filePath, 'r');
$this->assertEquals($filePath, $fileObject->getPathname());
$this->assertTrue($fileObject->isReadable());
}
示例9: testInit
/**
* @return void
*/
public function testInit()
{
$filePath = __DIR__ . '/example_write1.txt';
$fileObject = new FileWriter($filePath);
$this->assertEquals($filePath, $fileObject->getPathname());
$this->assertTrue($fileObject->isWritable());
$filePath = __DIR__ . '/example_write2.txt';
$fileObject = new \SplFileObject($filePath, 'r+');
$this->assertEquals($filePath, $fileObject->getPathname());
$this->assertTrue($fileObject->isWritable());
}
示例10: __construct
public function __construct($message, $parser, \SplFileObject $file = NULL)
{
$this->code = xml_get_error_code($parser);
if (false === $this->code) {
throw new \BadMethodCallException('This is not a valid xml_parser resource.');
}
parent::__construct($message ?: xml_error_string($this->code), $this->code);
$this->file = $file ? $file->getPathname() : '(data stream)';
$this->line = xml_get_current_line_number($parser);
$this->err['srcColumn'] = xml_get_current_column_number($parser);
$this->err['srcIndex'] = xml_get_current_byte_index($parser);
}
示例11: in
/**
* Add input argument
*
* @param string $filePath
* Input file path
*
* @return Identify
* @throws \InvalidArgumentException
*/
public function in($filePath)
{
if (!file_exists($filePath)) {
$message = 'The input file path (' . $filePath . ') is invalid or the file could not be located.';
throw new \InvalidArgumentException($message);
}
$file = new \SplFileObject($filePath);
if ($file->isReadable()) {
$this->inputFile = '"' . $file->getPathname() . '"';
}
$this->getQuery()->dirty();
return $this;
}
示例12: __construct
/**
* Construct CSV reader
*
* @param \SplFileObject $file Excel file
* @param int $headerRowNumber Optional number of header row
* @param int $activeSheet Index of active sheet to read from
*/
public function __construct(\SplFileObject $file, $headerRowNumber = null, $activeSheet = null)
{
$reader = \PHPExcel_IOFactory::createReaderForFile($file->getPathName());
$reader->setReadDataOnly(true);
$excel = $reader->load($file->getPathname());
if (null !== $activeSheet) {
$excel->setActiveSheetIndex($activeSheet);
}
$this->worksheet = $excel->getActiveSheet()->toArray();
if (null !== $headerRowNumber) {
$this->setHeaderRowNumber($headerRowNumber);
}
}
示例13: testRoutePath
/**
* Default route test
*/
public function testRoutePath()
{
$file = new \SplFileObject(__DIR__ . '/../../../../../files/cestlafete.jpg');
self::$DI['client']->request("GET", "/admin/tests/pathurl/path/", ['path' => $file->getPathname()]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type"));
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertTrue(is_object($content));
$this->assertObjectHasAttribute('exists', $content);
$this->assertObjectHasAttribute('file', $content);
$this->assertObjectHasAttribute('dir', $content);
$this->assertObjectHasAttribute('readable', $content);
$this->assertObjectHasAttribute('executable', $content);
}
示例14: testShouldRenderDocsActionWhenFileExists
/**
* @covers \Phansible\Controller\DefaultController::docsAction
*/
public function testShouldRenderDocsActionWhenFileExists()
{
$container = new \Pimple();
$this->twig->expects($this->once())->method('render')->with($this->equalTo('docs.html.twig'), $this->callback(function ($param) {
return array_key_exists('content', $param) && strpos($param['content'], 'ansible');
}));
$docFile = new \SplFileObject('/tmp/vagrant.md', 'w+');
$docFile->fwrite('Phansible');
$doc = 'vagrant';
$container['twig'] = $this->twig;
$container['docs.path'] = '/tmp';
$this->controller->setPimple($container);
$this->controller->docsAction($doc);
unlink($docFile->getPathname());
}
示例15: __construct
/**
* @param \SplFileObject $file Excel file
* @param integer $headerRowNumber Optional number of header row
* @param integer $activeSheet Index of active sheet to read from
* @param boolean $readOnly If set to false, the reader take care of the excel formatting (slow)
*/
public function __construct(\SplFileObject $file, $headerRowNumber = null, $activeSheet = null, $readOnly = true)
{
$reader = \PHPExcel_IOFactory::createReaderForFile($file->getPathName());
$reader->setReadDataOnly($readOnly);
/** @var \PHPExcel $excel */
$excel = $reader->load($file->getPathname());
if (null !== $activeSheet) {
$excel->setActiveSheetIndex($activeSheet);
}
$this->worksheet = $excel->getActiveSheet();
$this->maxColumn = $this->worksheet->getHighestColumn();
$this->maxRow = $this->worksheet->getHighestRow();
if (null !== $headerRowNumber) {
$this->setHeaderRowNumber($headerRowNumber);
}
}