Closed timburrows closed 7 years ago
yes @RifuI you need to do composer dumpautoload
for it make use of composer autoloading to find the class.
Okay thanks @harikt, perhaps this could be appended to the readme somewhere.
@harkit this project looks like just what I need to get Atom to do what I am after. Thanks so much for building it. I get the same error as above, with the same packages in place. Where do I run "composer dumpautoload". I have tried it in bash (on a Mac machine), but get command not found. Guess I am missing some vital piece of knowledge here. Thanks for your help.
@rossdotparker thank you for the message.
You can see the dependencies listed on : https://github.com/harikt/php-hyperclick#inspired-by
One of them is composer , a tool to manage dependencies. You can get it from getcomposer.org . Remember you need to configure composer.json to detect the autoloading functionality.
Alternatively you can keep a file vendor/autoload.php
which can find the classes as an autoloader works.
Thank you.
@harkit, thanks for this helpful reply. I have installed Composer as an Atom package, and also using brew (on Mac), but can't find composer.json anywhere on my system, and neither can I find any hints on Google. Any pointers? I feel lost! Thanks : )
You need to create a composer.json file on the root of the project.
See : https://getcomposer.org/doc/01-basic-usage.md#autoloading
You need something like
{
"autoload": {
"psr-4": {"Acme\\": "src/"}
}
}
But again depends on where and how the autoloading works. You may want to look more on composer documentation.
Appreciate the help, and totally understand that Composer is not your project, and that you have gone out of your way to help. I have had a play around, with little success, but have now run out of time to look at this right now. Will have to come back to it in the future. Thanks again for the help.
harikt, the relevant branch of the project (Gibbon) can be seen here:
https://github.com/GibbonEdu/core/tree/v12.0.00
The autoloader is src/autoloader.php
Any advice on how to proceed would be most appreciated.
Thanks : )
@rossdotparker cool. So basically you can create a vendor/autoload.php
file on the root of the project ( where atom is opened ) . I assume the require for vendor/autoload.php
will return an object of the autoloader.
return new Autoloader();
And add a method findFile
which is an alias for https://github.com/GibbonEdu/core/blob/202b8d3088c09018e36a182db111f4191f6ada3c/src/Autoloader.php#L127 . I believe that will make things work. I am not sure regarding other files and how autoloading works internally. But this is without composer :) .
If you love composer support. Add a composer.json
on root here https://github.com/GibbonEdu/core/tree/v12.0.00 .
Your composer.json
can define how to load the php classes. Eg :
{
"autoload": {
"psr-4": {
"Gibbon\\": "src/Gibbon",
"Library\\": "src/Library",
}
}
}
and use composer dumpautoload
which will create the autoloader in vendor/autoload.php
. I have noticed you have added lots of dependencies in your project without composer. It will be great help for you if you are using composer.
Hope that helps.
Thank you.
Hari, thanks for your time, patience and support. I am pretty close to getting it working, with vendor/autoload.php in place now, setting up an instance of the Autoloader object, and creating the alias:
<?php require_once '/Applications/MAMP/htdocs/github_gibbonEdu/core/src/Autoloader.php'; $loader = new Autoloader(); use function loadMappedFile as findFile; ?>
But I am now getting the following error:
Any ideas what would be causing this?
Looking forward I will check out composer as a way to manage dependencies.
Thanks again,
Ross,
PS, once I get Atom set up and working as I would like, I am going to write a post on it...and will include your instructions and a note of thanks for your help : )
The error you got is for you did not returned the $loader object.
require_once '/Applications/MAMP/htdocs/github_gibbonEdu/core/src/Autoloader.php';
$loader = new Autoloader();
use function loadMappedFile as findFile;
return $loader;
Question : Does the use function loadMappedFile as findFile;
will also make the method object an alias ? I think no. You probably need to implement it on the Autoloader
class.
Thank you
Harikt, thanks again for your time on this. I added the return $loader; instruction, but now getting the error below:
I guess this is to do with your last comment above, which I don't really understand? Can you try and explain this to me in more detail?
Thanks again.
use function loadMappedFile as findFile;
is to make an alias for a function. You need a method.
So create findFile
method inside the Autoloader
class.
Hope that helps!
If this is still an issue, please re-open. I hope this is resolved.
Thank you for the reports.
Hello, I don't understand the part about implementing the functionality of autoloader. What does this YourAutoloader class have to do? Is there some general template that could be used for? Really does every project need a different file?
// vendor/autoload.php $autoloader = new YourAutoloader(); // Make sure there is findFile method which can return the path to the file when class name is passed return $autoloader;
I'm using Windows 7 and XAMPP, and want to use this in quite simple PHP projects. I don't want to install additional dependencies.
I can not get this package to work. Here is the full error: "Error : Please make sure the composer vendor/autoload.php file exists in root of project and is readable."
I have:
Is there something missing from the instructions that may be obvious to experienced users? Do I need to run composer install in my project root?