RobotLoader: Invalidace cache při přesunutí souboru (patch included)

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Jan Tvrdík
Nette guru | 2595
+
0
-

Pokud v současné verzi přejmenuji soubor se třídou, tak musím smazat cache ručně, protože automatická invalidace se neprovede. Následující patch by to měl řešit:

Index: RobotLoader.php
===================================================================
--- RobotLoader.php	(revision 227)
+++ RobotLoader.php	(working copy)
@@ -95,11 +95,17 @@
 	public function tryLoad($type)
 	{
 		$type = strtolower($type);
-		$type = ltrim($type, '\\'); // PHP namespace bug #49143
+		$type = ltrim($type, '\\'); // PHP namespace bug #49143
 		if (isset($this->list[$type])) {
 			if ($this->list[$type] !== FALSE) {
-				LimitedScope::load($this->list[$type][0]);
-				self::$count++;
+				if ($this->isProduction() || is_file($this->list[$type][0])) {
+					LimitedScope::load($this->list[$type][0]);
+					self::$count++;
+
+				} else {
+					$this->list[$type] = NULL;
+					$this->tryLoad($type);
+				}
 			}

 		} else {
@@ -200,7 +206,7 @@
 	private function addClass($class, $file, $time)
 	{
 		$class = strtolower($class);
-		if (!empty($this->list[$class]) && $this->list[$class][0] !== $file) {
+		if (!empty($this->list[$class]) && $this->list[$class][0] !== $file && is_file($this->list[$class][0])) {
 			spl_autoload_call($class); // hack: enables exceptions
 			throw new \InvalidStateException("Ambiguous class '$class' resolution; defined in $file and in " . $this->list[$class][0] . ".");
 		}

Poznámka: Vypnuto v produkčním módu kvůli výkonu (volání funkce is_file před vkládáním všech souborů).

David Grudl
Nette Core | 8147
+
0
-

Díky, implementováno