-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #39 Fixes #40 remove laminas-loader dependency #95
Fixes #39 Fixes #40 remove laminas-loader dependency #95
Conversation
0def30d
to
691dfad
Compare
travis build green 🎉 |
@samsonasik please copy the description from original PR, so wouldn't have to click dozen of links to get needed information. for example, I'd like to know why this is BC break. |
@glensc updated, thanks ;) |
@samsonasik info why this is BC break still missing. |
The removing of public method is BC break, that is in the description. |
@samsonasik write it so then |
that is in the description that I copied |
@samsonasik seems you didn't get my message saying that copy text from the original issue, so wouldn't have to click dozen of links to get the needed information. for example, I'd like to know why this is BC break. now that info is spread around in comments in several issues/pull requests, not in compact form for current and future readers can find in one place. |
src/Headers.php
Outdated
/** | ||
* Set an alternate implementation for the PluginClassLoader | ||
* | ||
* @param PluginClassLocator $pluginClassLoader | ||
* @return Headers | ||
*/ | ||
public function setPluginClassLoader(PluginClassLocator $pluginClassLoader) | ||
{ | ||
$this->pluginClassLoader = $pluginClassLoader; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Return an instance of a PluginClassLocator, lazyload and inject map if necessary | ||
* | ||
* @return PluginClassLocator | ||
*/ | ||
public function getPluginClassLoader() | ||
{ | ||
if ($this->pluginClassLoader === null) { | ||
$this->pluginClassLoader = new Header\HeaderLoader(); | ||
} | ||
return $this->pluginClassLoader; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is the BC break; users calling those methods now will have errors occur.
There are two options:
- Bump to a new major version. This is not terribly enticing, as new major versions often take time to get traction, and we'd likely want to delay release until there are other BC breaks in place that we want to achieve.
- Keep the methods, but change them to indicate deprecation, as well as to modify how they work slightly.
If we went the second route:
- We can remove the parameter typehint on
setPluginClassLoader()
(type widening is allowed for parameters), and internally check for either aHeaderLoader
instance OR a laminas-loaderPluginClassLocator
. In the second case, we'd raise a deprecation notice. - We'd change the return typehint on
getPluginClassLoader()
toHeaderLoader|PluginClassLocator
, and raise a deprecation notice if it is called.
We'd need to ensure that the same property name is used by both these methods and resolveHeaderClass()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weierophinney I've updated keep setPluginClassLoader() and getPluginClassLoader() with E_USER_DEPRECATION mark and keep property pluginClassLoader
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
…PRECATION mark and keep property pluginClassLoader Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
b2f4e6e
to
05bca30
Compare
- Adds `@deprecated` and `@todo` annotations to the `$pluginClassLoader` property and the `setPluginClassLoader()` and `getPluginClassLoader()` methods - Adds `getHeaderLoader()` and `setHeaderLoader()` methods to allow providing alternate implementations. - Adds tests to ensure that deprecation notices are emitted. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
05bca30
to
ba55363
Compare
@samsonasik I pushed additional changes to your branch. Basically:
I think it's ready to ship now! |
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samsonasik I almost merged this, and then realized there's a bigger BC break we need to address.
Removing the extends PluginClassLoader
from HeaderLoader
without implementing the public methods it defined is the big BC break here. With it removed, users who previously interacted with the default instance now will have breakage.
What we need to do is implement these methods:
public static function addStaticMap($map)
public function registerPlugin($shortName, $className)
(this is theadd()
method you defined)public function registerPlugins($map)
public function unregisterPlugin($shortName)
(this is theremove()
method you defined)public function getRegisteredPlugins()
public function isLoaded($name)
(this is thehas()
method you defined)public function getClassName($name)
public function load($name)
(this is theget()
method you defined)public function getIterator()
(you'll need to implementIteratorAggregate
)
We can keep your existing names and mark the old ones as deprecated if you'd like; the main thing is ensuring that the API is 1:1 with what we had previously.
I can likely work on this Wednesday 2020-07-29 if you don't have time.
@weierophinney how do you trigger autoloader then? via autoload.files? |
@glensc —
That's a cool technique; I'd not seen using
Yes. Generally, we've created an However, I don't think it's going to happen right now. More below. @samsonasik and @michalbundyra — I've been thinking on this a ton, and there's no clean way to do this in a BC manner. However, we can make a change that provides forwards compatibility and formally deprecates usage of laminas-loader, so that a v3 can remove it. Here's how.
We then document in both the CHANGELOG and the documentation the new interface, implementation, and default behavior, so that users know that they need to start modifying their code if they relied on the Thoughts? |
src/Headers.php
Outdated
* @param PluginClassLocator $pluginClassLoader | ||
* @deprecated since 2.12.0 | ||
* @todo Remove for version 3.0.0 | ||
* @param Header\HeaderLoader|\Laminas\Loader\PluginClassLocator $pluginClassLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laminas\Loader\PluginClassLocator
can be changed with PluginClassLocator
as the class re-added to use statement.
@weierophinney I think that |
Still in I'm willing to do the work, if you'd like. |
@weierophinney ok, I will let you continue. Thank you |
Restores HeaderLoader from develop branch, and renames newly introduced version to HeaderLocator. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
you can use composer "replace" trick to remove "laminas-loader" from your installed vendors: but this solution is suitable only for applications. don't do this in libraries or your users will hate you. |
Also details update to PHP 7.1. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Also details update to PHP 7.1. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
40191de
to
849609f
Compare
Extracts `HeaderLocatorInterface` from `HeaderLocator`. In doing so, I decided to bump the minimum supported PHP version to 7.1 (which we can do on new minor versions), as it allows us to specify scalar typehints, nullable typehints, and void return types, providing a stronger contract. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
This will be a forwards-compat patch, and leave the original `HeaderLoader` in place. As such, we need to remove the `PluginClassLocator` stub from the test assets. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
- Reverts `(set|get)PluginClassLoader()` method to original implementations, but with the addition of triggering deprecation notices. `trigger_error()` is now silenced, per recommendation from @glensc. - Adds `$headerLocator` property. - Renames `(get|set)HeaderLoader()` methods to `get|setHeaderLocator()`, and adds typehints. These now operate on the `$headerLocator` property. - Modifies `resolveHeaderClass()` to check for a non-null `$pluginClassLoader` property; if found, it uses that to resolve the header class, defaulting to `GenericHeader` if not loaded. - Updates PHPUnit dependency to 7.5.20, so we can use the various error types it provides. This is possible since we now depend on 7.1+. However, I did not update to later versions of PHPUnit as they would require refactoring tests to add typehints. - Refactors the unit tests to mirror the changes made. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Also details update to PHP 7.1. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
849609f
to
ae5de31
Compare
@michalbundyra and/or @samsonasik — changes are in place. I've updated the description to better detail what has finally happened, and detailed it in the changelog as well. Tests are green. :) |
public function get(string $name, ?string $default = null): ?string; | ||
|
||
public function has(string $name): bool; | ||
|
||
public function add(string $name, string $class): void; | ||
|
||
public function remove(string $name): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are why I lumped the bump in PHP version into the patch: scalar type hints, return type hints, nullable types, and void return types. Essentially it is this patch that necessitates the bump in minimum version, which is exactly what the TSC decision was about in that first meeting. 😄
*/ | ||
public function setPluginClassLoader(PluginClassLocator $pluginClassLoader) | ||
{ | ||
// Silenced; can be caught in custom error handlers. | ||
@trigger_error(sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @glensc pointed out, this is how Symfony does deprecation notices. They'll get caught in error handlers, but not if unhandled. This prevents breakage in most use cases, but if you log errors, you'll catch them in your logs.
if (! $instanceOrFieldName instanceof Header\HeaderInterface && ! is_string($instanceOrFieldName)) { | ||
throw new Exception\InvalidArgumentException(sprintf( | ||
'%s requires a string or %s instance; received %s', | ||
__METHOD__, | ||
Header\HeaderInterface::class, | ||
is_object($instanceOrFieldName) ? get_class($instanceOrFieldName) : gettype($instanceOrFieldName) | ||
)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit was interesting. Because I turned on strict types in this file, I discovered a test that was passing null
to this method, which was incorrect. As such, I added this guard (and updated the test!).
Also details update to PHP 7.1. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
ae5de31
to
8e286c0
Compare
@weierophinney can you add a summary to users what they should do to stop using zend-loader? just upgrade and add composer "replace" to loader package? assuming just used defaults previously |
@glensc By default, if you are NOT calling
Beyond that, if you're using the laminas-mvc, you cannot really replace the laminas-loader package, as it's used by the MVC (though the usage is largely deprecated). As such, I haven't detailed how to do that; it's a niche use case. But what it does do is open the door for us to remove it from this component in v3, and, if v3 is not released before releases of MVC components that do not use it, we can replace it in the laminas-mvc-skeleton package. |
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Also details update to PHP 7.1. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Description
Re-create and modify zendframework/zend-mail#186 by @acelaya
Fixes #39
Fixes #40
Original PR description:
Actual changes
Laminas\Mail\Header\HeaderLocatorInterface
, defining how to map header names to classes.Laminas\Mail\Header\HeaderLocator
as a default implementation of that interface.Laminas\Mail\Headers
as follows:setPluginClassLoader()
andgetPluginClassLoader()
as deprecated.$headerLocator
property and accompanyingsetHeaderLocator()
andgetHeaderLocator()
methods.resolveHeaderClass()
that:$pluginClassLoader
property is available, uses that to locate the header class.getHeaderLocator()
to locate the header class.This approach provides a forwards-compatible approach to removing laminas-loader in version 3.0.