2 ms·
You won't even notice it. Everything you already have will continue to work fine. All you have to do is include the autoloader somewhere in your code path. An
by tylerjwilk00 8y ago
You won't even notice it.
Everything you already have will continue to work fine. All you have to do is include the autoloader somewhere in your code path.
An example assuming you already installed composer on the machine into your /bin or similar directory.
# add a new dependency:
composer require guzzlehttp/guzzle
# this dependency will now be in the vendor directory
ls ./vendor
# update your apps entry point (ie: frontcontroller.php):
// require composer's autoloader
require ('vendor/autoload.php');
# autoload will now find any dependencies you add via composer
// create guzzle client
$client = new \GuzzleHttp\Client();
# another tip, if you already have a bunch of class files some where (ie: myapp/src/classes , myapp/src/models ) You can include class paths via composer.json
"autoload": {
"classmap": ["classes/", "models/", "MyClass.php"]
}
You can now remove any hard-coded include or require statements.
There is a lot more things you can do with it but this is the most basic example.
- krapp 8y ago>There is a lot more things you can do with it but this is the most basic example. One useful feature is custom commands[0]. [0]https://getcomposer.org/doc/articles/scripts.md#writing-custom-commands https://getcomposer.org/doc/articles/scripts.md#writing-cust... Also, regarding autoloading, I find that once you get used to the structure of PSR-4, adding files to a PSR-4 namespace[1] and just having autoloading work is incredibly helpful. The only pain point is dealing with namespaces everywhere. [1]https://getcomposer.org/doc/04-schema.md#psr-4 https://getcomposer.org/doc/04-schema.md#psr-4