Symfony2 - PHP fatal error Class not found - composer-php

I have a weird behaviour with my symfony2 project. A few days ago, I've tried to add a custom form listener which failed because symfony didn't find the namespace. <- Just for your information
I didn't work on this error, because I had some other things to do. Now, I wanted to add an VAT-Validator to my signup form and I was using
composer require ddeboer/vatin-bundle
to add this bundle to my project. It was working great in my dev-enviroment. Then, when I wanted to update my project on my staging-webserver with git and while clearing the cache with
php app/console cache:clear --env=prod
I get this message:
PHP Fatal error: Class 'Ddeboer\VatinBundle\DdeboerVatinBundle' not found in ../app/AppKernel.php on line 24
I have tried it with other bundles, too. But its the same error with every "new" bundle. Since, I have experienced the namespace problem just a few days before, I guess there is a problem with autoloading or something.
Already, tried various solution I have found on google and stackoverflow.
In the documentation, there is a hint:
If you get a "class not found" error during this step, you may need to run export SYMFONY_ENV=prod before running this command so that the post-install-cmd scripts run in the prod environment.
I am using windows and this command is not working. Also, on my ubuntu server I can use this command, but there seems to be no effect.
Here is my composer.json:
{
"name": "Admin/myproject",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
}
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.7.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/elastica-bundle": "^3.2",
"elasticsearch/elasticsearch": "~1.0",
"cocur/slugify": "^2.0",
"ddeboer/vatin-bundle": "^2.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3",
"phpdocumentor/phpdocumentor": "~2.2"
},
"scripts": {
"post-root-package-install": [
"SymfonyStandard\\Composer::hookRootPackageInstall"
],
"post-install-cmd": [
"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::removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"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::removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
]
},
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
}
}

Related

Laravel deployment to azure windows web app using GitHub gives error requires ext-fileinfo * -> it is missing from your system

I am getting the following error when I try to deploy my laravel project to azure windows web app using github.
but it is deploying fine if I use azure tool
Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/framework[v7.29.0, ..., 7.x-dev] require league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.0, ..., 1.x-dev].
- league/flysystem[1.1.0, ..., 1.x-dev] require ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
- Root composer.json requires laravel/framework ^7.29 -> satisfiable by laravel/framework[v7.29.0, ..., 7.x-dev].
To enable extensions, verify that they are enabled in your .ini files:
- C:\tools\php\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
I have tried php --ini
C:\Program Files(x86)\PHP\v7.4\php.ini Scan for additional .ini files in:
and in that file it is enabled
extension=fileinfo
also here is my composer file
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.4 || ^8",
"doctrine/dbal": "^2.13",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
"laravel/framework": "^7.29",
"laravel/tinker": "^2.5",
"predis/predis": "^1.1",
"tcg/voyager": "^1.4",
"tymon/jwt-auth": "^1.0"
},
"require-dev": {
"facade/ignition": "^2.0",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.3",
"phpunit/phpunit": "^8.5.8|^9.3.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"platform-check": false
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"repositories": {
"hooks": {
"type": "composer",
"url": "https://larapack.io"
}
}
}
After searching for 24 hours, I have found the solution. This is related to the php set up while deployment. To setup PHP with necessary extensions you will need to update your .yml file on GitHub repository (.github/workflows folder).
Add a new line to "Setup PHP >> with" step like "extensions: fileinfo"
If you need to enable any other extension, you can add all of the extensions as comma seperated.
Example:
- name: Setup PHP
uses: shivammathur/setup-php#v2
with:
php-version: '7.4'
extensions: fileinfo, pdo_mysql
Please read this documentation: https://github.com/shivammathur/setup-php#heavy_plus_sign-php-extension-support

ErrorException When Registering with Laravel 8 Jetstream

