TYPO3 CMS  TYPO3_6-2
ClassLoaderBackend.php
Go to the documentation of this file.
1 <?php
3 
18 
26 
33  protected $requireFileTemplate = '<?php require \'%s\';';
34 
44  public function setLinkToPhpFile($entryIdentifier, $filePath) {
45  if ($entryIdentifier === '') {
46  throw new \InvalidArgumentException('The specified entry identifier must not be empty.', 1364205170);
47  }
48  if (!PathUtility::isAbsolutePath($filePath)) {
49  throw new \InvalidArgumentException('Only absolute paths are allowed for the class loader, given path was: ' . $filePath, 1381923089);
50  }
51  if (!@file_exists($filePath)) {
52  throw new \InvalidArgumentException('The specified file path (' . $filePath . ') must exist.', 1364205235);
53  }
54  if (strtolower(substr($filePath, -4)) !== '.php') {
55  throw new \InvalidArgumentException('The specified file (' . $filePath . ') must be a php file.', 1364205377);
56  }
57  if ($entryIdentifier !== basename($entryIdentifier)) {
58  throw new \InvalidArgumentException('The specified entry identifier (' . $entryIdentifier . ') must not contain a path segment.', 1364205166);
59  }
60 
61  $this->set($entryIdentifier, sprintf($this->requireFileTemplate, $filePath));
62  }
63 
72  public function setLinkToOtherCacheEntry($entryIdentifier, $otherEntryIdentifier) {
73  $otherCacheEntryPathAndFilename = $this->cacheDirectory . $otherEntryIdentifier . $this->cacheEntryFileExtension;
74  $this->setLinkToPhpFile($entryIdentifier, $otherCacheEntryPathAndFilename);
75  }
76 
85  public function get($entryIdentifier) {
86  if ($entryIdentifier !== basename($entryIdentifier)) {
87  throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756880);
88  }
89  $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
90  if (!@file_exists($pathAndFilename)) {
91  return FALSE;
92  }
93  return file_get_contents($pathAndFilename);
94  }
95 
104  public function getPathOfRequiredFileInCacheEntry($entryIdentifier) {
105  $result = FALSE;
106 
107  $fileContent = $this->get($entryIdentifier);
108  if ($fileContent !== FALSE) {
109  $pattern = '!^' . sprintf(preg_quote($this->requireFileTemplate), '(.+)') . '!i';
110  $matches = array();
111  if (preg_match($pattern, $fileContent, $matches) === 1) {
112  $requireString = $matches[1];
113  $result = $requireString;
114  }
115  }
116  return $result;
117  }
118 
127  public function has($entryIdentifier) {
128  if ($entryIdentifier !== basename($entryIdentifier)) {
129  throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756879);
130  }
131  $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
132  return @file_exists($pathAndFilename);
133  }
134 
143  protected function isCacheFileExpired($cacheEntryPathAndFilename) {
144  return @file_exists($cacheEntryPathAndFilename) === FALSE;
145  }
146 
154  protected function findCacheFilesByIdentifier($entryIdentifier) {
155  $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
156  return @file_exists($pathAndFilename) ? array($pathAndFilename) : FALSE;
157  }
158 
167  public function requireOnce($entryIdentifier) {
168  $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
169  return @file_exists($pathAndFilename) ? require_once $pathAndFilename : FALSE;
170  }
171 
172 }
setLinkToOtherCacheEntry($entryIdentifier, $otherEntryIdentifier)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.