Fatal error: Uncaught Error: using graphaware for PHP - php

I am using graphaware to connect to a neo4j graph database. I keep getting an error saying Fatal error: Uncaught Error even though I'm using the library in composer.json. Here is the code for the autoload.php:
<?php
/*
* This file is part of the GraphAware Neo4j PHP OGM package.
*
* (c) GraphAware Ltd <info#graphaware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
error_reporting(E_ALL | E_STRICT);
$basedir = __DIR__.'/../';
//$basedir = __DIR__.'C:/xampp/htdocs/';
$proxyDir = $basedir.DIRECTORY_SEPARATOR.'_var';
putenv("basedir=$basedir");
putenv("proxydir=$proxyDir");
$loader = require_once __DIR__.'/../vendor/autoload.php';
Here us the code for the configuration php file named configNeo4j.php:
<?php
// Connection to the database
require_once __DIR__.'/vendor/autoload.php';
use GraphAware\Neo4j\Client\Client;
use GraphAware\Neo4j\Client\ClientBuilder;
$client = new Client ();
$client = ClientBuilder::create ()
->addConnection ( 'default', 'http://neo4j:neo4jj#127.0.0.1:7474' )
-> addConnection('bolt', 'bolt://neo4j:neo4jj#127.0.0.1:7687')
->build ();
$query = "MATCH (X) RETURN X";
$result = $client->run ( $query );
?>
Here is an image of the file structure:
Now when I run the webpage on a web browser which I am doing using xampps apache server I get this error message:
Fatal error: Uncaught Error: Class 'GraphAware\Neo4j\Client\Client' not found in C:\xampp\htdocs\configNeo4j.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\configNeo4j.php on line 11
This might also help:
This is strange because I am using the library in eclipse and I have also installed the composer in the php.exe file in xampp. If anyone has any solution to this problem it would be great if you could let me know how this problem can be fixed.Thanks in advance.

try this:
require_once __DIR__.'/vendor/autoload.php';
your code is:
require_once __DIR__.'C:/xampp/htdocs/vendor/autoload.php';
you dont need to specify the full path of the files ('c:/xampp/...')
__DIR__ will give you the current directory of the file you wrote your codes
oh and anyway, did you edit the autoload.php? if you use third party classes or plugins, you should not have to edit their core files.

Use better relative path to load autoload file. With this you are also making the app independent from the OS and your filesystem. Just like this:
require_once __DIR__.'/vendor/autoload.php';

Related

Imagick successfull installation but error occurs: Uncaught Error: Class 'imagick' not found

I've read a dozen of articles, but none provides a proper solution. I have an SSH access to my server and I installed the imagick through composer as follows:
composer require calcinai/php-imagick
The library successfully installed on both my local server (open server) and on the remote server. Then I do:
$imagick = new imagick();
$imagick->setResolution(300, 300);
Everything works fine on my local machine, but on my web-hosting it returns Uncaught Error: Class 'imagick' not found. Do I need to do the require for all the files or something? Because I tried to add the following in the beginning:
require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/calcinai/php-imagick/src/Imagick.php';
now it throws me this: Uncaught Exception: Imagick::setResolution not implemented
Please, advice.
require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/calcinai/php-imagick/src/Imagick.php';
Above line is not required. As mentioned in the comments, Composer is strict with casing of class names and tweaking with cases of class names is discouraged as composer has proper strict autoloading of them in its classmaps.
$imagick = new Imagick();
Above line is the correct way of initialization. As far as the exception is concerned, their own internal implementation throws it as something yet to be implemented. Below is their method body they have,
Method definition:
/**
* #param float $x_resolution
* #param float $y_resolution
* #return bool
*/
public function setResolution($x_resolution, $y_resolution)
{
throw new Exception(sprintf('%s::%s not implemented', __CLASS__, __FUNCTION__));
}
As far as remote server is concerned, everything is performing fairly well there too. If you really need some implementation for setResolution, some other library might help.

php error at runtime Interface 'Psr\Container\ContainerInterface' not found

I recently uploaded a new dependency to a PHP app I am working on and I am now continually getting the following error in Postman
Fatal error: Interface 'Psr\Container\ContainerInterface' not found in
/var/www/html/api/vendor/container-interop/container-interop/src/Interop/Container/ContainerInterface.php on line
13
I have updated composer as well as a multitude of other things and still cannot seem to pinpoint the issue. (Also not sure if it means the error is with the index.php file or the container.php file)
Here is the code from the container.interface.php file
<?php
/**
* #license http://www.opensource.org/licenses/mit-license.php MIT
(see the LICENSE file)
*/
namespace Interop\Container;
use Psr\Container\ContainerInterface as PsrContainerInterface;
/**
* Describes the interface of a container that exposes methods to
read its entries.
*/
interface ContainerInterface extends PsrContainerInterface
{
}
And here is the initial code from my index.php file
<?php
ini_set('display_errors', 1);
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
// Includes ;
require_once( 'config/database.php' );
require_once( 'controller/base.php' );
//$app = new Slim\App();
$app = new Slim\App(['settings' => ['displayErrorDetails' => true]]);
$twilio = new Twilio\Rest\Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
$serviceAccount = ServiceAccount::fromJsonFile('my_file.json');
$firebase = (new Factory)->withServiceAccount($serviceAccount)-
>withDatabaseUri('my_firebase_website')->create();
Solution: I was utilizing filezilla to transfer updated dependencies from my vendor folder on my local machine & in the process I was downloaded the wrong autoload.php file

