I've just moved to Symfony 2.1, and I can't understand, how can I install my own bundles with Composer?
It was very easy in 2.0.x in deps:
[MyOwnBundle]
git=git#git.weboshin.ru:weboshin_cms_bundle.git
target=/bundles/My/OwnBundle
After that I just triggered bin/vendors update and that was it!
But now there's no deps file, and I supposed to do everything with Composer. Please give me any hints.
I've found the answer.
// my_project/compose.json:
{
"repositories": [
{
"type": "vcs",
"url": "own_repository_url"
}
],
// ...
"require": {
// ...
"own/bundle": "dev-master"
}
},
// own_repository/own_bundle/compose.json:
{
"name": "own/bundle"
}
Add a composer.json file to your bundle. For example I have this for one of my bundles:
{
"name": "cg/kint-bundle",
"type": "symfony-bundle",
"description": "This bundle lets you use the Kint function in your Twig templates. Kint is a print_r() replacement which produces a structured, collapsible and escaped output",
"keywords": ["kint", "debug", "symfony", "bundle", "twig"],
"homepage": "http://github.com/barelon/CgKintBundle",
"license": "MIT",
"authors": [
{
"name": "Carlos Granados",
"homepage": "http://github.com/barelon"
},
{
"name": "Symfony Community",
"homepage": "http://github.com/barelon/CgKintBundle"
}
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.0.0",
"raveren/kint": "dev-master"
},
"minimum-stability": "dev",
"autoload": {
"psr-0": {
"Cg\\KintBundle": ""
}
},
"target-dir": "Cg/KintBundle"
}
Then add your bundle to packagist.org. It is very simple, basically you just have to provide your git address and it will do the rest.
Once your bundle is available in packagist, then just add it as a dependency in the composer.json file for your symfony project. In my case I have:
"require": {
....
"cg/kint-bundle": "*"
},
Then just run "composer update" in your symfony directory and that´s all! You don´t even need to update the autoload file, composer will do it for you. The only thing left would be to load the bundle in appkernel.php
Related
there is a syntax error in my composer.json file but I just can't seem to find the error. I already have a Laravel object on top of the file, but I also want to add Goaop, like the following code.
how can I do it? thank you
//newly added code
{
"name": "goaop/goaop-laravel-bridge",
"description": "Integration bridge for Go! AOP framework",
"type": "library",
"keywords": ["bridge", "laravel", "aop", "php", "aspect"],
"require": {
"goaop/framework": "^1.0|^2.0",
"laravel/framework": "^5.0"
},
"license": "MIT",
"authors": [
{
"name": "Lisachenko Alexander",
"email": "lisachenko.it#gmail.com"
}
],
"autoload": {
"psr-4": {
"Go\\Laravel\\GoAopBridge\\": "./src"
}
}
}
Looks like you just copied the package's composer.json and pasted it to the bottom of yours. That is not how you install packages.
From your command line run:
composer require goaop/goaop-laravel-bridge
This will update your composer.json and .lock files and install the package.
I have two projects. One is my application and the second one is an external module that I want to use in future apps.
I have created my external module on GitHub and included in the composer.json of my application.
My external module gets downloaded / cloned but the required dependencies are not installed by composer.
Here's composer.json of my application:
{
"name": "application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.5",
"zendframework/zendframework": "2.*",
"zf-commons/zfc-user": "1.4.4",
"doctrine/doctrine-orm-module": "~0.9.2",
"zf-commons/zfc-user-doctrine-orm": "1.0.*",
"zendframework/zend-developer-tools": "^0.0.2",
"username/GlideUser": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/username/GlideUser.git"
}
]
}
Here's composer.json of my external module:
{
"name": "username/glide-user",
"description": "Module For Zend Framework 2",
"type": "library",
"license": "BSD-3-Clause",
"homepage": "https://github.com/username/GlideUser",
"keywords": [
"zf2",
"zfc-user",
"bjyauthorize"
],
"authors": [
{
"name": "Haris Mehmood",
"email": "abc#outlook.com",
"homepage": "abc.com",
"role": "Developer"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.3.3",
"bjyoungblood/bjy-authorize": "1.4.0"
},
"autoload": {
"psr-0": {
"GlideUser\\": "src/"
}
}
}
When I run composer install or composer update I expect bjyauthorize package to gets installed, but composer ignore the dependency and install everything else.
What is it that I am doing wrong here.
Try updating the following line in your application composer.json from:
"username/GlideUser": "dev-master"
to:
"username/glide-user": "dev-master"
This way, what is being required matches the name of the external module, which is the name defined inside the external module's composer.json.
Although it does not look directly applicable to the dependencies of the external module not installing, it could be the cause.
I would like to know how to register a dependency when creating laravel package.
In my package composer.json I have :
{
"name": "facilinfo/gallery",
"description": "Photo galleries management package for laravel",
"type": "library",
"license": "MIT",
"keywords": ["laravel"],
"authors": [
{
"name": "facilinfo",
"email": "contact#facil-info.net"
}
],
"minimum-stability": "stable",
"require": {
"laravelcollective/html": "5.2.*",
"intervention/image": "dev-master"
},
"autoload": {
"psr-4": {
"Facilinfo\\Gallery\\": "src/"
}
}
}
And when I do
$form = new Form();
I have a Class not found error.
How can I solve it?
Finally, I found the soultion myself. I had tout add this to my package service provider register function:
$this->app->register(\Collective\Html\HtmlServiceProvider::class);
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Form', '\Collective\Html\FormFacade');
and to add "laravelcollective/html": " 5.2.*" in the laravel installation where I'm developping my package and install in. It works now.
I'm trying to install this github repo to my project (running on codeigniter). The steps I'm doing is very simple:
{
"name": "project",
"description": "",
"license": "MIT",
"require": {
"php" : ">=5.3.0",
"blockchain/blockchain" : "1.*",
"ext-curl": "*"
},
"require-dev": {
}
} // composer.json
and run php composer.phar update. So the package installs but I can't use it in my project - I don't think its autoloaded. /vendor/autoload.php is required in my index.php. When I try it with different package for test purposes (kriswallsmith/buzz) - it works. So what I'm doing wrong?
Also I checked my vendor/composer/installed.json and I see this:
[
{
"name": "blockchain/blockchain",
"version": "v1.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/blockchain/api-v1-client-php.git",
"reference": "c219b9b00778cf6c025628bd34fd6543922fe81b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/blockchain/api-v1-client-php/zipball/c219b9b00778cf6c025628bd34fd6543$
"reference": "c219b9b00778cf6c025628bd34fd6543922fe81b",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.0"
},
"time": "2015-02-03 18:34:11",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Blockchain\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Blockchain API client library",
"homepage": "https://github.com/blockchain/api-v1-client-php",
"keywords": [
"bitcoin",
"blockchain"
]
}
]
and my function where I'm trying to use this lib:
private function __check_btc_balance()
{
error_reporting(E_ALL);
$Blockchain = new \Blockchain\Blockchain(PAYMENTS_BTC_API_CODE);
}
Have you followed the installation steps?
Basically there are some differences from common composer packages. Over here it says download the source code and run composer install from it's own folder
Then include the autoloader file from the folder of the downloaded files so you will have somewhere a folder Blockchain/vendor/autoload.php to include
Download the source or clone the repository. This php library works
with the Composer package manager. Navigate to the root of the
repository and run
$ composer install
This will create the /vendor folder in the repository root. In the php
source, simply:
// Include the autoload.php from its vendor directory require
'vendor/autoload.php'
// Create the base Blockchain class instance
I've seen ...
"autoload": {
"psr-4": {
"Blockchain\\": "src/"
}
},
I always keep all my code in src\Vendor\Project\Filename.php and composer autoloader works with this. Try to add this lines of code:
"autoload": {
"psr-0": {
"": "src/"
}
},
Can someone explain how I'm supposed to use composer with a php. I have a composer.json file in my doc root that downloads the core packages for my project, but then when I want to add another project like google+ php sdk found here https://github.com/googleplus/gplus-quickstart-php/
what do I do with that composer.json file? do i combine them manually? Do I just download that composer.json into a different dir?
my current composer.json file looks like this
{
"name": "fuel/fuel",
"type": "metapackage",
"description": "The FuelPHP framework",
"keywords": ["framework"],
"homepage": "http://fuelphp.com",
"license": "MIT",
"authors": [
{
"name": "FuelPHP Development Team",
"email": "team#fuelphp.com"
}
],
"support": {
"irc": "irc://irc.freenode.org/fuelphp",
"forum": "http://fuelphp.com/forums"
},
"require": {
"php": ">=5.3.3",
"monolog/monolog": "1.5.*",
"fuelphp/upload": "2.0",
"omissis/php-cloudfiles": "dev-master",
"mustache/mustache": "*"
},
"suggest": {
"mustache/mustache": "Allow Mustache templating with the Parser package",
"smarty/smarty": "Allow Smarty templating with the Parser package",
"twig/twig": "Allow Twig templating with the Parser package",
"mthaml/mthaml": "Allow Haml templating with Twig supports with the Parser package"
},
"config": {
"vendor-dir": "fuel/vendor"
},
"minimum-stability": "dev"
}
The g+ composer.json file looks like
{
"name": "googleplus/quickstart",
"description": "This quick-start app is built in PHP and lets you get started with the Google+ platform in a few minutes.",
"license": "Apache-2.0",
"repositories": [
{
"type": "package",
"package": {
"name": "google/google-api-php-client",
"version": "0.6.2",
"dist": {
"url": "http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.2.tar.gz",
"type": "tar"
},
"autoload": {
"classmap": [
"src/"
]
}
}
}
],
"require": {
"silex/silex": "1.0.*#dev",
"twig/twig": ">=1.8,<2.0-dev",
"google/google-api-php-client": "0.6.2"
}
}
Simply add this into the require block of your original composer file:
"googleplus/quickstart": "*",
I have little experience with Composer, but I can tell you that when you require a lib, you add that lib to your main composer.json file. Upon installation or update, the new lib will be downloaded and its composer.json file will be read by Composer; its dependencies will be automatically downloaded, and so on.
So we could say you're not supposed to download your requirements manually, you have to use Composer for that, it will take care of it for you.