88 */
99namespace UAParser \Util \Logfile ;
1010
11+ use Symfony \Component \Finder \Finder ;
12+ use Symfony \Component \Finder \SplFileInfo ;
1113use UAParser \Exception \ReaderException ;
1214
1315abstract class AbstractReader implements ReaderInterface
@@ -34,11 +36,34 @@ private static function getReaders()
3436 return static ::$ readers ;
3537 }
3638
39+ static ::$ readers = static ::getCustomReaders ();
3740 static ::$ readers [] = new ApacheCommonLogFormatReader ();
3841
3942 return static ::$ readers ;
4043 }
4144
45+ public static function autoloadCustomReaders ($ clazz )
46+ {
47+ $ parts = explode ('\\' , $ clazz );
48+ $ path = __DIR__ .DIRECTORY_SEPARATOR .'Custom ' .DIRECTORY_SEPARATOR .end ($ parts ).'.php ' ;
49+ if (is_file ($ path )) {
50+ require $ path ;
51+ }
52+ }
53+
54+ private static function getCustomReaders ()
55+ {
56+ $ finder = Finder::create ()->in (__DIR__ .DIRECTORY_SEPARATOR .'Custom ' );
57+ array_map (array ($ finder , 'name ' ), array ('*.php ' ));
58+
59+ $ readers = array ();
60+ foreach ($ finder as $ file ) {
61+ $ clazz = __NAMESPACE__ .'\\' .$ file ->getBasename ('.php ' );
62+ $ readers [] = new $ clazz ;
63+ }
64+ return $ readers ;
65+ }
66+
4267 public function test ($ line )
4368 {
4469 $ matches = $ this ->match ($ line );
@@ -68,3 +93,5 @@ protected function match($line)
6893
6994 abstract protected function getRegex ();
7095}
96+
97+ spl_autoload_register (array ('UAParser\Util\Logfile\AbstractReader ' ,'autoloadCustomReaders ' ));
0 commit comments