| 1 | <?php |
||
| 16 | class FileDictLoader implements DictLoaderInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Words segment name. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $segmentName = 'words_%s'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Dict path. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $path; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Segment files |
||
| 34 | * |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | protected $segments = array(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Constructor. |
||
| 41 | * |
||
| 42 | * @param string $path |
||
| 43 | * @param boolean $preload |
||
| 44 | */ |
||
| 45 | 18 | public function __construct($path, $preload = false) |
|
| 46 | { |
||
| 47 | 18 | $this->path = $path; |
|
| 48 | 18 | for ($i = 0; $i < 100; ++$i) { |
|
| 49 | 18 | $segment = $this->path . '/' . sprintf($this->segmentName, $i); |
|
| 50 | 18 | if (file_exists($segment)) { |
|
| 51 | 18 | $this->segments[$i] = array('segment' => $segment); |
|
| 52 | 18 | if ($preload) { |
|
| 53 | $this->segments[$i]['dictionary'] = (array) include $segment; |
||
| 54 | } |
||
| 55 | 18 | } |
|
| 56 | 18 | } |
|
| 57 | 18 | } |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Load dict. |
||
| 61 | * |
||
| 62 | * @param Closure $callback |
||
| 63 | */ |
||
| 64 | 9 | public function map(Closure $callback) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Load surname dict. |
||
| 75 | * |
||
| 76 | * @param Closure $callback |
||
| 77 | */ |
||
| 78 | 2 | public function mapSurname(Closure $callback) |
|
| 87 | } |
||
| 88 |