using PayWithAmazon with symfony 2 - installed with Composer - php

I installed this package via composer:
composer require amzn/login-and-pay-with-amazon-sdk-php
composer update
I added this to my Controller file:
use PayWithAmazon\Client;
... and would like to use the Client class, provided with this package.
$amazonClient = new PayWithAmazon\Client($this->amazonCredentials);
The error message of the framework:
ClassNotFoundException in CartController.php line 185: Attempted to load
class "Client" from namespace "**Microsite\FrontBundle\Controller\PayWithAmazon**".
Did you forget a "use" statement for e.g.
"Symfony\Bundle\FrameworkBundle\Client",
"Symfony\Component\BrowserKit\Client",
"Symfony\Component\HttpKernel\Client",
"Guzzle\Service\Client" or "Guzzle\Http\Client"?
`
Can anyone tells me what i do wrong?
How do I change the namespace for "Client" class from Microsite\FrontBundle\Controller\PayWithAmazon to the right one?
(I did not have problems with other packages...)
Cheers
Greg

I will suggest you do follow
use PayWithAmazon\Client as AmazonClient;
...
$amazonClient = new AmazonClient($this->amazonCredentials);

Related

Trying to use a composer package in laravel

Im using Laravel 5.8.
Im trying to use the following package
https://packagist.org/packages/s1lentium/iptools
To install it i have run:
composer require s1lentium/iptools
Confirmed the require line is in the composer.json
"s1lentium/iptools": "^1.1"
and that the package is in "vendor/s1lentium/iptools/"
How can i reference it in the code (controller or even in a view)??
When I try to use the IP class Laravel cannot find it.
I've researched a lot and but without success. Hope anyone can lead me to the correct step.
Thanks!
Run composer dump-autoload
You must call the IP class with \IPTools\IP, or use it:
use IPTools\IP;
Hope it helps.

Symfony console component, class not found

I'm using the console component without Symfony standard edition and I'm working on my application.php file. When I run it it says:
Fatal error: Class 'GenerateTableCommand' not found in D:\ConnectCommand\vendor\application.php on line 10
My code:
<?php
require __DIR__.'\autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new GenerateTableCommand());
$application->run();
?>
My repository can be found here if needed: https://github.com/guuse/ConnectCommand
Any help is greatly appreciated.
First of all there's no \GenerateTableCommand, as stated in the error message.
This class is under AppBundle\Command namespace, so it's full name is AppBundle\Command\GenerateTableCommand.
You should add use statement at the beggining:
use AppBundle\Command\GenerateTableCommand;
Anyway, you'll probably encounter further issues with loading this class, since you do not really have any autoloaders for your custom code, so PHP won't be able to load this class.
Also mixing 3rd party code with your own (in vendor directory) is not a good idea.

Symfony Assetic Dump get class not Found Exception

When I tries to assetic dump php app/console assetic:dump --env=prod, I got Error Like
[Symfony\Component\Debug\Exception\ClassNotFoundException]
Attempted to load class "Twig_Filter_Method" from the global namespace.
Did you forget a "use" statement?
In Browser Run my Project It is display error like :-
ClassNotFoundException in BootstrapIconExtension.php line 51:
Attempted to load class "Twig_Filter_Method" from the global namespace.
Did you forget a "use" statement?
Anyone have any Suggestion please let me know ..
Change
'apply_filter' => new \Twig_Filter_Method($this, 'applyFilter'),
to this
'apply_filter' => new \Twig_SimpleFilter('apply_filter', array($this, 'apply_filter')),
I had the same issue; for me it was related with the liip imagine bundle version i was using. I have changed that version and it worked smoothly

Cannot redeclare class error in Laravel but works fine in native php

I am using Alchemy API for filter out some data. Everything works fine in the native code. But when i used it in my Laravel Controller it throws Cannot redeclare class. My controller,alchemyapi.php and example.php are in the same directory. Here is how i include alchemyapi.php in native code
<?php
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI("MY API KEY"); ?>
But when i include it in the controller it throws my the error. is there something i am missing ?
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI("MY API KEY");
The native code(example.php) works well without any issue. But in laravel controller it throws a error saying Cannot redeclare class AlchemyAPI
in alchemyapi.php line 20
Instead of using require_once use namespace in your alchemyapi.php and then use use for same namespace in your MyController
alchemyapi.php
<?php
namespace App\Http\Controller;
class AlchemyApi {
//your code
}
MyController.php
<?php
namespace App\Http\Controller;
use App\Http\Controller\AlchemyApi;
class MyController {
$alchemy = new AlchemyApi("Your_api_key");
}
OK, so what I think is happening is that alchemyapi.php is somehow already being included by the composer autoloader.
Try this.
Create the directory lib in the root of your project.
Move alchemiapi.php into lib.
Under the "autoload" section in your composer.json add the following code. Make sure the JSON is valid:
"files": [
"lib/alchemyapi.php",
],
Run composer dump-autoload. If it errors, your composer.json is invalid or you haven't put the file in the correct place.
Delete require_once 'alchemyapi.php'; from your controller.
When dealing with composer, this is how you deal with classes in the global namespace. After running composer it scan those directories in app for PSR-4 classes.
I can't be sure but I think that composer is looking for it and you are also manually requiring it. That would explain why PHP thinks you are redeclaring the class.

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in dbunit\PHPUnit\Extensions\Database\TestCase.php on line 24

I want to write tests for MySQL Database. When I try to extend the database extension, it gives me the above error in title:
class FixtureTestCase extends PHPUnit_Extensions_Database_TestCase
Note: I have installed PHPUnit globally and I can access it through phpunit in cmd. I have latest PHPUnit 4.5.1.
I also installed Dbunit globally through composer:
composer global require phpunit/dbunit
Any help will be much appreciated. I've used PHP 5.4.
For referring to classes that are located within the global namespace, you can simply prefix them with a backward ( \ ) slash.
Try with this:
class FixtureTestCase extends \PHPUnit_Extensions_Database_TestCase
With the leading backward ( \ ) slash, PHP knows that we are referring to the PHPUnit_Extensions_Database_TestCase class in the global namespace, and located that one.
More info here
Hope this help.
It just might be the version of DBUnit. For example I'm using PHPUnit 4.8 and it works with DBUnit 1.4.
I had the above error when I was using composer with "phpunit/dbunit": ">=1.2" and I ended up with DBUnit 2.0.
Test your DB how? Through an API you created or direct accesses to DB? i would recommend you to write an API to access your DB and then write the tests to the API.
for exemple if you want to insert a user you call your web-server address (localhost:3000) or something you have and then call /users through POST to insert and make the routes to that.
I would suggest using LARAVEL for that.

Categories