-
Notifications
You must be signed in to change notification settings - Fork 9
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
A little request #10
Comments
Hi, Yes, it is, but it depends of how you structured your code.
Now, if you are using different namespaces for each one of these directories you'd have to instantiate Does it help? |
Hello Pablo, thanks for your reply. First and foremost I deeply apologize but English is not my primary language and I expressed myself very badly. What I wanted to know and if the Something similar:
namespace My_Project\Framework;
class Test1 {}
namespace Admin\Includes;
class My_Package {} Sorry again for the bad expression Adriano |
No problem, In that case you could use the Composer autoload function for the project you don't want the
And for the other project you do want |
Before anything else I am allergic to two things in life: fish and the composer ecosystem. :) Having said that, it was also my idea to use the devil's autoload. However looking at your code the following change came to my mind.
Obviously I'm not sure that this code will actually work because it's just a sketch of an idea. public function __construct( $args = null ) {
if ( $args && count( $args ) ) {
$this->add_namespaces( $args );
}
} If the public function add_namespace( $args ) {
$defaults = array(
'directory' => $this->get_calling_directory(),
'namespace_prefix' => $this->get_calling_file_namespace(),
'lowercase' => array( 'file' ), // 'file' | folders
'underscore_to_hyphen' => array( 'file' ), // 'file' | folders
'prepend_class' => true,
'classes_dir' => array( '.', 'vendor' ),
'debug' => false,
);
$parsed_args = array_merge( $defaults, $args );
$this->set_args( $parsed_args );
} Now a splash of magic
$autoloader = new WP_Namespace_Autoloader();
$autoloader->add_namespace(
$args = [
'directory' => __DIR__,
'namespace_prefix' => 'My_Project',
'classes_dir' => 'src',
];
);
$autoloader->add_namespace(
$args = [
'directory' => __DIR__,
'namespace_prefix' => 'My_Other_Project',
'classes_dir' => 'my_other_dir',
];
); This is my idea. What do you think about it? Do you think it can work? |
:D Hum, this library was made for WordPress coding standards. Probably there is another library that could do what you want, but apart from that, maybe it could work :) But can I ask why you are allergic to Composer ecosystem? |
I did some experiments this morning and the modification I was telling you about works. I'm not against composer as an autoloader but only as a dependency manager. |
Hi, first of all thank you for this class.
I need to know if you can use it to manage multiple directories.
In practice a coding similar to the following:
includes/my_classes
andadmin/includes/my__other_classes
andpublic/includes/my_other_classes
and so on
Thanks in advance
Adriano
The text was updated successfully, but these errors were encountered: