PhpOffice\PhpPresentation\Shape\Drawing\File::setPath PHP Method

setPath() public method

Set Path
public setPath ( string $pValue = '', boolean $pVerifyFile = true ) : PhpOffice\PhpPresentation\Shape\Drawing
$pValue string File path
$pVerifyFile boolean Verify file
return PhpOffice\PhpPresentation\Shape\Drawing
    public function setPath($pValue = '', $pVerifyFile = true)
    {
        if ($pVerifyFile) {
            if (!file_exists($pValue)) {
                throw new \Exception("File {$pValue} not found!");
            }
        }
        $this->path = $pValue;
        if ($pVerifyFile) {
            if ($this->width == 0 && $this->height == 0) {
                list($this->width, $this->height) = getimagesize($this->getPath());
            }
        }
        return $this;
    }

Usage Example

Esempio n. 1
0
 public function testPathWithRealFile()
 {
     $object = new File();
     $imagePath = PHPPRESENTATION_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'PhpPresentationLogo.png';
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\File', $object->setPath($imagePath, false));
     $this->assertEquals($imagePath, $object->getPath());
     $this->assertEquals(0, $object->getWidth());
     $this->assertEquals(0, $object->getHeight());
 }