I started a project on Laravel 7 just before the launch of Laravel 8, I am still learning this framework, so I updated to that version using this steps, and I am aware of this new scaffolding library call Jetstream that I installed with these steps:
composer require laravel/jetstream
php artisan jetstream:install livewire --teams
npm install && npm run dev
php artisan migrate
After working on my views and models I am proceeding to implement sessions functionalities, but when I tried to register with the project at localhost:8000/register, and having my data validated I get this error
Trying to get property 'id' of non-object (View: \path-to\my-project\resources\views\navigation-dropdown.blade.php) (View: \path-to\my-project\resources\views\navigation-dropdown.blade.php) (View: \path-to\my-project\resources\views\navigation-dropdown.blade.php)
http://localhost:8000/dashboard
This is the section of view that is throwing the exception
navigation-dropdown.blade.php line 169 this is the vanilla file
<!-- Team Settings -->
<x-jet-responsive-nav-link href="{{ route('teams.show', Auth::user()->currentTeam->id) }}" :active="request()->routeIs('teams.show')">
{{ __('Team Settings') }}
</x-jet-responsive-nav-link>
The data introduced in the register form gets stored in the database, but the error happens
I checked this other question Laravel Jetstream + Livewire + Teams FeatureTest problems when authenticate but it seems that answer apply to a different context since it is dealing with tests, no the vanilla register functions.
This is my current composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3.0",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.0",
"laravel/jetstream": "^1.0",
"laravel/sanctum": "^2.6",
"laravel/tinker": "^2.0",
"livewire/livewire": "^2.0"
},
"require-dev": {
"facade/ignition": "^2.3.6",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
I tried installing to test a fresh Laravel project with Jetstream, and this worked as it should, that let me confused as to what happened with my current project.
In the end, what worked for me was create a new fresh project with jetstream, then in my original project deleted the vendor and node_modules folder then copying the files of the new fresh project unto my original project and now it works as expected
Answer added on behalf of OP.
The user was not created with a team assigned, see users table and column current_team_id is null.
The navigation-menu.blade.php checks only for TeamFeatures but not if a team is really assigned.
#if (Laravel\Jetstream\Jetstream::hasTeamFeatures())
#if (Laravel\Jetstream\Jetstream::hasTeamFeatures() && Auth::user()->current_team_id)
For details here is the issue trying to get property of non-object

Upgrade Laravel version from 5.2.45 to 5.4

I am working on an existing application and the application is in laravel framework(version 5.2.45).And now i have to upgrade it to the version(5.4).I have follow the upgrade version step from laravel official documentation. Below is the steps which i have done :
1) Update the version number in laravel composer.json file in "laravel/framework" key.
2) Then after run the command composer update.
3) After that during executing the command i face error and the solution of that is to add the below line in composer.json file.
"minimum-stability": "dev",
"prefer-stable": true,
4) Then after again i execute the command composer update.Now i am facing the issue which i have attached in the below image :
Here is the code of composer.json file :
{
"name": "ozdemirburak/laravel-5-simple-cms",
"description": "Simple Laravel 5 content management system for starters.",
"keywords": [
"framework",
"laravel",
"cms"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.4.*",
"laravelcollective/html": "5.2.*",
"baum/baum": "~1.1",
"kris/laravel-form-builder": "1.6.*",
"laracasts/flash": "~1.3",
"mews/purifier": "~2.0",
"cviebrock/eloquent-sluggable": "~3.1.4",
"barryvdh/laravel-elfinder": "0.3.*",
"spatie/laravel-analytics": "~1.1",
"yajra/laravel-datatables-oracle": "~6.0",
"pingpong/modules": "~2.1",
"caffeinated/menus": "~2.0",
"fisharebest/laravel-assets": "~1.0",
"caffeinated/themes": "2.0.5",
"teepluss/theme": "dev-master",
"roumen/sitemap": "2.6.*",
"maatwebsite/excel": "^2.1",
"intervention/image": "^2.3",
"laravel/socialite": "^2.0",
"xinax/laravel-gettext": "^3.1",
"omnipay/paypal": " *",
"mews/captcha": "^2.2"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*",
"phpspec/phpspec": "~2.1",
"doctrine/dbal": "~2.5",
"squizlabs/php_codesniffer": "~1.5",
"laracasts/generators": "~1.1.3",
"barryvdh/laravel-ide-helper": "~2.0",
"barryvdh/laravel-debugbar": "~2.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize",
"php artisan elfinder:publish"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"preferred-install": "dist"
}
}
Note : For the current error i also found a solution in the stackoverflow and i implement that thing but still i am getting this error.
Thanks in advance!
You should update step by step, in your case update to 5.2 => 5.3 and after that 5.3 => 5.4 Please check laravel official documentation.
According to the error output:
"caffeinated/themes": "2.0.5" is locked to Laravel 5.1/5.2.
Upgrade that first.
Then the rest should follow.

