Issue
You may find this question a bit odd, but I read couple of articles and it is still unclear for me how to make it work. I have a server with composer installed I made it to request DomCrawler via request command, it installed it successfully, I have vendor\symfony directory and file autoload.php, which I include to my script. It returns object of Composer\Autoload\ClassLoader which seems to have classes
[prefixLengthsPsr4:Composer\Autoload\ClassLoader:private] => Array
(
[S] => Array
(
[Symfony\Polyfill\Mbstring\] => 26
[Symfony\Polyfill\Ctype\] => 23
[Symfony\Component\DomCrawler\] => 29
)
)
How to use them now? In manuals they are usually registered to that moment and people can simply make variable such as $var = new Symfony\Component\DomCrawler();
in my case it seems some additional command it required to include that classes to code, and it is unclear for me which one I have to use? Or how to include these classes to my code and to work with them...
$loader = require '../../composer/vendor/autoload.php';
$classes = get_declared_classes();
if( class_exists( 'Composer\Autoload\ClassLoader' ) ){
$methods = get_class_methods( 'Composer\Autoload\ClassLoader' );
}
echo '<pre>';
//print_r($loader);
print_r( $classes );
//print_r( $methods );
echo '</pre>';
die();
I don't see and crawler/symphony classes. Only composer classes are added to classes which php brings.
Solution
Classes will be loaded when you request for them - that is the point of autoloading. If you have have project with thousands of classes and particular request uses only 100 of them, only these 100 classes will be loaded. It allows you to save server resources by skipping loading all of unused classes.
Try to use class before calling get_declared_classes()
- it should be there.
$loader = require '../../composer/vendor/autoload.php';
$crawler = new \Symfony\Component\DomCrawler\Crawler();
$classes = get_declared_classes();
echo '<pre>';
print_r( $classes );
echo '</pre>';
die();
Answered By - rob006
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.