I install the PhpExcel library in my project with composer :
"require": {
"phpoffice/phpexcel": "dev-master"
}
I regarded in my composer folder : composer/autoload_namespaces.php :
return array(
'PHPExcel' => array($vendorDir . '/phpoffice/phpexcel/Classes'),
.....
)
Now in my controller I do :
$objPHPExcel = \PHPExcel_IOFactory::load($inputFile);
But I have the error :
"Class 'PHPExcel_IOFactory' not found". I don't understand where is my mistake..Can you help me please ? Thx in advance
When you create composer.json file you should run
composer install
And next in your code you should include generated autoloader:
require __DIR__ . '/vendor/autoload.php';
And it's all. Should works. You don't modify nothing in vendor directory.
Related
Composer in autoload_static.php use class that I don't need them in every app request.
'd5fa61a7f6cbc1df09dd4df84549a2dc' => __DIR__ . '/..' . '/rospdf/pdf-php/src/Cpdf.php',
'2d15964294879de66053d54f6bde65d7' => __DIR__ . '/..' . '/rospdf/pdf-php/src/Cezpdf.php',
How to remove them from this autoload file? I can delete/comment them manually but every Composer update this file is re-generated.
I try to add in my main composer.json:
"exclude-from-classmap": ["vendor/rospdf/pdf-php/src/"]
& run composer dump-autoload bo those class are still in there.
You can trick the autoloader of composer and let him think those are already loaded:
<?php
// Setting global variable:
$GLOBALS["__composer_autoload_files"] = [
"d5fa61a7f6cbc1df09dd4df84549a2dc" => true,
"2d15964294879de66053d54f6bde65d7" => true,
];
require "vendor/autoload.php";
But this needs to happen before the vendor/autoload.php is included.
I'm trying to import a composer project into a plugin for wordpress. Is there a better way to do this than requiring every single asset? I do not plan to use composer to manage anything moving forward with this project, but I did use composer to install all requirements into the project folder (the plugin folder). Essentially, I'm trying to figure out how to convert a composer project to a wordpress plugin.
What you could do, load the autoloader from vendor/autoloader.php inside your functions.php. Then you could do something like this:
$loader = require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
$loader->addPsr4('NAMESPACE\\', __DIR__ . '/app');
You are now autoloading the app folder.
How I use a composer packages into Wordpress plugin
I have a plugin's folder wp-content/plugins/stack-overflow/
Inside the folder I have the composer.json like next:
{
"name": "kumaxim/webhose-io-integration",
"license": "proprietary",
"authors": [
{
"name": "Your_name_here",
"email": "your_email_if#your_want.com"
}
],
"require": {
"php": "^5.4"
*** you can add other packages here ***
}
}
You have a plugin's file like next:
<?php
/**
* Plugin Name: The name of the plugin
*/
defined( 'WPINC' ) || die( 'Access restricted' );
function your_prefix_plugin_run() {
require_once __DIR__ . '/vendor/autoload.php';
}
your_prefix_plugin_run();
Pay attention, I strong recommend to call composer dependencies in plugin's bootstrap function. I have a problems in the past when I required it outside function.
What is next?
Add your dependencies and run composer install or composer update
I'm having trouble understanding with doesn't Composer autoloads the packages I required.
My current composer.json file has the following:
{
"require": {
"atlas/orm": "#dev"
},
"require-dev": {
"atlas/cli": "#dev"
}
}
It was supposed to generate a Namespace in the /vendor/composer/autoload_namespaces.php file. But it doesn't. The file only has the following:
// autoload_namespaces.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Psr\\Log\\' => array($vendorDir . '/psr/log'),
);
Of course, when I try to use the "require DIR . '/vendor/autoload.php';" to autoload the package and then use its classes, it does not work.
Any idea on how can I solve this?
For requiring in all of the installed dependencies, you have to require 'autoload.php'. For autoloading(PSR-4), in the composer.json file, you have to give a name under which everything will be namespaced and the folder name from which files will be autoloaded.
"Namespace_name\\":"folder_name"
Note: The backslash after the namespace_name needs to be escaped, hence the extra backslash.
Then run composer dump-autoload -o
Trying to get Stripe library up and running. Get failed opening required 'vendor/autoload.php' error.
autoload.php is there in /vendor
ran composer update, then composer install , didn't help.
config.php
<?php
require_once('vendor/autoload.php');
$stripe = array(
"secret_key" => "XXXXXXXXXXXXXXXXXXXXXX",
"publishable_key" => "XXXXXXXXXXXXXXXXXXXXXX"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
autoload.php
<?php
// autoload.php #generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit18eff69591fc6597a849a05ec4932261::getLoader();
It looks like a problem with your relative path. Because this "script is in /app/modules/stripe" and the vendor folder "is /vendor", then you can use the constant __DIR__ to reference the included script's location, and then up 3 relative directories.
require_once(__DIR__.'/../../../vendor/autoload.php');
Try to change the require_once to this:
require_once __DIR__ . '/vendor/autoload.php';
try this.Work for me.
composer update --no-scripts
CakeResque - Resque not found in ...app/Plugin/CakeResque/Lib/CakeResque.php on line 82
I've followed the instructions here: http://cakeresque.kamisama.me/install#requirements to setup CakeResque with my CakePHP project but the Resque class isn't loading. I installed CakeResque using Composer and I'm assuming I'm missing something (possible autoloader) but with no luck.
Any help is appreciated. Thanks.
Got help at github. I had missed adding composer autoloader in my app/Config/core.php per the instructions.
make sure the vendor directory is mentioned in the app/composer.json
{
"require": {
"kamisama/cake-resque": "^4.1"
},
"config": {
"vendor-dir": "Vendor"
}
}
in the app/Config/core.php require the autoload
require_once dirname(__DIR__) . '/Vendor/autoload.php';