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

Allow autoload.json in arbitrary directories, do not require root namespace in path/allow arbitrary path per root namespace. #5

Merged
merged 3 commits into from
May 1, 2017

Conversation

ghedipunk
Copy link
Contributor

Leaving this here for review, mostly.

My use case, that prompted me to make these changes in my fork

The directory structure that I'm working with here is PSR-0-like, but not compatible with PSR-0, because it doesn't use the root namespace in any folders. (Actually, it does use the root namespace in the project's root folder, but there are a couple of directories between the root folder and the folder where autoloaded classes reside.)

My directory structure:

  • /bigdumbogre -- project root. index.php lives here.
  • /bigdumbogre/Resources -- web resources... images, scripts, stylesheets, etc.
  • /bigdumbogre/Private -- protected by .htaccess. Also contains bootstrap.php which I will include lower with my example of how to use
  • /bigdumbogre/Private/Classes -- root of autoloaded classes.
  • /bigdumbogre/Private/Foundation/Configuration -- place where configuration files reside.

So, because of the project's special needs, I have edited the \Axel\Module\Library class to be a bit more configurable, and maintaining backwards compatibility by making the new constructor arguments optional.

Here's /bigdumbogre/Private/bootstrap.php, as an example of how I'm using it.

<?php

$globalBasePath = __DIR__;

require_once('Classes/External/Axel/axel.php');
$axel = new \Axel\Axel;

require_once('Classes/External/Dice/Dice.php');
$dice = new \Dice\Dice();

$axel->addModule(new \Axel\Module\PSR0('/Classes/External/Transphporm/src', '\\Transphporm'));
$axel->addModule(new \Axel\Module\Library($axel, '/Classes/Foundation/Configuration', '', $globalBasePath));

session_start();

/bigdumbogre/Private/Classes/Configuration/autoload.json for this project

{
    "include": ["../Autoloader.php"],
    "modules": {
        "\\BigDumbOgre\\Foundation\\Autoloader": []
    }
}

And /bigdumbogre/index.php that is able to get an arbitrary class

<?php

require_once('Private/bootstrap.php');

$router = $dice->create('\\BigDumbOgre\\Foundation\\Router');

@TRPB TRPB merged commit b7e0dbf into Level-2:master May 1, 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.

2 participants