Agent Library at Laravel. What's Wrong? - php

what's up?
I found this problem: I initiate a new project from 0, installing Laravel with composer:
composer create-project laravel/laravel --prefer-dist Blog
The following step was to add the Agent library https://github.com/jenssegers/agent.
composer require jenssegers/agent
This is the first library that I have ever used on Laravel and I'm not sure if I did it correctly. I added the line codes mentioned in the Agent's README.md at the config/app.php. After it, I went to public/index.php at my project and add the following lines to test it:
use Jenssegers\Agent\Facades\Agent;
$agent = new Agent();
Infortunally it didn't work and I had received the following error: Fatal error: Uncaught Error: Class "Jenssegers\Agent\Facades\Agent" not found in C:\xampp\htdocs\BlogBRU\public\index.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\BlogBRU\public\index.php on line 7. The line 7 correspond to $agent = new Agent();
I already tried to modify the use ... for:
use use Jenssegers\Agent\Facades;
use Jenssegers\Agent\Agent;
But it doesn't work.
I will appreciate it if you could help me. This is taking all my time!

Related

I used the TwitterOAuth library and got this error

Fatal error: Uncaught Error: Class 'Composer\CaBundle\CaBundle' not found in
C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php:572 Stack trace:
#0 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(620): Abraham\TwitterOAuth\TwitterOAuth->curlOptions()
#1 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(557): Abraham\TwitterOAuth\TwitterOAuth->request('https://api.twi...', 'GET', 'Authorization: ...', Array, false)
#2 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(490): Abraham\TwitterOAuth\TwitterOAuth->oAuthRequest('https://api.twi...', 'GET', Array, false)
#3 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(467): Abraham\TwitterOAuth\TwitterOAuth->makeRequests('https://api.twi...', 'GET', Array, false)
#4 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(232): Abraham\TwitterOAuth\TwitterOAuth->http('GET', 'h in C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php on line 572
I'm using it for the first time, so checked the TwitterOAuth.php file and line 572 then vscode says the CaBundle is undefined Type Undefined type 'Composer\CaBundle\CaBundle'. , I tried downloading the file over and over again but the same error.
I had the exact same problem following the instructions on here.
It turns out I wasn't including the right autoload. For those coming across the same problem:
Install composer locally on your directory as per these instructions.
Run php composer require abraham/twitteroauth.
Run php composer install.
Make sure to include the right path to the composer autoloader file, not the package autoloader, in your PHP code require "vendor/autoload.php";.
In each file that you will be using the package, don't forget to include the line use Abraham\TwitterOAuth\TwitterOAuth as TwitterOAuth;, so that you can use $foo = new TwitterOAuth();
I hope this helps those who might be new to composer like me.

How to use logger without composer and namespaces?

I am trying to install Mangopay https://github.com/Mangopay/mangopay2-php-sdk, but the recommended solution of installing it without composer doesn't work. I used this line:
require_once "mango/mangopay2-php-sdk-2.11.0/MangoPay/Autoloader.php";
$api = new MangoPay\MangoPayApi();
The file get's loaded, but I get the following error:
Fatal error: Uncaught Error: Class 'Psr\Log\NullLogger' not found in
/usr/local/apache2/htdocs/MangoPay/MangoPayApi.php:223 Stack trace:
#0 /usr/local/apache2/htdocs/pay.php(5): MangoPay\MangoPayApi-
>__construct() #1 {main} thrown in
/usr/local/apache2/htdocs/MangoPay/MangoPayApi.php on line 223
The issue is with the logger, which I manually downloaded and copied into the directory but it still doesn't work. I am only asking here because I am not getting any response from the developers.
Any help with manually installing the logger and getting the namespace to work with mangopay is welcome.

Error clearing cache / composer install - SensioFrameworkExtraBundle not found in kernel.php line 33

I face an issue since last Friday. Everything was working fine on my project and then friday when deploying:
after
$> php bin/console cache:clear
My Symfony project doesn't work anymore. I got this error:
Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SensioFrameworkExtraBundle" from namespace "Sensio\Bundle\FrameworkExtraBundle".
Did you forget a "use" statement for another namespace? in /Users/dam/Development/Alara/rayflex/git/rayborn/src/Kernel.php:33
Stack trace:
#0 /Users/dam/Development/Alara/rayflex/git/rayborn/vendor/symfony/http-kernel/Kernel.php(492): App\Kernel->registerBundles()
#1 /Users/dam/Development/Alara/rayflex/git/rayborn/vendor/symfony/http-kernel/Kernel.php(132): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 /Users/dam/Development/Alara/rayflex/git/rayborn/vendor/symfony/framework-bundle/Console/Application.php(64): Symfony\Component\HttpKernel\Kernel->boot()
#3 /Users/dam/Development/Alara/rayflex/git/rayborn/vendor/symfony/console/Application.php(148): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /Users/dam/ in /Users/dam/Development/Alara/rayflex/git/rayborn/src/Kernel.php on line 33
I tried to delete my vendor and reinstall same error
I tried a composer selfupdate && composer update
I Also tried to put the use in kernel.php...
Still nothing
I took an old tag of my project who was working fine Some month back. Same error..
I have Fix my problem on reinstalling SenSio Bundle
$ composer require sensio/framework-extra-bundle
I can't explain why, it was already installed and in the composer.json before ..
Thank for your help !

PHP Include - error in opening the stream

I am using an application that I downloaded using Composer.
The package has many classes that can be called and utilized.
However, when I run the below code, I am getting the following error.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
include 'vendor/autoload.php';
$clarifai = new \DarrynTen\Clarifai\Clarifai('CLARIFAI_API_KEY');
$input = new Input();
$input->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl();
$inputResult = $clarifai->getInputRepository()->add($input);
echo json_encode($inputResult);
?>
Error:
Warning:
include(/var/www/html/vendor/darrynten/clarifai-php/src/Entity):
failed to open stream: Not a directory in /var/www/html/ctest.php on
line 7
Warning: include(): Failed opening
'/var/www/html/vendor/darrynten/clarifai-php/src/Entity' for inclusion
(include_path='.:/usr/share/php') in /var/www/html/ctest.php on line 7
Fatal error: Uncaught Error: Class 'Input' not found in
/var/www/html/ctest.php:11 Stack trace: #0 {main} thrown in
/var/www/html/ctest.php on line 11
The class Input is located at /var/www/html/vendor/darrynten/clarifai-php/src/Entity which I am including using the include keyword in PHP right after the first include, of no avail.
include 'vendor/autoload.php';
include '/var/www/html/vendor/darrynten/clarifai-php/src/Entity';
Later, I used the following code
$concept = new \DarrynTen\Clarifai\Entity\Concept();
$concept->setId('boscoe')->setValue(true);
$input = new \DarrynTen\Clarifai\Entity\Input();
$input->setImage('https://samples.clarifai.com/puppy.jpeg')->isUrl()
->setConcepts([$concept]);
$inputResult = $clarifai->getInputRepository()->add($input);
on the last line, I am getting this error. (Guzzle related)
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client
error: POST https://api.clarifai.com/v2/inputs resulted in a 400
Bad Request response:
{"status":{"code":10020,"description":"Failure"},"inputs":[{"id":"e25be6bf0a4a4090a774694c016202cb","data":{"image":{"ur
(truncated...) in
/var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111
Stack trace: #0
/var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(65):
GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request),
Object(GuzzleHttp\Psr7\Response)) #1
Is this also name space related?
I have found a new PHP library that seems to be compatible with new apps in Clarifai created with the new api_key version: phpfanatic/clarifai
You can easily try to install it via composer:
composer require phpfanatic/clarifai
As dependencies you need to have:
PHP - 5.6, 7.0 - May work with ealier version, untested at this time.
cURL - *
Clarifai API Key - clarifai
PHPUnit - to run tests (optional).
Here you can find the full documentation with quick tutorial or step by step explanation.
Eddie from Clarifai here. Sorry you ran into an issue.
I see that you are using an API key. This community library currently only supports our old auth mechanism. All new "apps" in Clarifai are only created with an api_key as opposed to client_id and client_secret.
There's currently a PR open to add support for API keys.
We're hoping to have first class PHP support by the end of the year.

Google api php client

I'm trying to implement the google analytics API on localhost site using xampp on Mac OS.
but Im getting this error:
Fatal error: Uncaught Exception: This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation. in /Applications/XAMPP/xamppfiles/htdocs/ga-api/google-api-php-client/autoload.php:14 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/ga-api/index.php(4): require_once() #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/ga-api/google-api-php-client/autoload.php on line 14
Can anyone help me with this?
Given that you installed the library using Composer, it will be installed to vendor and will be available in the autoload.php that Composer generates.
I will require_once DIR. '/vendor/autoload.php'; in index.php (preferred) or where I need to instantiate the GoogleClient class.
Ensure that the path to client credentials are rightly referenced when you set auth config like so:
Google_Client->setAuthConfig($pathToCredentials)
Reference:
Setting auth credentials:
https://github.com/google/google-api-php-client#authentication-with-oauth
Autoloading classes:
https://getcomposer.org/doc/01-basic-usage.md#autoloading

Categories