Testing pull requests

I recently discovered a vulnerability in a package that I like to use in my Laravel projects. The package is a log viewer for Laravel: https://github.com/ARCANEDEV/LogViewer.
I put in an issue about the vulnerability and the owner said I can put in a Pull Request to try and rectify the issue, and I feel I could at least try.
My question is: is there a way to use the version of the package with my Pull Request in a testing environment, as if I were installing it via Composer?
Essentially, away from actual unit tests, is there a way to test run a package in a project?
Updates given research and available answers
After much Googling and reading of answers I tried the following:
Fork the repo I'm looking to make a pull request for. The fork is here: https://github.com/blorange2/LogViewer
Clone this forked repo onto my local machine and switch to the branch that's compatible with my current version of Laravel (which is v4.5 for Laravel 5.6)
Update the composer.json in my local project to have a repositories array
"repositories": [
{
"type": "path",
"url": "../forks/LogViewer"
}
],
With the whole thing looking like this:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"repositories": [
{
"type": "path",
"url": "../forks/LogViewer"
}
],
"require": {
"php": "^7.1.3",
"alexusmai/laravel-purifier": "^0.5.0",
"arcanedev/log-viewer": "^4.5",
"artesaos/laravel-linkedin": "^1.3",
"barryvdh/laravel-dompdf": "^0.8.4",
"cartalyst/tags": "6.0.*",
"cornford/googlmapper": "^2.33",
"doctrine/dbal": "^2.9",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"guzzlehttp/psr7": "^1.4",
"happyr/linkedin-api-client": "^1.0",
"intervention/image": "^2.5",
"ixudra/curl": "^6.16",
"jdavidbakr/mail-tracker": "~2.1",
"laravel/framework": "5.6.*",
"laravel/scout": "^5.0",
"laravel/socialite": "^3.0",
"laravel/tinker": "^1.0",
"laravelcollective/html": "^5.6",
"laravolt/avatar": "^3.0",
"league/flysystem-sftp": "~1.0",
"maatwebsite/excel": "^3.1",
"maddhatter/laravel-fullcalendar": "^1.3",
"mews/purifier": "^2.1",
"php-http/curl-client": "^1.7",
"php-http/message": "^1.6",
"pusher/pusher-http-laravel": "^4.2",
"socialiteproviders/microsoft-graph": "^2.0",
"spatie/calendar-links": "^1.0",
"spatie/flysystem-dropbox": "^1.2",
"spatie/laravel-analytics": "^3.6",
"spatie/laravel-backup": "^5.9",
"spatie/laravel-medialibrary": "7.6.3",
"spatie/laravel-permission": "^2.12",
"teamtnt/laravel-scout-tntsearch-driver": "^3.0",
"thujohn/twitter": "^2.2",
"unisharp/laravel-filemanager": "~1.8",
"vimeo/laravel": "^5.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
},
"autoload": {
"files": [
"app/Helpers/Helper.php"
],
"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
},
"minimum-stability": "dev",
"prefer-stable": true
}
My main project is located at the following path (from running pwd on Windows) C:\xampp\htdocs\projects\newable\newable-intranet
The cloned, forked project is located here: C:\xampp\htdocs\projects\forks\LogViewer.
However, running composer update does not use the local version, it just uses: "arcanedev/log-viewer": "^4.5",
When you want to use a custom version of a library in your project like with the original package, you can modify the composer.json.
You can add custom package sources (aka repositories) to your composer.json for local development I prefer the path-repository:
{
"repositories": [
{
"type": "path",
"url": "../LogViewer"
}
],
"require": {
"arcanedev/log-viewer": "*",
...
},
...
}
So if your project and LogView-library are in the same workspace directory, side by side, this will jump up to that workspace-directory and go into the library folder. In there it will look for a composer.json. You should then be able to update to your custom library, e.g. using composer require arcanedev/log-viewer:"*" or by manually changing the entry as shown above and then runcomposer install`.
Making composer download the custom version can be a bit tricky from time to time, but in general this should work. If it won't "download" your version, i.e. symlink the local folder, try removing the existing vendor folder and running composer install again. You can also add debug output to composer install -vvv to see if the repository is found and used.
The less elaborate approach would be to remove the original library folder inside your project's vendor/ folder and instead place a symlink to your custom library manually. This is usually enough when all you do is a small bugfix inside the library's code, but when you change dependencies and version requirements I prefer the first approach as it basically simulates downloading the package through composer making sure it is properly usable in client projects.

Composer Installation in windows Error

Tried to install composer in windows through command line. Downloaded composer.phar. Placed it in C/wamp/www/s/ folder. During installation got this error.
[RuntimeException]
Error Output: make: *** No rule to make target `compile-json'. Stop.
What should I do now..?
This is my composer.json
{
"name": "aws/aws-sdk-php",
"homepage": "http://aws.amazon.com/sdkforphp",
"description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project",
"keywords": ["aws","amazon","sdk","s3","ec2","dynamodb","cloud","glacier"],
"type": "library",
"license": "Apache-2.0",
"authors": [
{
"name": "Amazon Web Services",
"homepage": "http://aws.amazon.com"
}
],
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues"
},
"require": {
"php": ">=5.5",
"guzzlehttp/guzzle": ">=5.3|~6.0.1|~6.1",
"guzzlehttp/guzzle":"~4.0",
"guzzlehttp/psr7": "~1.0",
"guzzlehttp/promises": "~1.0",
"mtdowling/jmespath.php": "~2.2"
},
"require-dev": {
"ext-openssl": "*",
"ext-pcre": "*",
"ext-spl": "*",
"ext-json": "*",
"ext-dom": "*",
"ext-simplexml": "*",
"phpunit/phpunit": "~4.0",
"behat/behat": "~3.0",
"doctrine/cache": "~1.4",
"aws/aws-php-sns-message-validator": "~1.0"
},
"suggest": {
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
"ext-curl": "To send requests using cURL",
"doctrine/cache": "To use the DoctrineCacheAdapter"
},
"autoload": {
"psr-4": {
"Aws\\": "src/"
},
"files": ["src/functions.php"]
},
"autoload-dev": {
"psr-4": {
"Aws\\Test\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"scripts": {
"post-autoload-dump": [
"make compile-json"
]
}
}
Thank you for posting your composer.json file.
The error comes from the following invalid entry:
"scripts": {
"post-autoload-dump": [
"make compile-json"
]
}
The make command will not work on Windows.
I suggest to simply remove this part of the file and try again.
(Its not clear to me, which of your project dependencies needs an additional make step and why you added it. Anyway this composer.json seems to be identical to https://github.com/aws/aws-sdk-php/blob/master/composer.json . If you want to contribute to this project ask them how to build on Windows :)
If you simply want to fetch the aws-sdk-php package.
Follow their installation guide: http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html
Use php composer.phar require aws/aws-sdk-php on the CLI.
Or add aws/aws-sdk-php to your require section and then run composer install, like so:
{
"require": {
"aws/aws-sdk-php": "^3.3"
}
}

Resources