How can I install the Buzz bundle on Symfony 2.2.0? - symfony

I want to install the Buzz bundle. On GitHub, the installation instructions suggest the .bin/vendors install method. However, that's not supported in Symfony 2.2.0.
Is there another way I could install the bundle? I've been trying to install it using Composer, but without any luck.

Try adding in composer.json under require key:
"sensio/buzz-bundle": "dev-master"
Then follow the instructions from step3 onward
You'll also need to run composer.phar update after that.
And for future reference, lookup the package you need on packagist.org. You'll find there what you need to put in composer.json

Related

Use composer ton install depedencies while creating custom WP plugin

I'm really new to composer and don't understand it well (yet).
Here's the thing :
I'm building a Wordpress plugin that needs external libraries.
Thoses libraries are FluentDOM and Selectors-Symfony for FluentDOM.
Both have installation instructions for Composer only :
FluentDOM :
FluentDOM is available on Packagist.org, just add the dependency to your composer.json.
{
"require" : {
"fluentdom/fluentdom": "5.x"
}
}
Selectors-Symfony :
composer require symfony/css-selector
My plugin path is /wordpress/wp-content/my-custom-plugin.
Should I write a composer.json file at the root of this directory, and what should be its content ?
Eventually, I would like install those depedencies in /wordpress/wp-content/my-custom-plugin/_inc/lib
Could anyone explain me how to do this ?
Thanks !
Well, I'd say that unless Wordpress starts supporting Composer (they don't officially at this time although Wordpress can be installed with Composer if you know what you're doing, first and foremost know the package name of it), you shouldn't think too much about using it for delivery of your plugin, meaning: If you use other software in your plugin, I think you have to bundle it inside your plugin, or it won't work.
It still will create issues like "Is the version of the library you are using compatible with the same library other plugins use?" and "How do you do autoloading?" correctly.
Internally, you could use Composer to manage these libraries just like you would do with any other project that uses Composer, with the minor difference that the released package of your plugin must include all these libraries and autoloaders you added - with Composer or something else.
Be warned that I basically don't know anything about how Wordpress people usually organize their stuff. Reading the discussion I linked to in the comment to your question, I get the impression that they have still a very long way to go, and that there is nobody actively behind it and promotes using Composer for dependency management because it also works the usual way, or it might break things.
Internally, you could use Composer to manage these libraries just like
you would do with any other project that uses Composer, with the minor
difference that the released package of your plugin must include all
these libraries and autoloaders you added - with Composer or something
else.
Thanks Sven, that is what I wanted to know.
I finally managed to do it.
Here is my step-by-step guide to install a dependency (here, fluentDOM) into /wordpress/wp-content/plugins/my-custom-plugin/_inc/php with the terminal and without having any composer.json at the start.
First, of course, you need to install Composer. As I will use it for php dependencies of my plugin, I will install it in my-custom-plugin/_inc/php.
(You could also install it at the root of your plugin and adjust following commands)
1/ Open Terminal and go to that directory :
cd /Applications/MAMP/htdocs/my-project/wordpress/wp-content/plugins/my-custom-plugin/_inc/php
2/ Install Composer :
curl -sS https://getcomposer.org/installer | php
Now I'm ready to use Composer in my-custom-plugin/_inc/php.
On the fluentDOM website, I see that the package I need to install is called fluentdom/fluentdom.
3/ So, let's install the package :
composer require fluentdom/fluentdom
If you need more informations about this package, the website packagist could be useful. It shows informations (version, dependencies), ... for composer packages. See fluentdom/fluentdom.
This installs fluentdom in the default composer directory /vendor and generates a composer.json file; which is nice to update dependencies later.
Here's the generated content:
{
"require": {
"fluentdom/fluentdom": "~5.2"
}
}
But we wanted our dependency to be installed into my-custom-plugin/_inc/php, not into my-custom-plugin/_inc/php/vendor !
4/ Let's edit composer.json, and set the default directory parameter vendor-dir to empty.
{
"require": {
"fluentdom/fluentdom": "~5.2"
},
"config": {
"vendor-dir": ""
}
}
5/ Delete the my-custom-plugin/_inc/php/vendor directory as we don't need it anymore.
6/ Now that we have a composer.json file, we just have to run
composer.phar install
Or
composer.phar update
... and the magic happens ! Done !!! We have the dependencies installed, and an autoload.php file generated.
7/ The last thing to do is to include the autoload.php in your plugin :
require_once( plugin_dir_path( __FILE__ ) . '_inc/php/autoload.php' );
This was the way to achieve it without having a composer.json file.
If you have your composer.json file ready, skip steps 3 to 5.
I also suggest to read this blog post : 5 features to know about Composer PHP.

