public function read()
{
$data = array();
if (file_exists($this->options['directory'])) {
$pattern = $this->options['mode'] == self::MODE_DIRECTORY_AS_CATEGORY ? '/*' : '';
if (is_array($this->options['include']) && count($this->options['include']) !== 0) {
$files = array();
foreach ($this->options['include'] as $include) {
$files = array_merge($files, array_slice(glob("{$this->options['directory']}/{$include}{$pattern}", GLOB_NOSORT), 0, $this->options['limit']));
}
} else {
$files = array_slice(glob("{$this->options['directory']}{$pattern}/*", GLOB_NOSORT), 0, $this->options['limit']);
}
foreach ($files as $filename) {
if (is_file($filename)) {
if ($this->options['mode'] === self::MODE_DIRECTORY_AS_CATEGORY) {
$categoryPath = dirname($filename);
} else {
$categoryPath = $filename;
}
$data[] = array('category' => basename($categoryPath), 'document' => file_get_contents($filename));
}
}
}
return $data;
}