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

Fixed version truncation so one client doesn't affect the others #6075

Merged
merged 2 commits into from
Aug 9, 2020
Merged

Fixed version truncation so one client doesn't affect the others #6075

merged 2 commits into from
Aug 9, 2020

Conversation

Spikes042
Copy link
Contributor

When ParserAbstract::$maxMinorParts is changed by any
Client Parser, it is propagated to all Client Parsers. This
happens because static properties defined ONLY in the parent
class shares a common value with the child class.

To set version truncation specifically for a custom ClientParser, we
need to redefine ParserAbstract::$maxMinorParts in the child class
and use late static binding to access the property.

Example:

<?php

use DeviceDetector\Parser\Client\ClientParserAbstract;

class MyAppParser extends ClientParserAbstract{
    protected static $maxMinorParts = self::VERSION_TRUNCATION_PATCH;
    protected $fixtureFile = 'my_app.yml';
    protected $parserName = 'myapp';

    protected function getRegexesDirectory(){
        return __DIR__;
    }
}

More on late static binding in PHP:
https://www.php.net/manual/en/language.oop5.late-static-bindings.php

When `ParserAbstract::$maxMinorParts` is changed by any
Client Parser, it is propagated to all Client Parsers. This
happens because static properties defined ONLY in the parent
class shares a common value with the child class.

To set version truncation specifically for a custom ClientParser, we
need to redefine `ParserAbstract::$maxMinorParts` in the child class
and use late static binding to access the property.

Example:
```
<?php

use DeviceDetector\Parser\Client\ClientParserAbstract;

class MyAppParser extends ClientParserAbstract{
    protected static $maxMinorParts = self::VERSION_TRUNCATION_PATCH;
    protected $fixtureFile = 'my_app.yml';
    protected $parserName = 'myapp';

    protected function getRegexesDirectory(){
        return __DIR__;
    }
}
````

More on late static binding in PHP:
https://www.php.net/manual/en/language.oop5.late-static-bindings.php
@sgiehl
Copy link
Member

sgiehl commented Jan 8, 2020

@Spikes042 sorry for the late response. Actually the version truncation was meant to be global. But guess it doesn't matter to make it possible to change that, as long as the default behaviour doesn't change

@Spikes042
Copy link
Contributor Author

No problem @sgiehl, I can understand you have other things to do.

Yes, I thought of that and it shouldn't be a problem, as generally, a user should use ParserAbstract::setVersionTruncation($type) to set version truncation, which applies it globally.
In fact, as far as the user doesn't redefine ParserAbstract::$maxMinorParts in the child class, it will use the global (parent class) value

@Spikes042
Copy link
Contributor Author

Hello @sgiehl
Is there a chance of this getting merged?

@sgiehl sgiehl merged commit 681cd10 into matomo-org:master Aug 9, 2020
@sgiehl
Copy link
Member

sgiehl commented Aug 9, 2020

Sorry for the delay and thanks again for the improvement.

@Spikes042
Copy link
Contributor Author

No problem at all. Really do appreciate

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

2 participants