https://github.com/PHPOffice/PHPWord/issues/58 - "\PhpOffice\PhpWord\Shared\File" class was cut out.

This commit is contained in:
Roman Syroeshko 2014-03-25 17:00:07 +04:00
parent e6466f0ee5
commit a0e8b43193
5 changed files with 3 additions and 125 deletions

View File

@ -28,7 +28,6 @@ namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Shared\File;
/**
* Reader for Word2007
@ -87,7 +86,7 @@ class Word2007 extends AbstractReader implements IReader
if (strpos($fileName, '//') !== false) {
$fileName = substr($fileName, strpos($fileName, '//') + 1);
}
$fileName = File::realpath($fileName);
$fileName = realpath($fileName);
// Apache POI fixes
$contents = $archive->getFromName($fileName);

View File

@ -1,77 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Common file functions
*/
class File
{
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function fileExists($pFilename)
{
// Regular file_exists
return \file_exists($pFilename);
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename)
{
// Returnvalue
$returnValue = '';
// Try using realpath()
$returnValue = realpath($pFilename);
// Found something?
if ($returnValue == '' || is_null($returnValue)) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
// Return
return $returnValue;
}
}

View File

@ -27,7 +27,6 @@ namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\File;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
@ -123,7 +122,7 @@ class Manifest extends WriterPart
*/
private function _getImageMimeType($pFile = '')
{
if (File::fileExists($pFile)) {
if (file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {

View File

@ -26,7 +26,6 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Shared\File;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
@ -189,7 +188,7 @@ class ContentTypes extends WriterPart
*/
private function _getImageMimeType($pFile = '')
{
if (File::fileExists($pFile)) {
if (file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {

View File

@ -1,42 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Tests\Shared;
use PhpOffice\PhpWord\Shared\File;
/**
* @coversDefaultClass \PhpOffice\PhpWord\Shared\File
* @runTestsInSeparateProcesses
*/
class FileTest extends \PHPUnit_Framework_TestCase
{
/**
* Test file_exists()
*/
public function testFileExists()
{
$dir = __DIR__ . "/../_files/templates";
chdir($dir);
$this->assertTrue(File::fileExists('blank.docx'));
}
/**
* Test file_exists()
*/
public function testNoFileExists()
{
$dir = __DIR__ . "/../_files/templates";
chdir($dir);
$this->assertFalse(File::fileExists('404.docx'));
}
/**
* Test realpath()
*/
public function testRealpath()
{
$dir = realpath(__DIR__ . "/../_files/templates");
chdir($dir);
$file = 'blank.docx';
$expected = $dir . \DIRECTORY_SEPARATOR . $file;
$this->assertEquals($expected, File::realpath($file));
}
}