Phinx Class Not Found PHP - php

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';

Related

Can’t run PHPUnit with Composer on Travis-CI, class not found

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.

php artisan [BadMethodCallException]

First of all I have just begun to tinker with Laravel 5 and php artisan, so don't judge to harsh please ;)
To get rid of ./public/index.php in the website path I did the following:
moved all the files in root/page_local/ folder;
moved files from public folder to root/page/;
modified the root/page_local/index.php file accordingly.
So the laravel works as it should now, but php-artisan is not. Every command that I try to run returns the same error:
[BadMethodCallException]
Method patter does not exist.
But I remember creating a Controller before and it worked, I tried multiple functions (--version, list, create::controller).
Even when I run composer update it errors when it tries to run php artisan clear-compiled.
I still managed to update the composer by running composer update --no-scripts
Please help me out on this one because I couldn't find any information regarding this issue on Laravel website and google. If you will need me to provide any of my code, let me know what you need and I will do so.
Thanks in advance.
Search your code for patter string, my guess is that you have a typo somewhere and the method is called pattern so use that instead. There is no patter method anywhere in Laravel code.

Laravel 5.1: Cannot redeclare class Illuminate\\Contracts\\Support\\Arrayable

I am getting an error message in my Laravel 5 application:
PHP Fatal error: Cannot redeclare class Illuminate\\Contracts\\Support\\Arrayable in /var/www/.../bootstrap/cache/compiled.php on line 156
This error only occurs on my staging environment and not on my local website. I would love to post more info but I do not have it. Because I do not know where this error is caused.
If I remove the file (cache/compiled.php) everything seems to work fine. But after every deploy the same error occurs. On my localhost everything works fine as well.
My question: does anybody have a clue where to look because I am out of ideas.
Try this way.
At first remove the cache/compiled.php file
then run this command
php artisan clear-compiled
I had the same problem and found the following article, which was very helpful:
https://sentinelstand.com/article/laravel-5-optimization-commands
The only solution that was working for me was manually deleting bootstrap/cache/compiled.php. Switching around the order in which the autoloaders are called in bootstrap/autoload.php did not work for me because I had the same problem the other way round, ie. I had a class in compiled.php that was causing something from autoload.php to be autoloaded before autoload.php ran.
In my case, I am using a combination of PSR4 and manual class mappings in my composer.json file. I'm sure this is part of the problem. (Don't judge me: this app started in Laravel 3, so it's taking time to add namespacing throughout the code base :-).
One reason why things may work differently in different environments is because the artisan optimize command will only generate the bootstrap/cache/compiled.php file if you provide the --force option or if debugging mode is not enabled. So it is likely that you are not getting this file in development because debugging is enabled but are getting this file in staging and/or production because debugging is not enabled.
Ultimately, here's what I have landed on as a solution for production deployments:
artisan config:cache
artisan optimize
rm bootstrap/cache/compiled
Update symlink to point to new version.
This way you still get bootstrap/cache/services.json, which is helpful, whereas artisan clear-compiled removes that file. Also, there will be a very brief period of time where bootstrap/cache/compiled.php will exist, which is why it is important to run these commands before you update the symlink to point your web server at the new version.
It is also worth noting that the compiled.php file that is created by artisan optimize in Laravel 5.1 is no longer generated in Laravel 5.4 because, as Taylor has stated, PHP 7 is much more performant and so the benefit of bundling all the application classes into one file, which is meant to save on disk I/O, is negligble now. Taylor recommends enabling and properly configuring your OPcache instead - you will get far more performance benefits from that.
I experienced the same but eventually found the solution.
I have my own helpers.php files in laravel. Just like the framework ones, I added them as autoloads in my composer.json. A couple of those functions are macros for the Collection (\Illuminate\Support\Collection::macro(...)).
When that helpers.php file is autoloaded, the definition of those macros cause the autoloading of Illuminate\Support\Collection. This in turn uses Illuminate\Contracts\Support\Arrayable.
So basically all of these are already loaded by the time they are defined again in cache/compiled.php. Boom.
Long story short: For me the fix was simply to switch inclusion of the compiled file and the autoloader around.
bootstrap/autoload.php:
$compiledPath = __DIR__.'/cache/compiled.php';
if (file_exists($compiledPath)) {
require $compiledPath;
}
require __DIR__.'/../vendor/autoload.php';
This might not be a viable solution add include code in your compiled file runs right away and refers to helper functions, but I think the chances on that happening should be pretty minimal.
The problem is with the artisan optimize command. If you remove the compiled.php file and then do not run optimize, it should work.

Using pre existing library in Symfony

I am new to Symfony. I am trying to use a pre existing library that I have used for my Payment Gateway API, with Symfony (v2.3).
Before using Symfony I would have a composer.json file in the root directory and I would simply use PHP require 'vendor/Braintree.... However with Symfony I am having a really difficult time using the library for payment gateway API by importing it to my Controller.
Note: I am using an Entity in the same controller as follows, which has a similar directory structure and works great:
use Jets\JetsBundle\Entity\Company;
This is what I tried to use the payment gateway API:
use Jets\JetsBundle\Braintree\braintree\braintree_php\lib\Braintree;
and the Braintree.php contains:
namespace Widb\WidbBundle\Braintree\braintree\braintree_php\lib;
I keep getting the following error:
FatalErrorException: Error: Class 'Jets\JetsBundle\Controller\Braintree_Configuration' not found in C:\xampp\htdocs\www\symfony\src\Jets\JetsBundle\Controller\DefaultController.php line 239
And the DefaultController.php Line 239 contains:
Braintree_Configuration::environment('sandbox');
As a side note, I didn't do anything other than drag / drop the ready configured library directory from my old server to the Symfony directory on the new server. Am I missing some configuration script or cmd set up or something?
I appreciate any assistance in this regard. I will forever be grateful is someone can help me troubleshoot this.
Here is my DefaultController.php code:
http://pastebin.com/kwisEBzL
Many thanks in advance!
This Braintree project seems to be PSR-0, so you should be able to use it pretty easily.
Don't do this:
use Jets\JetsBundle\Braintree\braintree\braintree_php\lib\Braintree;
There is no such namespace.
Include the Braintree project using Composer (notice they have the PSR-0 autoloading config already: https://github.com/braintree/braintree_php/blob/master/composer.json).
EDIT: add this to your composer.json and don't forget to run composer update (or php composer.phar update)
Update 2: As pointed out in the comments, it is a good idea to use a stable tag/branch. That way, if there are breaking changes, you can make sure to fix them before updating. So always check the version of the library (2.23 may not be the latest version any more).
"require": {
...
"braintree/braintree_php": "~2.23"
},
The autoloader should pickup all of the classes if you use the global namespace (notice the leading slash):
\Braintree_Configuration::environment('sandbox');
Let me know if this works.
Side note, you should probably create a bundle that does the configuration for you in a centralized place.
You really missed out one of the first comments.. which was spot on and will most likely take away alot of headaches.
Follow the instructions given at https://github.com/cometcult/CometCultBraintreeBundle, this is a bundle that provides "Braintree". A bundle in this case actually is a "module" you can hook in, and configure by configuration files.
Relevant commands that are missing for handling composer:
http://getcomposer.org/doc/03-cli.md#install
http://getcomposer.org/doc/03-cli.md#require
As soon as you have finished it up you should take a look at the bottom two parts, besides conifgurating everything.
$factory = $this->get('comet_cult_braintree.factory');
$customerService = $factory->get('customer');
If you need more help let me know
I'm don't uderstand what you actually try to do in your DefaultController.php, but I have some assumptions.
UPD:
FIRST and SECOND point was deleted.
THIRD:
When you trying to make use Jets\JetsBundle\Braintree\braintree\braintree_php\lib\Braintree; you have load only class Braintree from file Braintree.php. Not whole file with another data like require_once instructions.
FOURTH:
/vendor directory of Symfony2 projects usually contains third-part libs. So you can put your lib here.
Hope some of this points helps you.
P.S. Sorry for poor English.

Symfony: getting Class not found error

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

Categories