1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: namespace picon;
24:
25: 26: 27: 28: 29: 30: 31:
32: class ResourceReference
33: {
34: private $file;
35: private $identifier;
36:
37: public function __construct($file, Identifier $identifier)
38: {
39: Args::isString($file, 'file');
40: $this->file = $file;
41: $this->identifier = $identifier;
42: }
43:
44: public function getFile()
45: {
46: return $this->file;
47: }
48:
49: public function getIdentifier()
50: {
51: return $this->identifier;
52: }
53:
54: public function loadResource()
55: {
56: $fileName = $this->getResourceFile($this->identifier->getFullyQualifiedName());
57:
58: if($fileName==null)
59: {
60: throw new \RuntimeException(sprintf("Unable to located file for resource %s with class scope %s", $this->file, $this->identifier->getFullyQualifiedName()));
61: }
62: $resouce = @file_get_contents($fileName);
63:
64: if($resouce==false)
65: {
66: throw new \FileException(sprintf("Failed to open file %s", $fileName));
67: }
68: return $resouce;
69: }
70:
71: private function getResourceFile($className)
72: {
73: $reflection = new \ReflectionClass($className);
74: $fileInfo = new \SplFileInfo($reflection->getFileName());
75:
76: $file = $fileInfo->getPath()."/".$this->file;
77: if(file_exists($file))
78: {
79: return $file;
80: }
81: if(get_parent_class($className)!=false)
82: {
83: return $this->getResourceFile(get_parent_class($className));
84: }
85: return null;
86: }
87: }
88:
89: ?>
90: