jablonka.czprosek.czf

freenet-router

Subversion Repositories:
[/] [trunk/] [freenet-router/] [var/] [www/] [freenet-router/] [Framework/] [ClassLoading/] [VersionedClassLoader.php] - Blame information for rev 2

 

Line No. Rev Author Line
12simandl<?php
2 
3namespace Phem\ClassLoading;
4 
5/**
6 * @author kubapet
7 */
8class VersionedClassLoader
9{
10 static function getClass($name, \DateTime $date,$suffix = ".php")
11 {
12 $baseDir = str_replace("\\", DS, $name);
13 
14 $nameArray = explode("\\", $name);
15 $nameArray[0] = APP_DIR;
16 $viewName = \Phem\ToolSuite::getLastArrayItem($nameArray);
17 
18 $lookFor = "";
19 for($i=0;$i<count($nameArray)-1;$i++)
20 {
21 $lookFor .= $nameArray[$i].DS;
22 }
23 
24 $lookFor .= $viewName;
25 
26 $foundFiles = new \Phem\Core\Collection();
27 
28 foreach(glob($lookFor."*") as $file)
29 {
30 $dateStr = \Phem\ToolSuite::getStringBetween($file, $lookFor."_", $suffix);
31 
32 if ($dateStr=="")
33 {
34 $dateStr="1970-01-01";
35 }
36 $validFrom = new \DateTime($dateStr);
37 
38 if ($date >= $validFrom)
39 {
40 $foundFiles->set($file,$validFrom);
41 }
42 }
43 
44 if ($foundFiles->count() == 0)
45 {
46 //Throw exception
47 }
48 
49 $foundFiles->sort(\Phem\Core\CollectionSortType::DESC,"date");
50 
51 $fileNameArr = explode(DS,$foundFiles->getFirstKey());
52 end($fileNameArr);
53 $index = key($fileNameArr);
54 $file = substr($fileNameArr[$index],0,strlen($fileNameArr[$index])-strlen($suffix));
55 
56 $nameArray[0] = APP_NAMESPACE;
57 end($nameArray);
58 $index = key($nameArray);
59 $nameArray[$index] = $file;
60 
61 $className = implode("\\",$nameArray);
62 
63 return $className;
64 
65 }
66}

Powered by WebSVN 2.2.1