How to load a file before composer and /vendor/autoload.php? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!Composer cannot load loader when PhpUnit is usedAutoloading classes in PHPUnit using Composer and autoload.phpLaravel Controller load files due to ClassLoader and incorrect composer filesHow to stop PHP Composer autoload require-dev library?Composer not creating all needed phpunit include pathsComposer incorrectly creating symlinks in vendor/bin“vendor” folder missing after running “Composer Install”Avoid to require vendor/autoload.php in every fileComposer dump-autoload loading custom files from composer not project rootHow to determine which libraries were loaded by Composer autoload.php
How to align text above triangle figure
How does debian/ubuntu knows a package has a updated version
Can a USB port passively 'listen only'?
How can I make names more distinctive without making them longer?
What to do with chalk when deepwater soloing?
How come Sam didn't become Lord of Horn Hill?
How do I keep my slimes from escaping their pens?
Extract all GPU name, model and GPU ram
The logistics of corpse disposal
What exactly is a "Meth" in Altered Carbon?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
Echoing a tail command produces unexpected output?
Sci-Fi book where patients in a coma ward all live in a subconscious world linked together
Is it true that "carbohydrates are of no use for the basal metabolic need"?
Storing hydrofluoric acid before the invention of plastics
What does the "x" in "x86" represent?
Short Story with Cinderella as a Voo-doo Witch
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
How to bypass password on Windows XP account?
String `!23` is replaced with `docker` in command line
51k Euros annually for a family of 4 in Berlin: Is it enough?
3 doors, three guards, one stone
porting install scripts : can rpm replace apt?
Is the Standard Deduction better than Itemized when both are the same amount?
How to load a file before composer and /vendor/autoload.php?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!Composer cannot load loader when PhpUnit is usedAutoloading classes in PHPUnit using Composer and autoload.phpLaravel Controller load files due to ClassLoader and incorrect composer filesHow to stop PHP Composer autoload require-dev library?Composer not creating all needed phpunit include pathsComposer incorrectly creating symlinks in vendor/bin“vendor” folder missing after running “Composer Install”Avoid to require vendor/autoload.php in every fileComposer dump-autoload loading custom files from composer not project rootHow to determine which libraries were loaded by Composer autoload.php
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I need to load Wordpress wp-load.php before the vendor/autoload.php and Laravel.
I can update in the public/index.php
but at PHPUnit level the vendor/bin/phpunit
loads vendor/autoload.php
before the wp-load.php
.
Is it possible to force composer to load a file before anything else ?
I tried
"autoload" :
"files" : ["public/wordpress/wp-load.php"]
But it doesn't seems to work as composer loads Laravel before wordpress...
The only ugly fix I found is to manually load wp-load in the vendor/autoload.php file but I need to do that at every composer update.
php wordpress laravel composer-php phpunit
add a comment |
I need to load Wordpress wp-load.php before the vendor/autoload.php and Laravel.
I can update in the public/index.php
but at PHPUnit level the vendor/bin/phpunit
loads vendor/autoload.php
before the wp-load.php
.
Is it possible to force composer to load a file before anything else ?
I tried
"autoload" :
"files" : ["public/wordpress/wp-load.php"]
But it doesn't seems to work as composer loads Laravel before wordpress...
The only ugly fix I found is to manually load wp-load in the vendor/autoload.php file but I need to do that at every composer update.
php wordpress laravel composer-php phpunit
add a comment |
I need to load Wordpress wp-load.php before the vendor/autoload.php and Laravel.
I can update in the public/index.php
but at PHPUnit level the vendor/bin/phpunit
loads vendor/autoload.php
before the wp-load.php
.
Is it possible to force composer to load a file before anything else ?
I tried
"autoload" :
"files" : ["public/wordpress/wp-load.php"]
But it doesn't seems to work as composer loads Laravel before wordpress...
The only ugly fix I found is to manually load wp-load in the vendor/autoload.php file but I need to do that at every composer update.
php wordpress laravel composer-php phpunit
I need to load Wordpress wp-load.php before the vendor/autoload.php and Laravel.
I can update in the public/index.php
but at PHPUnit level the vendor/bin/phpunit
loads vendor/autoload.php
before the wp-load.php
.
Is it possible to force composer to load a file before anything else ?
I tried
"autoload" :
"files" : ["public/wordpress/wp-load.php"]
But it doesn't seems to work as composer loads Laravel before wordpress...
The only ugly fix I found is to manually load wp-load in the vendor/autoload.php file but I need to do that at every composer update.
php wordpress laravel composer-php phpunit
php wordpress laravel composer-php phpunit
edited Mar 25 at 10:01
yivi
5,86172855
5,86172855
asked Mar 22 at 9:09
injetkiloinjetkilo
15019
15019
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Composer is not responsible for loading autoload.php
, but the whatever framework you are using is. PHPUnit, in your case.
PHPUnit only loads vendor/autoload.php
because that file is bootstrapped in phpunit.xml
configuration.
Much easier than doing any weird injection during composer run is simply to create your own testing bootstrap file.
If you check phpunit.xml
you'll find a bootstrap declaration which by default loads vendor/autoload.php
:
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
Create a new bootstrap file (e.g. testing_bootstrap.php
) and there include whatever files you need in addition to vendor/autoload.php
:
<?php
// testing_bootstrap.php
require 'path/to/wordpress/wp-load.php';
require 'vendor/autoload.php`;
And modify your phpunit.xml
file so it uses this file to bootstrap your tests.
bootstrap="testing_bootstrap.php"
This is cleaner and more maintainable, and accomplishes the right result. Which files are loaded/bootstrapped before execution is not composer's job.
To accomplish the same during a regular Laravel run, you'll need to modify Laravel's entry point file, you'll find there that autoload is required there:
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
If you want to load a different file before autoload, simply add the appropriate require
or include
statement before that point.
E.g.:
require 'path/to/wordpress/wp-load.php';
require __DIR__.'/../vendor/autoload.php';
Using the files
key of composer will simply not work. These files are loaded on vendor/composer/autoload_files.php
file, and this in turn is loaded on vendor/composer/autoload_real.php::getLoader
, after the rest of the autoloading process setup has been performed.
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
add a comment |
The fix I found for the moment is to apply a php script right after the composer autoload dump (in scripts post-autoload-dump) => it does the trick.
1
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296195%2fhow-to-load-a-file-before-composer-and-vendor-autoload-php%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Composer is not responsible for loading autoload.php
, but the whatever framework you are using is. PHPUnit, in your case.
PHPUnit only loads vendor/autoload.php
because that file is bootstrapped in phpunit.xml
configuration.
Much easier than doing any weird injection during composer run is simply to create your own testing bootstrap file.
If you check phpunit.xml
you'll find a bootstrap declaration which by default loads vendor/autoload.php
:
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
Create a new bootstrap file (e.g. testing_bootstrap.php
) and there include whatever files you need in addition to vendor/autoload.php
:
<?php
// testing_bootstrap.php
require 'path/to/wordpress/wp-load.php';
require 'vendor/autoload.php`;
And modify your phpunit.xml
file so it uses this file to bootstrap your tests.
bootstrap="testing_bootstrap.php"
This is cleaner and more maintainable, and accomplishes the right result. Which files are loaded/bootstrapped before execution is not composer's job.
To accomplish the same during a regular Laravel run, you'll need to modify Laravel's entry point file, you'll find there that autoload is required there:
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
If you want to load a different file before autoload, simply add the appropriate require
or include
statement before that point.
E.g.:
require 'path/to/wordpress/wp-load.php';
require __DIR__.'/../vendor/autoload.php';
Using the files
key of composer will simply not work. These files are loaded on vendor/composer/autoload_files.php
file, and this in turn is loaded on vendor/composer/autoload_real.php::getLoader
, after the rest of the autoloading process setup has been performed.
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
add a comment |
Composer is not responsible for loading autoload.php
, but the whatever framework you are using is. PHPUnit, in your case.
PHPUnit only loads vendor/autoload.php
because that file is bootstrapped in phpunit.xml
configuration.
Much easier than doing any weird injection during composer run is simply to create your own testing bootstrap file.
If you check phpunit.xml
you'll find a bootstrap declaration which by default loads vendor/autoload.php
:
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
Create a new bootstrap file (e.g. testing_bootstrap.php
) and there include whatever files you need in addition to vendor/autoload.php
:
<?php
// testing_bootstrap.php
require 'path/to/wordpress/wp-load.php';
require 'vendor/autoload.php`;
And modify your phpunit.xml
file so it uses this file to bootstrap your tests.
bootstrap="testing_bootstrap.php"
This is cleaner and more maintainable, and accomplishes the right result. Which files are loaded/bootstrapped before execution is not composer's job.
To accomplish the same during a regular Laravel run, you'll need to modify Laravel's entry point file, you'll find there that autoload is required there:
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
If you want to load a different file before autoload, simply add the appropriate require
or include
statement before that point.
E.g.:
require 'path/to/wordpress/wp-load.php';
require __DIR__.'/../vendor/autoload.php';
Using the files
key of composer will simply not work. These files are loaded on vendor/composer/autoload_files.php
file, and this in turn is loaded on vendor/composer/autoload_real.php::getLoader
, after the rest of the autoloading process setup has been performed.
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
add a comment |
Composer is not responsible for loading autoload.php
, but the whatever framework you are using is. PHPUnit, in your case.
PHPUnit only loads vendor/autoload.php
because that file is bootstrapped in phpunit.xml
configuration.
Much easier than doing any weird injection during composer run is simply to create your own testing bootstrap file.
If you check phpunit.xml
you'll find a bootstrap declaration which by default loads vendor/autoload.php
:
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
Create a new bootstrap file (e.g. testing_bootstrap.php
) and there include whatever files you need in addition to vendor/autoload.php
:
<?php
// testing_bootstrap.php
require 'path/to/wordpress/wp-load.php';
require 'vendor/autoload.php`;
And modify your phpunit.xml
file so it uses this file to bootstrap your tests.
bootstrap="testing_bootstrap.php"
This is cleaner and more maintainable, and accomplishes the right result. Which files are loaded/bootstrapped before execution is not composer's job.
To accomplish the same during a regular Laravel run, you'll need to modify Laravel's entry point file, you'll find there that autoload is required there:
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
If you want to load a different file before autoload, simply add the appropriate require
or include
statement before that point.
E.g.:
require 'path/to/wordpress/wp-load.php';
require __DIR__.'/../vendor/autoload.php';
Using the files
key of composer will simply not work. These files are loaded on vendor/composer/autoload_files.php
file, and this in turn is loaded on vendor/composer/autoload_real.php::getLoader
, after the rest of the autoloading process setup has been performed.
Composer is not responsible for loading autoload.php
, but the whatever framework you are using is. PHPUnit, in your case.
PHPUnit only loads vendor/autoload.php
because that file is bootstrapped in phpunit.xml
configuration.
Much easier than doing any weird injection during composer run is simply to create your own testing bootstrap file.
If you check phpunit.xml
you'll find a bootstrap declaration which by default loads vendor/autoload.php
:
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
Create a new bootstrap file (e.g. testing_bootstrap.php
) and there include whatever files you need in addition to vendor/autoload.php
:
<?php
// testing_bootstrap.php
require 'path/to/wordpress/wp-load.php';
require 'vendor/autoload.php`;
And modify your phpunit.xml
file so it uses this file to bootstrap your tests.
bootstrap="testing_bootstrap.php"
This is cleaner and more maintainable, and accomplishes the right result. Which files are loaded/bootstrapped before execution is not composer's job.
To accomplish the same during a regular Laravel run, you'll need to modify Laravel's entry point file, you'll find there that autoload is required there:
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
If you want to load a different file before autoload, simply add the appropriate require
or include
statement before that point.
E.g.:
require 'path/to/wordpress/wp-load.php';
require __DIR__.'/../vendor/autoload.php';
Using the files
key of composer will simply not work. These files are loaded on vendor/composer/autoload_files.php
file, and this in turn is loaded on vendor/composer/autoload_real.php::getLoader
, after the rest of the autoloading process setup has been performed.
edited Mar 25 at 8:39
answered Mar 22 at 10:43
yiviyivi
5,86172855
5,86172855
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
add a comment |
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Hi @yivi, the problem is that I use PHPUnit for unit testing and it has an other loader entry point than the Laravel... => For the moment I managed to hack that with a after-composer update script to inject wp-load.php before vendor/autoload.php
– injetkilo
Mar 25 at 8:10
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
Ok, updated my answer to account for the fact that you need this during tesitng, although the approach is the same. @injetkilo
– yivi
Mar 25 at 8:33
add a comment |
The fix I found for the moment is to apply a php script right after the composer autoload dump (in scripts post-autoload-dump) => it does the trick.
1
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
add a comment |
The fix I found for the moment is to apply a php script right after the composer autoload dump (in scripts post-autoload-dump) => it does the trick.
1
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
add a comment |
The fix I found for the moment is to apply a php script right after the composer autoload dump (in scripts post-autoload-dump) => it does the trick.
The fix I found for the moment is to apply a php script right after the composer autoload dump (in scripts post-autoload-dump) => it does the trick.
answered Mar 25 at 8:14
injetkiloinjetkilo
15019
15019
1
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
add a comment |
1
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
1
1
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
Can you explain that further such that others can learn from your answer?
– Nico Haase
Mar 25 at 8:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296195%2fhow-to-load-a-file-before-composer-and-vendor-autoload-php%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown