Can't use Symfony VarDumper - Attempted to call function "dump" from namespace - symfony

Context
I'm currently working on an OroPlatform project (4.1.10) and I can't use the Symfony dump function in my controllers.
Issue
I've seen on Packagist that OroPlatform 4.1.10 has the symfony/symfony dependency which contains symfony/var-dumper: v4.4.13 and when I've tried to install it, I've got the following error message : Package symfony/var-dumper is not installed

To register the dump function, you have to edit src\AppKernel::registerBundles() method to add there
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
inside if ('dev' === $this->getEnvironment()) { statement

Related

Install twig/extensions on a Symfony 4 or Symfony 5 new project

I'm preparing to migrate a huge website from Symfony 3.4 to Symfony 4.4.
To do this, I'm starting from a new fresh installation of Symfony 4.4, and as the intial project requires the use of Twig Extensions I try to install it on this new Symfony 4.4 project.
But composer indicates Your requirements could not be resolved to an installable set of packages.
The error message is obvious, but I don't understand why this situation happens on a fresh symfony 4.4 project.
What I tried :
I create a new Symfony symfony new --full --version=lts testproject that installed Symfony 4.4 and right after composer require twig/extensions => Your requirements could not be resolved to an installable set of packages.
I create a new Symfony symfony new --full testproject that installed Symfony 5.0 and right after composer require twig/extensions => Your requirements could not be resolved to an installable set of packages.
I tried with Symfony flex but same problem => Your requirements could not be resolved to an installable set of packages.
I retried after clearing the composer cache but no change.
This worked :
- I create a new Symfony symfony new --full --version=3.4 testproject that installed Symfony 3.4 and right after composer require twig/extensions => OK
I understand that dependencies conflits occur for Symfony 4.4 and more, but according to Symfony doc How to Write a custom Twig Extension no further actions are required and it should work.
What I'm missing ? Does someone faced the same problem ? Thanks
if you're using Flex, you should install twig first:
composer req twig
then, do:
composer require twig/extensions
I hope that help.
Finally it seems that running composer require twig/extensions is no more required to create custom Twig Extensions in Symfony 4.
By default a new Symfony built with website skeleton owes a use Twig\Extension\AbstractExtension; as per required to create a twig extension like below one :
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('price', [$this, 'formatPrice']),
];
}
public function formatPrice($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
{
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
$price = '$'.$price;
return $price;
}
}

HWIOauthbundle with FOSUserbundle Integration error

Attempted to load class "Curl" from namespace "Buzz\Client". Did you
forget a "use" statement for another namespace? 500 Internal Server
Error - ClassNotFoundException
in app/cache/dev/appDevDebugProjectContainer.php at line 1809 -
protected function getHwiOauth_HttpClientService()
{
$this->services['hwi_oauth.http_client'] = $instance = new \Buzz\Client\Curl();
$instance->setVerifyPeer(false);
$instance->setTimeout(10);
When you asking a question please specify your operating system and versions of frameworks you are using (e.g. symfony 2). Here is an answer for windows and symfony2
1) Delete manually added folders
2) If you don't have composer installed, install it
For windows
For other read this
2) Install HWIOAuthBundle
HWIOAuthBundle readme.md
option i) Using composer
Open the symfony project directory where composer.json resides.
Open command prompt (In Windows: Shift key + Right click => open command window here)
Run this
composer require hwi/oauth-bundle
OR
option ii) Add dependencies to your composer.json (not recomended)
"require": {
// other dependencies will be here //
"hwi/oauth-bundle": "^0.4.0",
"friendsofsymfony/user-bundle": "^1.3"
}
then execute following command
composer install

Creating vendor bundle in symfony2 and deploying it via composer

I'm trying to create my first vendor bundle. I have found a lot of informations in this question but i'm stuck.
My github repository is available here :
https://github.com/vtedesco/Peary
I have registered it in composer :
https://packagist.org/packages/vted/peary
In another project I have installed it via the command composer require vted/peary, files are correctly visible under my directory vendors/vted/peary.
But when it try to add it in AppKernel.php like this:
$bundles = array(
...
new Vted\PearyBundle\VtedPearyBundle(),
...
);
I get the following error :
ClassNotFoundException in AppKernel.php line 24:
Attempted to load class "VtedPearyBundle" from namespace "Vted\PearyBundle".
Did you forget a "use" statement for "Vted\PearyBundle\VtedPearyBundle"?
I think it's maybe a naming issue somewhere but I can't find it. The VtedPearyBundle.php class look good for me.
Your current bundle structure is more suitable for the psr-4 autoloader:
{
"autoload" : {
"psr-4" : {
"Vted\\PearyBundle\\" : ""
}
}
}
Alternatively, you can use the target-dir with psr-0. However, the psr-4 autoloader is preferred.

Install JMSSerializerBundle

I installed FOSRestBundle but it needs JMSSerializerBundle.
I added in my deps the next lines:
[JMSSerializerBundle]
git=git://github.com/schmittjoh/JMSSerializerBundle.git
target=bundles/JMS/SerializerBundle
Here it explains how to do it: http://jmsyst.com/bundles/JMSSerializerBundle/master/installation
but when I try $php bin/vendors install it shows me an error:
[InvalidArgumentException]
The service definition "jms_serializer.serializer" does not exist.
You should comment the new FOS\RestBundle\FOSRestBundle(), line in AppKernel.php in the registerBundles() method. Then install the JmsSerializerBundle and after that you should decommend that line and register the JsmSerializerBundle.
The manual says it to register the bundle with the kernel:
new JMS\Serializer\JMSSerializerBundle($this),
but the installer create the folder: vendor/bundles/JMS/SerializerBundle
so, it must be added the next line to the AppKernel.php instead of the other:
new JMS\SerializerBundle\JMSSerializerBundle($this),
Did you also do the following steps from the manual? Sounds to me like you didn't add the line
new JMS\Serializer\JMSSerializerBundle($this)
to AppKernel.php

How to install a Symfony 2.0 Bundle from Zip file

I tried installing the FixturesBundle as described in http://symfony.com/doc/2.0/bundles/DoctrineFixturesBundle/index.html but my proxy wont let me out.
So I went to https://github.com/doctrine/data-fixtures and download a zip from the latest commit.
I unzipped into the vendor directory and renamed it to doctrine-fixures. I edited the autoload.php and AppKernel.php files as described in the tutorial.
When I run:
php app\console doctrine:fixtures:load
I get the following message:
PHP Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesB
undle' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on
line 20
Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle
' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on line
20
Is there a way to run the installation of bundle pointing it to a zip file?
I´m running Symfony 2.0.9 on Windows 7.
Seems like the doctrine bundle has been moved outside of Symfony scope back to Doctrine.
Please, use https://github.com/doctrine/DoctrineFixturesBundle
I had the same problem and this is how i successfully solved it. I started to download this files data-fixtures and DoctrineFixturesBundle, unzipped both into /vendor/doctrine and created this folder structure:
vendor
- doctrine
- doctrine-fixtures-bundle
- Doctrine
- Bundle
- FixturesBundle
DoctrineFixturesBundle.php
..other files...
vendor
- doctrine
- data-fixtures
- lib
- test
composer.json
..other files...
Then i edited the AppKernel.php and added
public function registerBundles(){
.....
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
.....
}
Edited the composer.json located in the root of the project and added this 2 lines:
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
Mine, now look like this:
{
"autoload": {
"psr-0": {
"": "src/",
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
}
}
}
afterwards execute composer dump-autoload -o to recreate the classmap. All this was thanks to the users Wouter J and nifr that answered my question How to install DoctrineFixturesBundle offline
Happy coding!
Yes, it's true that Doctrine is being moved away from the Symfony namespace (see here).
So if you're using the Symfony standard distribution you download from the website (without using git), and you want to have the FixturesBundle installed manually, you have to download the doctrine-fixtures library from here, extract the zip into
YourProject/vendor/doctrine-fixtures
Download the FixturesBundle from here, and extract it in
YourProject/vendor/bundles/Doctrine/Bundle/FixturesBundle
Then you have to register the library's namespace, do it by adding
'Doctrine\\\\Common\\\\DataFixtures' => \__DIR\__.'/../vendor/doctrine-fixtures/lib',
in your autoload.php.
In addition, you'll have to register the Doctrine's namespace, because some part of your application will be using the DoctrineBundle shipped from the Symfony namespace, but the new downloaded FixturesBundle will be using the new Doctrine's namespace, so to make it work, in your autoload.php add the following line (taking care you do it before the Doctrine namespace, remember that more specific rules go first!)
'Doctrine\\\\Bundle' => \__DIR\__.'/../vendor/bundles',
So all you have to do now is to register the new bundle in your AppKernel.php writing
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

Resources