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

Use PSR-4 for autoloader #4074

Closed
mattab opened this issue Aug 11, 2013 · 9 comments
Closed

Use PSR-4 for autoloader #4074

mattab opened this issue Aug 11, 2013 · 9 comments
Labels
Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Aug 11, 2013

Todo post #4059

@robocoder
Copy link
Contributor

Any thoughts on renaming "core/" to "core/Piwik", and "plugins" to "plugins/Piwik/Plugin"? Then the codebase would be PSR0 compliant and we could use something like this in composer.json:

    "autoload": {
        "psr-0": {
            "Piwik\\Plugin\\": "plugins/"
            "Piwik\\": "core/",
        },
        "classmap": [
            "libs/"
        ]
    }

and eliminate core/Loader.php altogether.

@halfdan
Copy link
Member

halfdan commented Aug 26, 2013

@vipsoft: Great idea!

As an alternative we could also just combine core/plugins into a single src/ folder. This would avoid having a rather redundant "plugins/Piwik/Plugins".

We would then have "src/Piwik" and "src/Piwik/Plugins"

"autoload": {
  "psr-0": {
    "Piwik\\": "src/"
  },
  "classmap": [
    "libs/"
  ]
}

With composer we already have a PSR-0 compatible autoloader and can get rid of the unnecessary core/Loader.php.

@mattab
Copy link
Member Author

mattab commented Aug 26, 2013

I would prefer keeping core/ and plugins/ rather than adding one more level... I'll simplify the Loader.php as a result (rather than use composer autoloader)

@halfdan
Copy link
Member

halfdan commented Aug 26, 2013

This basically means we will not be PSR-0/1/2 compliant. Having the above directory structure is required by PSR-0 and PSR-1/2 require PSR-0 compliancy.

Any option to discuss this matter?

@robocoder
Copy link
Contributor

With the breaking changes of a major version bump, I think this would be the opportune time for PSR-0 compliance. (And PSR-2 depends on PSR-1 which depends on PSR-0.)

Let's ask the team to weigh in.

Caveat: there are still manual include/require but definitely doable.

(For the record, I'm in favor of using the composer autoloader for the tracker as well.)

@tsteur
Copy link
Member

tsteur commented Nov 10, 2013

In da22f52: refs #4074 spl should be always enabled since PHP 5.3 and cannot be disabled, so no need to check for spl. Do not throw an exception in first autoloader if class does not exist, this should give the second autoloader a change to load the class.

@tsteur
Copy link
Member

tsteur commented Nov 10, 2013

In bc758f2: refs #4074 in case we know it is a plugins or a core class, try to load it directly from there and do not look in other folders first. Unfortunately we still need the other logic for backwards compatibility

@mattab
Copy link
Member Author

mattab commented Jan 13, 2014

In a665821: Fix jsProxyTest, ie. make tracker work refs #4493
Why include file manually? because piwik.php does not use autoloader yet.
Maybe as part of refs #4074 we could setup autoloader for piwik.php / tracking API.

@mattab
Copy link
Member Author

mattab commented Sep 8, 2014

Issue should be closed since we now use Composer autoloader in #6024

Nice work @diosmosis

@mattab mattab closed this as completed Sep 8, 2014
@halfdan halfdan changed the title User PSR-4 for autoloader Use PSR-4 for autoloader Sep 8, 2014
sabl0r pushed a commit to sabl0r/piwik that referenced this issue Sep 23, 2014
…annot be disabled, so no need to check for spl. Do not throw an exception in first autoloader if class does not exist, this should give the second autoloader a change to load the class.
sabl0r pushed a commit to sabl0r/piwik that referenced this issue Sep 23, 2014
… try to load it directly from there and do not look in other folders first. Unfortunately we still need the other logic for backwards compatibility
sabl0r pushed a commit to sabl0r/piwik that referenced this issue Sep 23, 2014
Why include file manually? because piwik.php does not use autoloader yet.
Maybe as part of refs matomo-org#4074 we could setup autoloader for piwik.php / tracking API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Projects
None yet
Development

No branches or pull requests

4 participants