I am following the directions given here to install neoclient on Windows 7 -
https://github.com/neoxygen/neo4j-neoclient
But I get the error -
<b>Parse error</b>: syntax error, unexpected 'use' (T_USE) in <b>C:\xampp\htdocs\send.php</b> on line <b>7</b><br />
when I try to run the sample php code.
My code is -
<?php
try
{
require_once 'vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default','http','localhost',7474)
->build();
$version = $client->getNeo4jVersion();
}
catch(Exception $e)
{
echo $e->getMessage();
}
echo $version;
?>
composer.json -
{
"name": "neoxygen/neoclient",
"type": "library",
"description": "NeoClient is the most advanced Http Client for Neo4j",
"keywords": [
"graph",
"neo4j",
"cluster",
"client",
"high-availibility"
],
"homepage": "http://neoxygen.io",
"license": "MIT",
"authors": [
{
"name": "Christophe Willemsen",
"email": "chris#neoxygen.io"
}
],
"require": {
"php": ">= 5.5",
"guzzlehttp/guzzle": "^6.0",
"monolog/monolog": "~1.1",
"symfony/yaml": "^2.7",
"symfony/config": "^2.7",
"symfony/dependency-injection": "^2.7",
"symfony/event-dispatcher": "^2.7",
"graphaware/neo4j-response-formatter": "^1.0"
},
"require-dev": {
"phpspec/phpspec": "~2.0",
"phpunit/phpunit": "4.*",
"bossa/phpspec2-expect": "*",
"behat/behat": "~3.0"
},
"autoload": {
"psr-4": {
"Neoxygen\\NeoClient\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Neoxygen\\NeoClient\\Tests\\": "tests/Neoxygen/NeoClient/Tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.1-dev"
}
}
}
I'm the maintainer of NeoClient.
I don't think I have ever seen this piece of code somewhere, please point to a link.
Especially, require and use statements should be in the beginning of the file, after the open tag.
Secondly, you don't need to instantiate the client in a try/catch block.
Here is the correct piece of code :
<?php
require_once 'vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default','http','localhost',7474)
->build();
try
{
$version = $client->getNeo4jVersion();
}
catch(Exception $e)
{
echo $e->getMessage();
}
echo $version;
?>
Related
I am trying to integrate firebase/php-jwt into my Laravel project.
I added the following code from the firebase/php-jwt to test it out.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use GuzzleHttp;
use Phpfastcache\CacheManager;
use Firebase\JWT\CachedKeySet;
use Firebase\JWT\JWT;
class MyUserController extends Controller
{
public function searchUser(Request $request)
{
$jwksUri = 'omitted';
// Create an HTTP client (can be any PSR-7 compatible HTTP client)
$httpClient = new Client();
// Create an HTTP request factory (can be any PSR-17 compatible HTTP request factory)
$httpFactory = new GuzzleHttp\Psr7\HttpFactory();
// Create a cache item pool (can be any PSR-6 compatible cache item pool)
$cacheItemPool = CacheManager::getInstance('files');
$keySet = new CachedKeySet(
$jwksUri,
$httpClient,
$httpFactory,
$cacheItemPool,
null, // $expiresAfter int seconds to set the JWKS to expire
true // $rateLimit true to enable rate limit of 10 RPS on lookup of invalid keys
);
$decoded = JWT::decode($jwt, $keySet);
$token = $request->bearerToken();
dd($token);
}
}
But I am getting the following error when I run the code
Class 'Firebase\JWT\CachedKeySet' not found
I found a similar question here and I have tried adding the require statement for vendor/autoload.php and it didn't work for me.
I am using PHP version 7.4.29.
Here is my composer.json
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.3|^8.0",
"firebase/php-jwt": "^6.1",
"flipbox/lumen-generator": "^8.2",
"guzzlehttp/guzzle": "^7.0",
"itsgoingd/clockwork": "^5.1",
"laravel/lumen-framework": "^8.3.1",
"phpfastcache/phpfastcache": "^8.1",
"symfony/psr-http-message-bridge": "^2.1"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"symfony/psr-http-message-bridge": "0.2"
}
So how do I fix this?
I'm working on symfony 2.8 project and I'm new in it. Now I try to upgrade it to the newest version. I found the rector package for update the symfony (rector-prefixed exactly, for older version). I've install it and try to run like it is in documentation: https://github.com/rectorphp/rector, and got this error in the console:
'vendor' is not recognized as an internal or external command,
operable program or batch file.
I've don't found any information about errors like this so I think it could be a problem connect with console error. When I try to write any command for example:
php app/console list
I've got this exception back:
#!/usr/bin/env php
[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.
I don't know exactly where to looking for a problem. I will add my console file code and composer.json, maybe someone have same problem as me.
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
set_time_limit(0);
require __DIR__.'/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": {
"Tixi\\": "src/Tixi/"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"autoload-dev": {
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
},
"require": {
"php": "~7.4",
"ext-json": "*",
"apy/breadcrumbtrail-bundle": "1.3.*",
"composer/ca-bundle": "~1.2.7",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/doctrine-migrations-bundle": "1.3.*",
"doctrine/orm": "^2.4.8",
"egulias/email-validator": "~1.2",
"friendsofsymfony/oauth-server-bundle": "1.5.*",
"friendsofsymfony/rest-bundle": "1.7.*",
"incenteev/composer-parameter-handler": "~2.0",
"jms/serializer-bundle": "1.5.*",
"knplabs/knp-snappy-bundle": "1.5.*",
"mediaburst/clockworksms": "2.0.*",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.0.2",
"symfony/swiftmailer-bundle": "~2.3,>=2.3.10",
"symfony/symfony": "2.8.*",
"twig/extensions": "1.5.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"rector/rector-prefixed": "^0.9.31",
"sensio/generator-bundle": "~3.0",
"symfony/phpunit-bridge": "~2.7"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"bin-dir": "bin",
"platform": {
"php": "7.4"
},
"sort-packages": true,
"discard-changes": true
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.8-dev"
}
}
}
I solved already the problem. First the problem with Rector was with the command. I don't know exactly why but normal command don't work with my project. In Rector documentation there is:
vendor/bin/rector
command but in my project there works only:
php bin/rector
So this problem was solved. Next I have an issue with any other command form command line. There was a Logic exception. But I handle with this after upgrade the Symfony from 2.8 to 3.x. So I think there was conflict between the oldest version of Symfony and the php 7.4 version.
I'm new with namespaces and I'm making tests but when I run app.php I get the next error:
Fatal error: Class 'ProtocoloWT\models\status' not found in
C:\xampp\htdocs\wt.uptkd\protocoloWt\app.php
.
app.php
use Neomerx\JsonApi\Encoder\Encoder;
use Neomerx\JsonApi\Encoder\EncoderOptions;
use ProtocoloWT\models\status;
require '../vendor/autoload.php';
$status = status::instance(http_response_code(204));
$encoder = Encoder::instance([
'\status' => '\statusEsquema',
], new EncoderOptions(JSON_PRETTY_PRINT, 'http://example.com/api/v1'));
echo $encoder->encodeData($status);
status.php
namespace ProtocoloWT\models;
class status
{
public static function instance ($status)
{
$estado = new status();
$estado->status = $status;
return $estado;
}
}
composer.json
{
"name": "neomerx/json-api",
"description": "Framework agnostic JSON API (jsonapi.org) implementation",
"keywords": [
"jsonapi.org",
"json-api",
"jsonapi",
"neomerx",
"json",
"api"
],
"homepage": "https://github.com/neomerx/json-api",
"support": {
"issues": "https://github.com/neomerx/json-api/issues"
},
"license": "Apache-2.0",
"authors": [
{
"name": "neomerx",
"email": "info#neomerx.com"
}
],
"require": {
"php": ">=5.5.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6 || ^5.0 || ^6.0",
"mockery/mockery": "~0.9.4",
"scrutinizer/ocular": "^1.3",
"squizlabs/php_codesniffer": "^2.5",
"monolog/monolog": "^1.18",
"phpmd/phpmd": "^2.6"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Neomerx\\JsonApi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Neomerx\\Tests\\JsonApi\\": "tests/",
"Neomerx\\Samples\\JsonApi\\": "sample/"
}
},
"scripts": {
"test": ["#test-unit", "#test-cs", "#test-md"],
"test-unit": "./vendor/phpunit/phpunit/phpunit --coverage-text",
"test-unit-with-coverage": "phpdbg -qrr ./vendor/bin/phpunit --coverage-text",
"test-cs": "./vendor/bin/phpcs -p -s --standard=PSR2 ./src ./tests",
"test-md": "./vendor/bin/phpmd ./src text codesize,controversial,cleancode,design,unusedcode,naming",
"perf-php": "docker-compose run --rm cli_php php /app/sample/sample.php -t=10000",
"perf-hhvm": "docker-compose run --rm cli_hhvm hhvm /app/sample/sample.php -t=10000"
}
}
File app.php is in a directory called protocoloWT/ and status.php is in protocoloWT/models.
I installed a framework with composer and I can use those namespaces (Neomerx\JsonApi), but I can't create my own namespaces in my files because I get that error. What could be the issue?
PS: Sorry for my english, I have tried to explain it the best I can
I have this in my composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"alchemy/zippy": "^0.4.8",
"barryvdh/laravel-debugbar": "^3.1",
"fideloper/proxy": "~3.3",
"graham-campbell/exceptions": "^10.0",
"intervention/image": "^2.4",
"intervention/imagecache": "^2.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.5",
"symfony/dom-crawler": "^3.3"
},
"files": [
"vendor/redbutton/text-image-alpha/vendor/autoload.php"
],
"require-dev": {
"filp/whoops": "^2.1",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
The php files for my package are in a laravel installation:
/vendor/redbutton/text-image-alpha/src/
When I try to call a file I get the message:
Class 'Class 'RedButton\TextImageAlpha\TextImageAlpha' not found' not found
I use this to try and call the class:
$image = new \RedButton\TextImageAlpha\TextImageAlpha( 'some string' );
The file in /vendor/redbutton/text-image-alpha/src/TextImageAlpha.php looks like this:
<?php
namespace RedButton\TextImageAlpha;
use RedButton\TextImageAlpha\Exceptions;
use RedButton\Tools\Objects;
/**
* TextImageAlpha class convert a text to image.
*
* #author Tomas Rathouz <trathouz at gmail.com>
*/
class TextImageAlpha
{
// lots of code
}
This is my first composer package and I don't really have an idea of what is going wrong here. Could someone please explain to me what I'm doing wrong?
Good news. I've looked at your package at Bitbucket and you're doing it right in its composer.json:
Drop unnecessary code from composer.json
I've noticed in pasted composer.json there is manual adding of some vendor file.
"files": [
"vendor/redbutton/text-image-alpha/vendor/autoload.php"
],
/vendor nested in /vendor doesn't make sense as it might duplicate autoloading and break it.
Also I don't see redbutton/text-image-alpha in require section, where it should be.
How to add package the right way?
To install your package just call composer:
composer require redbutton/text-image-alpha
And that's it.
It should appear in require section in composer.json. Composer will autoload it by rules in composer.json of the package - here.
Test
I've tried following code and class is found correctly:
<?php
require __DIR__ . '/vendor/autoload.php';
$image = new \RedButton\TextImageAlpha\TextImageAlpha('some string');
var_dump($image);
Having composer.json:
{
"require": {
"redbutton/text-image-alpha": "^1.0"
}
}
Error:
Cell class Audit.AuditCell is missing. Cake\View\Exception\MissingCellException
Plugin files:
plugins/Audit/src/Template/Cell/Audit/model.ctp
plugins/Audit/src/View/Cell/AuditCell.php
In, src/Template/Servers/view.ctp:
echo $this->cell('Audit.Audit::model', [strtolower($this->request->controller), $this->request->pass[0]]);
In, config/bootstrap.php:
Plugin::load('Audit', ['bootstrap' => true, 'routes' => true]);
Using CakePHP 3.3.16.
Edit #1
Snapshot of my IDE:
Edit #2
Relevant parts of my composer.json
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "3.3.*",
"mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0",
"cakephp/plugin-installer": "*",
"adayth/cakephp-cipher-behavior": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "src",
"Audit\\": "./plugins/Audit/src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
"Audit\\Test\\": "./plugins/Audit/tests"
}
I added the proper namespace Audit\View\Cell to my file.