authorization of app using pinterest api php and create board

i am using dirkgroenen library php for authorization of my app and create board
which i downloaded from here
https://github.com/dirkgroenen/Pinterest-API-PHP
evry time i run this code it gives me uncaught error about the line:8
Fatal error: Uncaught Error: Class 'Dotenv\Dotenv' not found in C:\xampp\htdocs\pin\vendor\demo\boot.php:8
here is the code for boot.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require ("../autoload.php");
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
$pinterest = new
DirkGroenen\Pinterest\Pinterest(getenv("4915445646307112766"),
getenv("1ae8683b277958bd9739cedb0f0b1434eee42176dd3d44cbf44981f9acaadd94"));
if (isset($_GET["code"]))
{
$token = $pinterest->auth->getOAuthToken($_GET["code"]);
$pinterest->auth->setOAuthToken($token->access_token);
setcookie("access_token", $token->access_token);
}
else if (isset($_GET["access_token"]))
{
$pinterest->auth->setOAuthToken($_GET["access_token"]);
}
else if (isset($_COOKIE["access_token"]))
{
$pinterest->auth->setOAuthToken($_COOKIE["access_token"]);
}
else
{
assert(false);
}
?>
can anyone please help me to fix it.. i have spent more than 48 hours to resolve this issue..
any help will be greatly appreciated
Obviously, you don't have Dotenv class anywhere where PHP expects it to be found.
Options:
You don't have it at all, then download it from here: vlucas/phpdotenv. Composer should have downloaded it, BUT only if you used composer to install DirkGroenen.
You have it but it is outside autoload path - check autoload path, make sure that Dotenv is located in appropriate vendor-folder.
You have it but it doesn't support autoload (sic!) - check with latest version OR include it directly with include/require
It requires phpunit/phpunit to be installed aswell.

Fzaninotto Faker PHP Fatal Error

I keep getting this error when I am trying to test Faker PHP from github on my server:
Fatal error: Class 'Faker\Provider\en_US\Address' not found in /home/andrew/public_html/JeffWork/src/Faker/Provider/en_US/Address.php on line 6
Link: http://aswanson.net/JeffWork/test/test.php
All of the package files have been installed and uploaded properly, and the code on line 5 & 6 looks like:
class Address extends \Faker\Provider\en_US\Address
{
Please make sure whether the file exists in the folder where your referring for "/home/andrew/public_html/JeffWork/src/Faker/Provider/en_US/Address.php".
Please take a new update with composer with the following
composer require fzaninotto/faker
Now with the updated version 1.6, you will be able to solve this kind of issue make sure to use autoload.php in file where your using.
The following shows the snippet of usage
<?php
require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();
$person = new Faker\Provider\en_US\Person($faker);
$address = new Faker\Provider\en_US\Address($faker);
foreach(range(1,10) as $i){
echo $address->address(),'<br/>';
}
Cheers!

How to setup a php client Thrift 0.9.1 ...

I'm trying to setup a php client for RPC with a HBase Thrift server but I'm getting some errors at the begining ... I've compilated the HBase.thrift file (with the 0.9.1 compiler) and I've put the 2 generated files like bellow (/ is the root of my project, I'm using apache server on ArchOS) :
/include/Hbase.php
/include/Types.php
I've included the lib folder of thrift0.9.1/lib/php/lib (composed of Thrift and sub folders) under / and so I've the following file system :
/include/HBase.php
/Types.php
/Thrift/Base
/ClassLoader
/Exception
/ext
...
To be able to use my service (HBase.php) I've to load files so my code is the following :
<?php
$GLOBALS['THRIFT_ROOT'] = PHYSICAL_PATH;
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TMessageType.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Factory/TStringFuncFactory.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TType.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
//hbase thrift
require_once ('Hbase.php');
require_once ('Types.php');
?>
When I'm charging the different files, I'm getting an error for this line --require_once ('Types.php');-- and the error is : Fatal error: Class 'Thrift\Exception\TException' not found in /var/www/html/POCThrift2/include/Types.php on line 1266
I understand it like : When I tried to include Types.php, the Thrift\Exception\TException namespace was not use (despite the use Thrift\Exception\TException; in the beginig of the Types file) but I don't know why I'm getting his error ... can you help me ? Does anyone has encountered this problem before ? Thx in advance, I'm stuuuck right now ...

Categories