Installing phpunit - are the sebastian & symfony directories necessary?

When installing phpunit 4.0 using composer (in PHPStorm) I get ....
/phpunit
/sebastian
/symfony
Does anyone know why I get the 2nd two and if there are necessary in any way.
Thanks
these dependencies are necessary as you can see at the composer file of PHPUnit. Before Composer was around and they shipped the software only via PEAR, you need to install all the dependencies by your own. At the end nothing changed.
In case you are concerned about installing all these dependencies over and over again for every PHP project you need PHPUnit, you can install it globally on you system.
Add composer global require 'phpunit/phpunit=3.7.*' to your composer.json.
Yes, those two directories are necessary for PHPUnit to work.
The dependencies in the vendor folder are managed by composer for you, you don't need to worry here. The reason you have them is because you installed PHPUnit.
When you remove PHPUnit and those dependencies aren't required by any other package, they will be removed again.

How to update a single library with Composer?

I need to install only 1 package for my SF2 distribution (DoctrineFixtures).
When I run
php composer.phar update
I get
- Updating twig/twig (dev-master 39d94fa => v1.13.0)
The package has modified files:
M CHANGELOG
M doc/filters/batch.test
M doc/filters/index.rst
M doc/filters/url_encode.rst
M doc/functions/index.rst
M doc/tags/index.rst
M doc/tests/index.rst
M lib/Twig/Autoloader.php
M lib/Twig/Compiler.php
M lib/Twig/CompilerInterface.php
-10 more files modified, choose "v" to view the full list
It appears the last developer edited a lot of files inside vendor.
In order to get around this, I tried
php composer.phar update <package_name>
But that doesn't seem to work. How can I update/install only one library from composer.json?
To install doctrine/doctrine-fixtures-bundle with version 2.1.* and minimum stability #dev use this:
composer require doctrine/doctrine-fixtures-bundle:2.1.*#dev
then to update only this single package:
composer update doctrine/doctrine-fixtures-bundle
If you just want to update a few packages and not all, you can list them as such:
php composer.phar update vendor/package:2.* vendor/package2:dev-master
You can also use wildcards to update a bunch of packages at once:
php composer.phar update vendor/*
As commented by #ZeroThe2nd ZSH users may need to wrap their vendor/* in quotation marks:
php composer.phar update "vendor/*"
--prefer-source: Install packages from source when available.
--prefer-dist: Install packages from dist when available.
--ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option.
--dry-run: Simulate the command without actually doing anything.
--dev: Install packages listed in require-dev (this is the default behavior).
--no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules.
--no-autoloader: Skips autoloader generation.
--no-scripts: Skips execution of scripts defined in composer.json.
--no-plugins: Disables plugins.
--no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
--optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
--lock: Only updates the lock file hash to suppress warning about the lock file being out of date.
--with-dependencies: Add also all dependencies of whitelisted packages to the whitelist.
--prefer-stable: Prefer stable versions of dependencies.
--prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.
Difference between install, update and require
Assume the following scenario:
composer.json
"parsecsv/php-parsecsv": "0.*"
composer.lock file
"name": "parsecsv/php-parsecsv",
"version": "0.1.4",
Latest release is 1.1.0. The latest 0.* release is 0.3.2
install: composer install parsecsv/php-parsecsv
This will install version 0.1.4 as specified in the lock file
update: composer update parsecsv/php-parsecsv
This will update the package to 0.3.2. The highest version with respect to your composer.json. The entry in composer.lock will be updated.
require: composer require parsecsv/php-parsecsv
This will update or install the newest version 1.1.0. Your composer.lock file and composer.json file will be updated as well.
You can use the following command to update any module with its dependencies
composer update vendor-name/module-name --with-dependencies
You can basically do following one to install new package as well.
php composer.phar require
then terminal will ask you to enter the name of the package for searching.
$ Search for a package []: //Your package name here
Then terminal will ask the version of the package (If you would like to have the latest version just leave it blank)
$ Enter the version constraint to require (or leave blank to use the latest version) []: //your version number here
Then you just press the return key. Terminal will ask for another package, if you dont want to install another one just press the return key and you will be done.
Just use
composer require {package/packagename}
like
composer require phpmailer/phpmailer
if the package is not in the vendor folder.. composer installs it and if the package exists, composer update package to the latest version.
Update:
require install or update the latest package version. if you want update one package just use update.
To ensure that composer update one package already installed to the last version within the version constraints you've set in composer.json remove the package from vendor and then execute :
php composer.phar update vendor/package
Because you wanted to install specific package
"I need to install only 1 package for my SF2 distribution (DoctrineFixtures)."
php composer.phar require package/package-name:package-version
would be enough

How do you register bundles in Symfony2.1 designed for older versions of Symfony?

I am attempting to use they EntityAudit extension for Doctrine2 in my Symfony2.1 app.
I'm very new to this, and I've just started realizing how many "correct" methods there have been for installing new bundles for Symfony over the years. Some sort of "Deps" file used to exist but does no longer? When installing Symfony, "using Composer" was an option -- but purely an option, it seemed. Now I'm starting to think that's not true.
In EntityAudit's instructions it refers to "Autoload", and based on other things, I'm apparently supposed to modify the registerNamespaces array in my Autoload.php. Except I don't have that. So I found this link where the guy indicates Symfony2.1 doesn't do that anymore in favor of using Composer.
I don't really know how to use Composer in this case though. I don't really know how to use it at all, actually, but I seem to have bumbled through doing 1 or 2 basic things in it -- "updating" itself and "installing" .. vendors? Anyway, I can find no instructions general enough to be adapted for this need. Thanks in advance for any help!
The deps file is used in 2.0 to manage dependencies. The 2.1 version uses the much better Composer dependency management tool.
Install with composer
First you'll need some basix about composer. For instance, read this article: http://net.tutsplus.com/tutorials/php/easy-package-management-with-composer/
Before you can use composer to install a bundle you should look for a Packagist package of that bundle. For the SimpleThings\EntityAuditBundle you should look for a simplethings/entity-audit-bundle package and it does exists: https://packagist.org/packages/simplethings/entity-audit-bundle
SIDENOTE
Packagist is the main archive for Composer.
If you are searching for a bundle, the best thing you can do is check out
KnpBundles, it is the unofficial achive of Symfony Bundles.
If a bundle contains a README file, it is displayed there and if it has a Packagist
package it shows a link to the package. It's a really usefull site to begin searching
for bundles.
Now you have the package name, you should determine the version you want to use. As this is a not-finished bundle we can use the latest version by using the dev-master version. But it could be possible that a dev-master version is for Symfony2.2 and we should use another version if we use Symfony2.1, this should be in the README file (in the Package, which you can view on Github or KnpBundles). If it isn't in the README, you can use the version you want. An example of the note about version can be found in the StofDoctrineExtensionsBundle.
Now we can add the bundle to our composer.json file and update the dependencies. You can do this manually:
Add it to the composer.json file:
{
...,
"require": {
...,
"simplethings/entity-audit-bundle": "dev-master"
}
}
Update the dependency
$ php composer.phar update simplethings/entity-audit-bundle
or update all dependencies
$ php composer.phar update
Or you can do this is one command:
Run this command (which includes the package in the composer.json and updates the package)
$ php composer.phar require simplethings/entity-audit-bundle:dev-master
Now the bundle is installed into our Symfony project (in vendor/simpletings/) and the autoloader recognises this bundle. The only thing we need to do now is registering the bundle in the AppKernel:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
...,
new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
);
// ...
}
}

Symfony2 Composer Not Downloading Packages

I was recently trying to re-install the fos:userbundle and noticed the docs have changed. They are no longer using the deps file are now referencing the new package manager composer.
I found some info about integrating composer with sf2.0.* here:
http://knplabs.com/blog/symfony2-with-composer
After downloading the src: https://github.com/KnpLabs/symfony-with-composer
I tried adding the following to my composer.json: "friendsofsymfony/user-bundle": "*"
as per the instructions: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md
When I run bin/vendors update I get the following:
Updating dependencies
Nothing to install or update
Writing lock file
Generating autoload files
It does not appear to be installing the fos package. Am I missing something?
Thanks
Composer is a PHAR archive that takes care of installing dependencies, update them, create projects, etc. It has nothing to do with the old bin/vendors.
What you need to do is to download Composer:
curl -s http://getcomposer.org/installer | php
And install your dependencies:
php composer.phar install
By the way, the symfony-with-composer thing you downloaded is an old version of Symfony2 Standard Distribution that isn't maintained anymore, as mentioned on the repository itself.

Resources