Namespacing issue? or something else? - php

I am trying to implement the Graphaware\neo4j client in php
neo4j-php-client
I ran composer to download the files to the working directory .www
and tried initiating the client using
require_once(BASEPATH.'vendor/autoload.php');
use GraphAware\Neo4j\Client\ClientBuilder;
$client = ClientBuilder::create()->addConnection('default', 'http://neo4j:myPassword#localhost:7474')->build();
I get this error.
<b>Fatal error</b>: Class 'GraphAware\Neo4j\Client\ClientBuilder' not found in <b>*path_to_my_www_dir\index.php*</b> on line <b>36</b><br />
Why am i seeing this?

I'm the maintainer of GraphAware Neo4j Client.
My bet is that you have been disturbed when reading the README of the repository.
The current master branch contains the code for 4.0#alpha, so if you ran in the command line composer require graphaware/neo4j-php-client chances are high that composer installed the last stable version in the 3.X series and thus the required class doesn't exist there.
I would suggest you try to install the alpha7 version of the client by running :
composer require graphaware/neo4j-php-client:^4.0#alpha
Let me know if you have other issues

We ran into the issue with neo4j-php-client not supporting PHP 5.5 as well. While the "correct" solution is to upgrade to a newer version of PHP, it isn't exactly the most convenient--especially if you just want to start evaluating this library. The only reason that PHP >= 5.6 is required is for Neo4j's bolt protocol, so as long as you stick to using the http protocol instead everything will work fine. In order to get composer to play nice though, you have to make a few changes to neo4j-php-client's composer.json:
Change "php": ">= 5.6" to "php": ">= 5.5"
Replace "graphaware/neo4j-bolt": "^1.5" with "graphaware/neo4j-common": "^3.0"
We ended up forking the library on Github and then updated our composer.json to use our modified version of neo4j-php-client. The relevant parts are:
{
...
"require": {
...
"graphaware/neo4j-php-client": "dev-OptionalBoltSupport"
},
...
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/wnielson/neo4j-php-client"
}
]
}
After doing this you can run composer update and neo4j-php-client should install fine.

You simply need to require vendor/autoload.php as said in documentation.
So require_once 'vendor/autoload.php'; will solve your problem.
The problem is that, even if you are using use ..., your php file didn't know anything about the php class file you're trying to create.
You need to include that file using include or require function.

Related

Heroku Class 'NumberFormatter' not found

Deploying my Laravel 7 app in Heroku I get this error, it appears only in Heroku, not on my local box (localhost)
Class 'NumberFormatter' not found (View: ...)
Server Details:
Heroku
PHP 7.4.12
Laravel Framework 7.30.4
The NumberFormatter classDocs requires the PHP Internationalization extension (intl)Docs, and this extension is not available built-in on Heroku Heroku Built-in ExtensionsHeroku Docs.
Instead Heroku gives you permission to use optional extensionsHeroku Docs.
To make use of them you can either use the composer command to require it ("ext-intl"):
composer require ext-intl
Or you can manually add this to composer.json in the require sectionComposer Docs:
{
"require": {
"ext-intl": "*"
}
}
Commit the file and push the changes to Heroku. The error should be gone until you find the next missing class.
This is another example, why it is a good idea if you have a Composer based PHP project, to document the extensions in use as well in the composer.json file.
When the day comes, you have them documented in the Composer JSON already.
And systems like Heroku can benefit from it, too!

Using conditional OR in requirements in a composer.json?

We have a problem with composer. Our library requires a either ... or ... library.
So basically it requires it like this:
"php-64bit": ">=5.4.0"
OR
"php": ">=5.4.0" AND "ext-example": "^1.0.2"
So basically it requires a specific PHP version.
Additionally it requires a 64bit version of PHP OR a specific library to work.
Is this possible to do with composer? If so how? If not can we solve it in another way?
I'd think you should not go overboard with your dependency definition.
Both platform situations require PHP 5.4 or later. I'd add that as the only hard dependency.
Composer has a "suggest" feature. Your extension could be suggested with a descriptive text to indicate that only the 32bit platform would need it.
Your code would already have to deal with the situation, so you probably have checks implemented to see whether you are using 64bits (and omit using the extension) or not. That code might emit an error when being used on 32bit without the extension.
"require": {
"php": ">=5.4"
},
"suggest": {
"ext-example":"Required to use this package on 32bit PHP"
}
This avoids having the user add a script to his composer.json that does nothing more than helping him understand why it fails when first trying to install your package. He'd have to read the documentation anyway.
I assume, you intend to make your library available through Packagist.
Composer can run scripts triggered by events, but only those defined in the root composer.json.
Include a script to detect the PHP environment OS agnostically (64 or 32bit) in your library. Since you require ">=5.4.0" in both cases, your script can conditionally require your additional library "ext-example": "^1.0.2" when in a 32bit environment.
Example Cmd.php in your library:
namespace Some\Name\Space;
class Cmd
{
public static function check32() {
// detect environment here... then:
if ($is32) {
$cmd = 'php composer.phar require vendor/32bit-library:dev-master';
exec($cmd, $output, $return_var);
}
}
}
This will run composer.phar in the app's root directory.
Referring entry in root composer.json:
"scripts": {
"post-install-cmd": [
"Some\\Name\\Space\\Cmd::check32"
]
}
The caveat here is that exec() must be available on your user's machine and that the user has to include your library as well as your post-install-cmd in their composer.json.

