I need some help with a problem. I'm trying to execute a simple build with tests on Travis-CI, but its error, saying that it could not found Class:
Fatal error: Class 'com\bitshammer\collection\utils\CollectionUtils' not found in /home/travis/build/BitsHammer/CollectionUtils/test/CollectionUtilsTest.php on line 20
Just for your knowledge, it’s my first project using Composer! What I am doing wrong? Do you guys have any idea? Thanks!
Travis-CI page
Project page on GitHub
I believe your namespaces are wrong for the autoloading.
In composer.json, your autoloading maps the namespace com\bitshammer\ to src/.
You currently have the namespace at com\bitshammer\collection\utils which means your file path for this class would instead needs to be src/collection/utils/CollectionUtils.php instead of src/CollectionUtils.php.
Alternatively you could change the namespace for this class to be com\bitshammer instead of com\bitshammer\collection\utils.
Related
After manually deleting a Trait file that was no longer needed by the compiler I see that the compiler is looking in the Controller folder instead of the Traits folder.
I have tried composer dump-autoload, php artisan clear-compiled, php artisan /clear-cache and php artisan optimize. How can I fix this problem?
After manually deleting a Trait file that was no longer needed by the compiler I see that the compiler is looking in the Controller folder instead of the Traits folder.
I guess this means you moved the Trait file into another directory?
Since composer usually is configured to use the PSR-4 autoloading this would require you to also change the namespace of the move Trait.
I.e. trying to load App\Http\Controllers\CommonTrait the autoloader is looking for the Trait in the src/Http/Controllers/CommonTrait.php file. If you moved that file to say src/Http/Controllers/Traits/CommonTrait.php you have to change the namespace of the Trait to
namespace App\Http\Controllers\Traits;
and import it for usage as
use App\Http\Controllers\Traits\CommonTrait;
The answer to my problem is to make sure that nothing in your code is using the trait. I found a controller that was still using the trait. Big newbie mistake. Maybe it's time for this old sea-dog to ...
So I'm trying to set up Phinx a database migrations tool in Slim however, I'm having a little trouble getting the migration to work properly it keeps giving me this error Fatal error: Class 'App\Database\Migrations\Migration' not found in C:\Users\Hassan\Desktop\www\sites\hassanaljadooa\database\migrations\20170804115407_created_user_table.php on line 7 when ever I try to migrate.
I know it has to do with the Migrations class but I spell checked it multiple times I couldn't find any typos in class, and I'm quite frankly lost this error just shouldn't exist from my point of view.
To make life easy for anyone trying to help, here's the link to the bitbucket repo hosting my entire source code for this project https://hassanaljadooa#bitbucket.org/hassanaljadooa/hassanaljadooa.git just clone this repo and start looking.
The main files to look at are phinx.php in the root of the directory, app/database/migration.php, and the database/migrations folder.
side note:: im using psr-4 to load classes.
Thanks in advance.
Try to add the composer autoloader to phinx.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
I searched for hours to solve my problem, but now I just don't know what to check anymore..
I created a new project for composer: https://github.com/Gcob/esvit-ng-table-for-symfony
Everything is fine until it comes to the appKernel.php, I declarate my new freshly downloaded from composer bundle like this: new Gcob\NgTableBundle\GcobNgTableBundle(), but I got an error message:
ClassNotFoundException in AppKernel.php line 23:
Attempted to load class "GcobNgTableBundle" from namespace "Gcob\NgTableBundle".
Did you forget a "use" statement for another namespace?
I don't know exacly how the appKernel finds its bundles, but I know that the namespace is important and the filename too, so my file GcobNgTableBundle.php has the namespace namespace Gcob\NgTableBundle; and the class declaration is class GcobNgTableBundle extends Bundle as it should be.
Is there any place I should tell the kernel that the file GcobNgTableBundle.php exists for vendor bundles? If some one got any idea, please tell me, but don't forget that I tried a lot of stuff ( first time asking question o_O )
You need to change your composer and add an autoload part.
Without it, namespaces can fail. Check documentation for details.
It must be similar to this:
"autoload": {
"psr-4": { "Symfony\\Bundle\\EsvitNgTableBundle\\": "" }
},
Check this one for example.
After a lot of wasted time, I understood :P The answer of mim was in the good direction! I learned here how composer namespaces works. The appKernel in Symfony only loads the composer file "vendor/composer/autoload_namespaces.php" to load FAKE namespaces xD.
So I'm trying to create a custom console command in Laravel 5.1 which does some helpful function for my project. I can do this fine when putting the console command in a file located at the base commands folder but not when I just to add a subdirectory.
'App\Console\Commands\SomeCustomCommandThatWorks',
'App\Console\Commands\MySubNameSpace\CustomCommandThatFails',
So how do I add my command like MySubNameSpace\Command?
Namespace doesn't appear to have any effect on this. The namespace of the command could be App\Console\MySubNameSpace\MyCommand or App\Console\MyCommand both fail if the file is located at 'App\Console\Commands\MySubNameSpace\MyCommand'. The file also fails if located at 'App\Console\Commands\MyCommand' with namespace App\Console\MySubNameSpace\MyCommand.
Right now I get this error.
Class App\Console\Commands\DeletePhantomServers does not exist
I have tried running composer dumpautoload but to no success.
Any help would be appreciated.
According to autoloading standards, none of the combinations you have above will work. The namespace needs to be set according to the directory. So if you have the command in this folder
Console\Commands\MySubNameSpace\MyCommand
your namespace has to be
App\Console\Commands\MySubNameSpace\MyCommand
I must be tired. After reading Michael's answer I looked at the namespaces and realised I was just simply writing them wrong.
I was putting
namespace App\Console\Commands\MySubNameSpace\MyCommand;
class MyCommand ...
Where I needed to put
namespace App\Console\Commands\MySubNameSpace;
class MyCommand ...
Thanks for the help people :)
I am trying to learn Symfony 2. I'm trying to follow the example in the Symfony book (Page 17). I have downloaded and unpacked Symfony in my working directory.
The absolute path to the file I'm trying to use is in: symfony\vendor\symfony\symfony\src\Symfony\Component\HttpFoundation\Request.php
However following the books example closely, I just put:
use Symfony\Component\HttpFoundation\Request
Either way, both these approaches did not work for me.
Using the books approach I'm getting the following error:
Fatal error: Class 'Symfony\Component\HttpFoundation\Request' not found in C:/...
Using my approach with the longer path, I'm still getting this error, when I use include to navigate to the long path, the file is found but I'm getting some other error (just wanted to verify I'm able to get to the file, which I am).
I appreciate any advice in overcoming this problem. Many thanks in advance!
in PHP use statement requires Fully Qualified Class Name, not directory. So use Symfony\Component\HttpFoundation\Request is just fine.
If you decided to try these "examples" you will have to require autoload.php file first. It is located in your vendors directory.
So if you make file named "myfile" in symfony web folder it should start like this:
<?php
require '../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
Run - > composer update
Run the Path -> ./vendor/bin/upgrade-carbon
Then Will fixed this issue in laravel