Skip to content

Commit 0116c89

Browse files
authored
Merge pull request #677 from Progi1984/634_exceptions
#634 : Set specific exceptions
2 parents 2b04ee5 + cea5f34 commit 0116c89

File tree

103 files changed

+1220
-1094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1220
-1094
lines changed

src/PhpPresentation/AbstractShape.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace PhpOffice\PhpPresentation;
2222

23+
use PhpOffice\PhpPresentation\Exception\ShapeContainerAlreadyAssignedException;
2324
use PhpOffice\PhpPresentation\Shape\Hyperlink;
2425
use PhpOffice\PhpPresentation\Shape\Placeholder;
2526
use PhpOffice\PhpPresentation\Style\Border;
@@ -146,7 +147,7 @@ public function getContainer(): ?ShapeContainerInterface
146147
* @param ShapeContainerInterface $pValue
147148
* @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide?
148149
*
149-
* @throws \Exception
150+
* @throws ShapeContainerAlreadyAssignedException
150151
*
151152
* @return $this
152153
*/
@@ -175,7 +176,7 @@ public function setContainer(ShapeContainerInterface $pValue = null, $pOverrideO
175176
// Set new \PhpOffice\PhpPresentation\Slide
176177
$this->setContainer($pValue);
177178
} else {
178-
throw new \Exception(sprintf('A %s has already been assigned. Shapes can only exist on one %s.', ShapeContainerInterface::class, ShapeContainerInterface::class));
179+
throw new ShapeContainerAlreadyAssignedException(self::class);
179180
}
180181
}
181182

@@ -328,8 +329,6 @@ public function getShadow(): ?Shadow
328329
}
329330

330331
/**
331-
* @throws \Exception
332-
*
333332
* @return $this
334333
*/
335334
public function setShadow(Shadow $pValue = null)
@@ -350,9 +349,7 @@ public function hasHyperlink()
350349
}
351350

352351
/**
353-
* Get Hyperlink.
354-
*
355-
* @throws \Exception
352+
* Get Hyperlink
356353
*/
357354
public function getHyperlink(): Hyperlink
358355
{
@@ -364,9 +361,7 @@ public function getHyperlink(): Hyperlink
364361
}
365362

366363
/**
367-
* Set Hyperlink.
368-
*
369-
* @throws \Exception
364+
* Set Hyperlink
370365
*/
371366
public function setHyperlink(Hyperlink $pHyperlink = null): self
372367
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class DirectoryNotFoundException extends PhpPresentationException
24+
{
25+
public function __construct(string $path)
26+
{
27+
parent::__construct(sprintf(
28+
'The directory %s doesn\'t exist',
29+
$path
30+
));
31+
}
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class FeatureNotImplementedException extends PhpPresentationException
24+
{
25+
public function __construct()
26+
{
27+
parent::__construct('The feature is not implemented. Please create an issue.');
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class FileCopyException extends PhpPresentationException
24+
{
25+
public function __construct(string $source, string $destination)
26+
{
27+
parent::__construct(sprintf(
28+
'The file %s can\'t be copied to %s',
29+
$source,
30+
$destination
31+
));
32+
}
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class FileNotFoundException extends PhpPresentationException
24+
{
25+
public function __construct(string $path)
26+
{
27+
parent::__construct(sprintf(
28+
'The file "%s" doesn\'t exist',
29+
$path
30+
));
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class FileRemoveException extends PhpPresentationException
24+
{
25+
public function __construct(string $path)
26+
{
27+
parent::__construct(sprintf(
28+
'The file %s can\'t be removed',
29+
$path
30+
));
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class InvalidClassException extends PhpPresentationException
24+
{
25+
public function __construct(string $class, string $error)
26+
{
27+
parent::__construct(sprintf(
28+
'The class %s is invalid (%s)',
29+
$class,
30+
$error
31+
));
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class InvalidFileFormatException extends PhpPresentationException
24+
{
25+
public function __construct(string $path, string $class, string $error = '')
26+
{
27+
if ($class) {
28+
$class = 'class ' . $class;
29+
}
30+
if ($error) {
31+
$error = '(' . $error . ')';
32+
}
33+
34+
parent::__construct(sprintf(
35+
'The file %s is not in the format supported by %s%s%s',
36+
$path,
37+
$class,
38+
!empty($error) ? ' ' : '',
39+
$error
40+
));
41+
}
42+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class InvalidParameterException extends PhpPresentationException
24+
{
25+
public function __construct(string $parameter, string $value)
26+
{
27+
parent::__construct(sprintf(
28+
'The parameter %s can\'t have the value "%s"',
29+
$parameter,
30+
$value
31+
));
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace PhpOffice\PhpPresentation\Exception;
22+
23+
class OutOfBoundsException extends PhpPresentationException
24+
{
25+
public function __construct(int $minBounds, ?int $maxBounds, int $expectedBounds)
26+
{
27+
parent::__construct(sprintf(
28+
'The expected value (%d) is out of bounds (%d, %s)',
29+
$expectedBounds,
30+
$minBounds,
31+
$maxBounds ?? 'Infinite'
32+
));
33+
}
34+
}

0 commit comments

Comments
 (0)