Skip to content

Commit def3908

Browse files
committed
Throw an exception when a font is not found.
1 parent 8262bb5 commit def3908

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace FontLib\Exception;
4+
5+
class FontNotFoundException extends \Exception
6+
{
7+
public function __construct($fontPath)
8+
{
9+
$this->message = 'Font not found in: ' . $fontPath;
10+
}
11+
}

src/FontLib/Font.php

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace FontLib;
1010

11+
use FontLib\Exception\FontNotFoundException;
12+
1113
/**
1214
* Generic font file.
1315
*
@@ -22,6 +24,10 @@ class Font {
2224
* @return TrueType\File|null $file
2325
*/
2426
public static function load($file) {
27+
if(!file_exists($file)){
28+
throw new FontNotFoundException($file);
29+
}
30+
2531
$header = file_get_contents($file, false, null, null, 4);
2632
$class = null;
2733

0 commit comments

Comments
 (0)