Skip to content

Commit

Permalink
change the loader logic of load dict files. (#121)
Browse files Browse the repository at this point in the history
* change the loader logic of load dict files.

* change the loader logic of load dict files.
  • Loading branch information
Honvid authored and overtrue committed Apr 21, 2019
1 parent 046e162 commit 89f560e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/FileDictLoader.php
Expand Up @@ -49,7 +49,9 @@ public function __construct($path)
*/
public function map(Closure $callback)
{
for ($i = 0; $i < 100; ++$i) {
$dirs = scandir($this->path);
$size = count($dirs) - 2;
for ($i = 0; $i < $size; ++$i) {
$segment = $this->path.'/'.sprintf($this->segmentName, $i);

if (file_exists($segment)) {
Expand Down
7 changes: 6 additions & 1 deletion src/GeneratorFileDictLoader.php
Expand Up @@ -57,7 +57,9 @@ public function __construct($path)
{
$this->path = $path;

for ($i = 0; $i < 100; ++$i) {
$dirs = scandir($this->path);
$size = count($dirs) - 2;
for ($i = 0; $i < $size; ++$i) {
$segment = $this->path.'/'.sprintf($this->segmentName, $i);

if (file_exists($segment) && is_file($segment)) {
Expand All @@ -70,6 +72,7 @@ public function __construct($path)
* Construct a new file object.
*
* @param string $filename file path
* @param string $mode file open mode
*
* @return SplFileObject
*/
Expand All @@ -82,6 +85,8 @@ protected function openFile($filename, $mode = 'r')
* get Generator syntax.
*
* @param array $handles SplFileObjects
*
* @return Generator
*/
protected function getGenerator(array $handles)
{
Expand Down
4 changes: 3 additions & 1 deletion src/MemoryFileDictLoader.php
Expand Up @@ -55,7 +55,9 @@ public function __construct($path)
{
$this->path = $path;

for ($i = 0; $i < 100; ++$i) {
$dirs = scandir($this->path);
$size = count($dirs) - 2;
for ($i = 0; $i < $size; ++$i) {
$segment = $path.'/'.sprintf($this->segmentName, $i);

if (file_exists($segment)) {
Expand Down

0 comments on commit 89f560e

Please sign in to comment.