Why do CodeIgniter projects sometimes include composer.phar package?

I'm new to Composer and in my current project I would like to install a bunch of PHP libraries like:
Doctrine
Security Library (Which i have no idea but looking for in CodeIgniter)
Bootstrap layout libraries and other when necessary
For that matter , I would like to use Composer based library management in my application,
and i get confused that if i have to include composer.phar on my project directory or not.
since i have it on my environment path and I can run Composer form command line .
How can integrate the above libraries into my codeigniter application then..
Appreciate your toughs!
The composer.phar file is an executable and it should not be committed. What it actually does is that it looks in your composer.json file and there you can declare some more dependencies (libraries for example) and their version:
{
"require": {
"doctrine/orm": "*"
}
}
The version in this case is declared with "*" so Composer will get the latest version. This is very useful if there are more people on the project, to make sure all of them have the same version of dependencies installed (so the composer.json file must be committed).
If you run "composer.phar update" on the other hand, this will get the latest version of all dependencies, no matter the version placed in composer.json and updates the lock file with the new versions.

PHP failed to load vendor folder : How to install composer on my server?

Asked Here but no proper response.
Hi, When I tried to use paypal sdk, and when I tried to submit the details, it is showing this error.
Fatal error: require(): Failed opening required '/home/wwwrapid/public_html/test/samples/vendor/paypal/paypal-merchant-sdk-php-4f570f5/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwrapid/public_html/test/merchant-sdk-php-master/samples/PPAutoloader.php on line 451
When I go through the folders path, I dont find any folder named 'vendor'.
I have been searching the solution for this for two days. Some sites say it's a composer error and installing composer solves the issue. and this is the code for that.
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
My problem is I am not able to understand what they mean? I don't even know where to add this code? I mean in which file? How can that composer be installed on my site?
If you're on Windows the easiest thing to do is download the Windows installer and use it.
In order for Composer to install, though, you're going to need PHP installed. The easiest way to do this is to just configure a local server setup using WAMP or something similar. You'll need do that prior to installing Composer.
Once all of that is done you'll be able to utilize Composer to manage PHP packages within your projects. It's really pretty awesome stuff, but it can be a little confusing if you've never worked with it before.
Basically, once it's installed, you can just create a composer.json file at your project root. This file is basically a config file that tells Composer what PHP packages you want to use (among other things.)
For PayPal's SDK you could setup a composer.json file with nothing but this in it:
"require": {
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"paypal/rest-api-sdk-php" : "0.5.*"
}
Then, from the command line, you can browse to the project root (where the composer.json file is) and run "composer update".
This would look at the composer.json file and download any/all packages that are required based on that line. In this case it would be pulling in the PayPal REST API SDK, and then all of the samples that PayPal provides would work for you.
Composer is what creates that /vendor directory and sets up an autoloader for you. Hope that helps.

Class 'Pheanstalk_Pheanstalk' not found in Laravel 4 with Beanstalk

I'm trying to get beanstalk up and running and I'm getting the exception when trying to run Queue::push():
Class 'Pheanstalk_Pheanstalk' not found
I've run composer require pda/pheanstalk, and even regenerated my auto-load file an extra time.
It's happening in ./vendor/laravel/framework/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php
Any ideas?
In composer.json, replace the pda/pheanstalk requirement line by
"pda/pheanstalk": "2.0.*"
Run
composer update
Warning: will also update Laravel.
Source: http://laravel.io/forum/07-17-2014-class-pheanstalk-pheanstalk-not-found
Disregard. Found the answer at https://github.com/laravel/framework/issues/746. Apparently the newest version has been reorganized or something.
You may be using pheanstalk 3 which didn't work for me with Laravel 4. Use this command to switch to an older version:
composer require pda/pheanstalk "~2.1"
If you are using a version such as 2.1.1, and if you are using a namespace use Pheanstalk\Pheanstalk, then that might be the issue (it was for me). Version 2.1.1 isn't compatible with using namespaces, hence you would delete the use ... line and then, when initiating an instance of class type Pheanstalk, you do it as follows:
$pheanstalkObject = new Pheanstalk_Pheanstalk('127.0.0.1');

Categories