I have installed the package from composer I am trying to include file from vendor folder into controller but it does not including.
Here is what I am trying
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use src\Coinpayments;
use src\keys;
class CoinController extends Controller
{
public function DoIt(){
$cps = new CoinPaymentsAPI();
}
}
And this is in composer.json
"require": {
"php": "^7.1.3",
"coinpaymentsnet/coinpayments-php": "^1.0",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0"
},
In the result I am getting following error which is
Class 'App\Http\Controllers\CoinPaymentsAPI' not found
After a composer install it's advised to run
composer dump-autoload
In the instructions from the package they tell you to include the following file:
require('/your_installation_path_to/src/CoinpaymentsAPI.php');
You aren't including it correctly, pretty sure your IDE is giving you errors.
It's probably, I found this information in the composer.json file included in the package:
use Coinpaymentsnet\CoinpaymentsAPI
Related
i am using Symfony Panther with Laravel framework. I got an error while using this
unknown error: cannot create temp dir for user data dir
{"exception":"[object]
(Facebook\WebDriver\Exception\UnknownErrorException(code: 0):
I have installed XAMPP for Windows 7.4.2.
PHP: 7.4.2, Apache: 2.4.41
composer.json
"require": {
"php": "^7.1.3",
"fabpot/goutte": "^3.2",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "~6.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0",
"symfony/css-selector": "^4.4",
"symfony/http-client": "^4.4",
"symfony/panther": "^0.7.0"
}
Laravel Controller Class
namespace App\Http\Controllers;
include (base_path() .'/vendor/autoload.php');
use Illuminate\Http\Request;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\HttpClient\HttpClient;
class PageController extends Controller
{
public function myFunction(Request $request)
{
$client = \Symfony\Component\Panther\Client::createChromeClient();
$client->request('GET', 'https://api-platform.com'); // Yes, this website is 100% written in JavaScript
$client->clickLink('Support');
// Wait for an element to be rendered
$crawler = $client->waitFor('.support');
echo $crawler->filter('.support')->text();
}
}
[2020-02-27 16:12:21] local.ERROR: unknown error: cannot create temp
dir for user data dir {"exception":"[object]
(Facebook\WebDriver\Exception\UnknownErrorException(code: 0):
unknown error: cannot create temp dir for user data dir at
D:\WWW\PHP\myproject\vendor\php-webdriver\webdriver\lib\Exception\WebDriverException.php:139)
Check that your disk is not running low on space.
Does XAMPP have the correct permissions? It may be required to run with elevated permissions.
Check the %TEMP% and %TMP% environment variables and ensure they exist. (To do this, run echo %TEMP% and echo %TMP% on the Windows' command line)
Related: "cannot create temp dir for user data dir" error when not running as admin
I updated my composer.json file to include dbunit:
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^1"
},
I ran composer and it updated my installation to include dbunit (I already had PHPUnit).
But when I tried to add the TestCaseTrait namespace to my test the IDE claims it can't find that namespace.
use PHPUnit\Framework\TestCase; <----- this works great
use PHPUnit\DbUnit\TestCaseTrait; <----- error that namespace doesn't exist
Am I missing a step?
I was able to reproduce your problem with this in my composer.json:
"phpunit/dbunit": "^1"
By increasing the version to ^4, the namespace is no longer unfindable. Keep this in mind, if you didn't already know about the composer json schema:
The caret will update you to the most recent major version (the first number).
^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.
Here's the working composer.json I used:
{
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^4"
}
}
I'll go straight to the point, I only changed the controller namespace Musique\Controller to STM\Controller
namespace STM\Controller;
use Silex\Application;
class HomeController{
public function indexAction(Application $app){
return $app['twig']->render("index.html.twig");
}
also changed my composer.json file
{
"name": "jasonazoulay/SoTrustMe",
"description": "Tiers de confiance",
"authors": [
{
"name": "Jason Azoulay",
}
],
"require": {
"silex/silex": "^2.0",
"doctrine/dbal": "~2.5",
"twig/twig": "^1.33",
"symfony/asset": "^3.2",
"symfony/twig-bridge": "^3.2",
"symfony/form": "~2.8|3.0.*",
"symfony/translation": "~2.8|3.0.*",
"symfony/config": "~2.8|3.0.*"
},
"autoload": {
"psr-4": {"SoTrustMe\\": "src"}
}
}
and of course the route also
$app->get('/',"STM\Controller\HomeController::indexAction")->bind('home');
and now i get this error
InvalidArgumentException in ControllerResolver.php line 187:
Class "STM\Controller\HomeController" does not exist.
though it was working just fine before I change the namespace !
please help me
Since you are loading your classes with composer and you introduced a new directory in your project you are going to need to re-run: composer dump-autoload
this will regenerate the list of all classes that need to be included in the project and updates the Composer cache. For more detail regarding this issue you could have a look at this question.
"require": {
"infusionsoft/php-sdk": "^1.2",
"laravel/lumen-framework": "5.1.*",
"vlucas/phpdotenv": "~1.0",
"barryvdh/laravel-debugbar": "^2.2",
"goaop/framework": "^2.0",
"php-http/httplug": "^1.1",
"infusionsoft/old-php-isdk": "*"
},
I'm trying to use the "infusionsoft/old-php-isdk" which is in the packagist composer repository but it's not specific to Laravel. I'm using an order controller and it's code that I picked up from another developer so he references the current (and working) "infusionsoft/php-sdk" as the following
"use infusionsoft\infusionsoft;"
What namespace do I call it if it has no namespace from the package?
Here's the original link to the composer package.
https://packagist.org/packages/infusionsoft/old-php-isdk
Am I missing something? Do I need to assign it a namespace? What and where would I put it?
Apparently version 4 of PHPUnit now uses Composer to autoload, which means that the usual means of including PHPUnit in Behat version 2:
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
Doesn't work. I was hoping that /vendor/autoload.php in my Behat folder would include it but it seems like it's not the case.
I guess what I'm asking is what is the general way in which I can include into my code a library that was added by Composer?
You can successfully use default /vendor/autoload.php to both load your libraries and your code. It's hard to say exactly what might be wrong without further details, but make sure your composer dependencies are updated and then simply require the composer's authoload.php. The composer.json should look similar to:
{
"require": {
"behat/behat": "dev-master",
"behat/mink": "dev-master",
"behat/mink-extension": "dev-master",
"behat/mink-browserkit-driver": "dev-master",
"behat/mink-goutte-driver": "dev-master",
"behat/mink-selenium2-driver": "dev-master",
"phpunit/dbunit": "*",
"phpunit/phpunit": "*",
},
"autoload": {
"psr-0": {
"": "./src/"
}
}
}
You can include it in your context hook (this is Behat 3 example though):
/**
* #beforeSuite
*/
public static function setUpSuite()
{
require_once './vendor/autoload.php';
}