Skip to content

Commit

Permalink
Update backwards compat alias generation.
Browse files Browse the repository at this point in the history
Generate aliases in the new files. This allows us to resolve issues
where typehints result in fatal errors by ensuring that aliases exist
when the new class is used. The old class location forces the new
location to load which ensures that both names resolve to the same state
(class + alias loaded).

Unfortunately this requires relaxing the PSR1 side-effect rules as the
`@codingStandardsIgnoreStart` tags did not work.
  • Loading branch information
markstory committed Jan 22, 2017
1 parent 131f0ed commit 946478e
Show file tree
Hide file tree
Showing 32 changed files with 75 additions and 37 deletions.
2 changes: 0 additions & 2 deletions composer.json
Expand Up @@ -42,8 +42,6 @@
"src/Core/functions.php",
"src/Collection/functions.php",
"src/I18n/functions.php",
"src/Database/backwards_compat.php",
"src/Http/backwards_compat.php",
"src/Utility/bootstrap.php"
]
},
Expand Down
7 changes: 6 additions & 1 deletion phpcs.xml.dist
@@ -1,4 +1,9 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Core">
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>

<!-- Necessary for class aliases used for backwards compat -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<severity>0</severity>
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions src/Database/Schema/Table.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earlier 3.x versions.
class_alias('Cake\Database\Schema\TableSchema', 'Cake\Database\Schema\Table');
// @deprecated Load new class and alias
class_exists('Cake\Database\Schema\TableSchema');
3 changes: 3 additions & 0 deletions src/Database/Schema/TableSchema.php
Expand Up @@ -879,3 +879,6 @@ public function dropConstraintSql(ConnectionInterface $connection)
return $dialect->dropConstraintSql($this);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Database\Schema\TableSchema', 'Cake\Database\Schema\Table');
3 changes: 0 additions & 3 deletions src/Database/backwards_compat.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Http/Client.php
Expand Up @@ -549,3 +549,5 @@ protected function _createAuth($auth, $options)
return new $class($this, $options);
}
}
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client', 'Cake\Network\Http\Client');
3 changes: 3 additions & 0 deletions src/Http/Client/Adapter/Stream.php
Expand Up @@ -320,3 +320,6 @@ public function contextOptions()
return array_merge($this->_contextOptions, $this->_sslContextOptions);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Adapter\Stream', 'Cake\Network\Http\Adapter\Stream');
3 changes: 3 additions & 0 deletions src/Http/Client/Auth/Basic.php
Expand Up @@ -72,3 +72,6 @@ protected function _generateHeader($user, $pass)
return 'Basic ' . base64_encode($user . ':' . $pass);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Auth\Basic', 'Cake\Network\Http\Auth\Basic');
3 changes: 3 additions & 0 deletions src/Http/Client/Auth/Digest.php
Expand Up @@ -142,3 +142,6 @@ protected function _generateHeader(Request $request, $credentials)
return $authHeader;
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Auth\Digest', 'Cake\Network\Http\Auth\Digest');
3 changes: 3 additions & 0 deletions src/Http/Client/Auth/Oauth.php
Expand Up @@ -350,3 +350,6 @@ protected function _encode($value)
);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Auth\Oauth', 'Cake\Network\Http\Auth\Oauth');
3 changes: 3 additions & 0 deletions src/Http/Client/CookieCollection.php
Expand Up @@ -117,3 +117,6 @@ public function getAll()
return array_values($this->_cookies);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\CookieCollection', 'Cake\Network\Http\CookieCollection');
3 changes: 3 additions & 0 deletions src/Http/Client/FormData.php
Expand Up @@ -268,3 +268,6 @@ public function __toString()
return http_build_query($data);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\FormData', 'Cake\Network\Http\FormData');
3 changes: 3 additions & 0 deletions src/Http/Client/FormDataPart.php
Expand Up @@ -221,3 +221,6 @@ public function __toString()
return $out;
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\FormDataPart', 'Cake\Network\Http\FormData\Part');
3 changes: 3 additions & 0 deletions src/Http/Client/Message.php
Expand Up @@ -171,3 +171,6 @@ public function body($body = null)
return $this;
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Message', 'Cake\Network\Http\Message');
3 changes: 3 additions & 0 deletions src/Http/Client/Request.php
Expand Up @@ -254,3 +254,6 @@ public function body($body = null)
return $this;
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Request', 'Cake\Network\Http\Request');
3 changes: 3 additions & 0 deletions src/Http/Client/Response.php
Expand Up @@ -601,3 +601,6 @@ public function __isset($name)
return isset($this->{$key});
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Client\Response', 'Cake\Network\Http\Response');
3 changes: 3 additions & 0 deletions src/Http/Response.php
Expand Up @@ -2439,3 +2439,6 @@ public function __debugInfo()
];
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\Response', 'Cake\Network\Response');
3 changes: 3 additions & 0 deletions src/Http/ServerRequest.php
Expand Up @@ -2132,3 +2132,6 @@ public function offsetUnset($name)
unset($this->params[$name]);
}
}

// @deprecated Add backwards compat alias.
class_alias('Cake\Http\ServerRequest', 'Cake\Network\Request');
4 changes: 0 additions & 4 deletions src/Http/backwards_compat.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Network/Http/Adapter/Stream.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Adapter\Stream', 'Cake\Network\Http\Adapter\Stream');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Adapter\Stream');
4 changes: 2 additions & 2 deletions src/Network/Http/Auth/Basic.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Auth\Basic', 'Cake\Network\Http\Auth\Basic');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Auth\Basic');
4 changes: 2 additions & 2 deletions src/Network/Http/Auth/Digest.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Auth\Digest', 'Cake\Network\Http\Auth\Digest');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Auth\Digest');
4 changes: 2 additions & 2 deletions src/Network/Http/Auth/Oauth.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Auth\Oauth', 'Cake\Network\Http\Auth\Oauth');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Auth\Oauth');
4 changes: 2 additions & 2 deletions src/Network/Http/Client.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client', 'Cake\Network\Http\Client');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client');
4 changes: 2 additions & 2 deletions src/Network/Http/CookieCollection.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\CookieCollection', 'Cake\Network\Http\CookieCollection');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\CookieCollection');
4 changes: 2 additions & 2 deletions src/Network/Http/FormData.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\FormData', 'Cake\Network\Http\FormData');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\FormData');
3 changes: 2 additions & 1 deletion src/Network/Http/FormData/Part.php
@@ -1,2 +1,3 @@
<?php
class_alias('Cake\Http\Client\FormDataPart', 'Cake\Network\Http\FormData\Part');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\FormDataPart');
4 changes: 2 additions & 2 deletions src/Network/Http/Message.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Message', 'Cake\Network\Http\Message');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Message');
4 changes: 2 additions & 2 deletions src/Network/Http/Request.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Request', 'Cake\Network\Http\Request');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Request');
4 changes: 2 additions & 2 deletions src/Network/Http/Response.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Client\Response', 'Cake\Network\Http\Response');
// @deprecated Load new class and alias.
class_exists('Cake\Http\Client\Response');
4 changes: 2 additions & 2 deletions src/Network/Request.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\ServerRequest', 'Cake\Network\Request');
// @deprecated Load new class and alias
class_exists('Cake\Http\ServerRequest');
4 changes: 2 additions & 2 deletions src/Network/Response.php
@@ -1,3 +1,3 @@
<?php
// @deprecated Backwards compatibility with earler 3.x versions.
class_alias('Cake\Http\Response', 'Cake\Network\Response');
// @deprecated Load new class and alias
class_exists('Cake\Http\Response');

0 comments on commit 946478e

Please sign in to comment.