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
Fix issue #67 - New AssetStrategy #93
Conversation
Why is travis failing? I am not experienced in pull requests... Please provide some hint so I can fix... |
Cause you have code style errors. See log: https://travis-ci.org/basz/SlmLocale/jobs/298633316 You are able to run those checks yourself before committing with this command vendor/bin/php-cs-fixer fix -v --diff --dry-run |
One of your tests isnt passing |
By fixing code style issues I accidentally removed a line of code... Now everything should be working. |
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.
looks good feature but would be good if you could update documentation or at least add example
/** @var array */ | ||
protected $file_extensions; | ||
|
||
public function detect(LocaleEvent $event) |
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 method is can be removed already exists in AbstractStrategy
|
||
public function setOptions(array $options = []) | ||
{ | ||
if (array_key_exists('file_extensions', $options)) { |
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.
should not be optional or at least default should be an empty array
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.
default value is now an empty array.
} | ||
} | ||
|
||
public function setOptions(array $options = []) |
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.
@basz I am not sure but this method should be in StrategyInterface
why it is not there?
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.
honestly no idea. I see multiple methods in https://github.com/basz/SlmLocale/blob/master/src/SlmLocale/Strategy/AbstractStrategy.php that should be define d on the interface. Perhaps in a different PR?
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: mfuesslin |
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.
remove this doc block
@@ -191,6 +191,9 @@ public function detect(RequestInterface $request, ResponseInterface $response = | |||
$events->triggerEventUntil(function ($r) use (&$return) { | |||
if ($r instanceof ResponseInterface) { | |||
$return = true; | |||
} elseif ($r === false) { | |||
// return true, if a previous listener returned false. So we can stop processing further listeners. This is needed for AssetStrategy to prevent redirects. | |||
return true; |
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.
would be nice to have this tested also
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.
I do not know exactly how to test this specific part. Maybe someone can help me here?
*/ | ||
class AssetStrategy extends AbstractStrategy | ||
{ | ||
/** @var array */ |
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.
maybe add description something like a list of extensions to be ignored or example
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.
added example in code comment and documentation.
class AssetStrategy extends AbstractStrategy | ||
{ | ||
/** @var array */ | ||
protected $file_extensions; |
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.
default to empty array []
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.
good addition. please fix the suggestions from svycka and I think it is good to go. thanks
} | ||
} | ||
|
||
public function setOptions(array $options = []) |
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.
honestly no idea. I see multiple methods in https://github.com/basz/SlmLocale/blob/master/src/SlmLocale/Strategy/AbstractStrategy.php that should be define d on the interface. Perhaps in a different PR?
refactored here #97 |
Fixing problems of issue #67, which describes problems by using SlmLocale in combination with the famous https://github.com/RWOverdijk/AssetManager module.
Problem
When using asset manager to manage assets in your project, uris of assets getting rewritten to locale aware uris. This leads to 404 not found, because the assetmanager is not able to resolve them anymore. Therefore we need a strategy to cope such uris.
Solution
The provided AssetStrategy checks if the requested uri is an asset and prevents url rewriting through other strategies.
Example config