Skip to content
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

Closed
wants to merge 10 commits into from
Closed

Fix issue #67 - New AssetStrategy #93

wants to merge 10 commits into from

Conversation

koseduhemak
Copy link
Contributor

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

return [
    'slm_locale' => [
        'default' => 'de_DE',

        'supported' => ['en_GB', 'de_DE'],

        'strategies' => [
           [
                'name' => SlmLocale\Strategy\AssetStrategy::class,
                'options' => [
                    'file_extensions' => [
                        'css', 'js'
                    ]
                ]
            ],
            'query',
            [
                'name' => \SlmLocale\Strategy\UriPathStrategy::class,
                'options' => [
                    'redirect_when_found' => true,
                    'aliases' => array('de' => 'de_DE', 'en' => 'en_GB'),
                ]
            ],
            'cookie',
            'acceptlanguage'
        ],

        'mappings' => [
            'en' => 'en_GB',
            'de' => 'de_DE',
        ]
    ],
];

@koseduhemak
Copy link
Contributor Author

Why is travis failing? I am not experienced in pull requests... Please provide some hint so I can fix...

@basz
Copy link
Owner

basz commented Nov 7, 2017

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

@basz
Copy link
Owner

basz commented Nov 7, 2017

One of your tests isnt passing

@koseduhemak
Copy link
Contributor Author

By fixing code style issues I accidentally removed a line of code... Now everything should be working.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 80.211% when pulling 85f13fd on koseduhemak:master into 7df75eb on basz:master.

Copy link
Collaborator

@svycka svycka left a 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)
Copy link
Collaborator

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)) {
Copy link
Collaborator

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

Copy link
Contributor Author

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 = [])
Copy link
Collaborator

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?

Copy link
Owner

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
Copy link
Collaborator

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;
Copy link
Collaborator

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

Copy link
Contributor Author

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 */
Copy link
Collaborator

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

Copy link
Contributor Author

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to empty array []

@svycka svycka requested a review from basz November 8, 2017 09:57
Copy link
Owner

@basz basz left a 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 = [])
Copy link
Owner

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?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 80.423% when pulling ed76a86 on koseduhemak:master into 7df75eb on basz:master.

@svycka svycka self-assigned this Nov 15, 2017
@svycka svycka added this to the v0.3.0 milestone Nov 15, 2017
svycka pushed a commit that referenced this pull request Nov 16, 2017
@svycka
Copy link
Collaborator

svycka commented Nov 16, 2017

refactored here #97

@svycka svycka closed this Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants