Composer require version but allow also develop branches - symfony

Current composer
"require": {
"php": ">=5.5",
"other/bundle": "~1.0"
},
When some use other/bundle on dev-develop or another branch he can't install my bundle. How I can allow this?

This is what stability flags are for.
"require": {
"php": ">=5.5",
"other/bundle": "~1.0#dev"
},

Related

Missing Classes from Silverstripe Omnipay

On a fresh scotch box https://box.scotch.io/ (which I generally recommend)
and with this composer:
{
"name": "silverstripe/installer",
"description": "The SilverStripe Framework Installer",
"require": {
"php": ">=5.3.3",
"silverstripe/cms": "3.5.1",
"silverstripe/framework": "3.5.1",
"silverstripe/reports": "3.5.1",
"silverstripe/siteconfig": "3.5.1",
"silverstripe-themes/simple": "3.1.*",
"silverstripe/silverstripe-omnipay": "^2.1",
"omnipay/paymentexpress": "^2.2",
"firebase/php-jwt": "^4.0"
},
"require-dev": {
"phpunit/PHPUnit": "~3.7#stable"
},
"extra": {
"branch-alias": {
"3.x-dev": "3.5.x-dev"
}
},
"config": {
"process-timeout": 600
},
"prefer-stable": true,
"minimum-stability": "dev"
}
And using payment.yml from https://github.com/silverstripe/silverstripe-omnipay
Silverstripe builds Payments, but none of the Omnipay classes are included. I have used Omnipay before with SS with no problems.
Anybody know what is going on?
Make sure you run the following on the command-line:
$> ./framework/sake dev/build flush=all
Also always worth just blowing away the contents of SS' cache (You're using Vagrant, so assuming this is a Dev env) which is usually located in /tmp if you're using the F/S and not memcache or some such, then running dev/build again. This will both clear and rebuild your cache, and in the process tell SS about all the new classes it has available to it.
silverstripe-omnipay makes use of php namespaces for many of its files, it just so happens that ServiceFactory is one of them so in order for SilverStripe to find the correct file to include you must specify its use at the top of files you intend to use ServiceFactory.
<?php
use SilverStripe\Omnipay\Service\ServiceFactory;
...
It is not entirely obvious because modules made for SilverStripe rarely make use of namespaces fo and silverstripe-omnipay makes no mention that ServiceFactory is namespaced in its examples.
What errors do you get? and how are you trying to access the classes?
You should be able to call the classes like this (depending on the Omnipay version)
<?php
use Omnipay\Omnipay;
class PaymentPage extends Page
{
function ...
{
try {
$response = $gateway->purchase([...
}
}

TYPO3 Composer dependency conflict

I'll be brief:
I have a TYPO3 with composer installed.
Let us have a look at the require part from TYPO3.
"require": {
"php": ">=5.5.0",
"ext-fileinfo": "*",
"ext-json": "*",
"ext-pcre": "*",
"ext-session": "*",
"ext-xml": "*",
"psr/log": "1.0.*#dev",
"pear/http_request2": "~2.2.1",
"swiftmailer/swiftmailer": "~5.4.1",
"symfony/console": "~2.7.0",
"symfony/finder": "~2.7.0",
"doctrine/instantiator": "~1.0.4",
"typo3/class-alias-loader": "^1.0",
"typo3/cms-composer-installers": "^1.2.8",
"psr/http-message": "~1.0",
"cogpowered/finediff": "~0.3.1",
"mso/idna-convert": "^0.9.1"
}
As you can see TYPO3 needs "symfony/console": "~2.7.0" so that means: (>=2.7 <= 2.8)
Next to it I run a CakePHP with the migrations plugin for the custom CakePHP Part.
Let's have a look at the require part from the database migration plugin as well:
"require": {
"php": ">=5.4",
"robmorgan/phinx": "0.5.3",
"cakephp/cakephp": "~3.1"
},
Nothing wrong here on the first look, but let us go in detail and have a closer look at "robmorgan/phinx": "0.5.3". This Plugin needs the following packages, and again let's have a closer look at the composer.json from "phinx".
"require": {
"php": ">=5.4",
"symfony/console": "~2.8|~3.0",
"symfony/config": "~2.8|~3.0",
"symfony/yaml": "~2.8|~3.0"
}
And now as you can see this package needs "symfony/console" at least in 2.8, but it doesn't work because TYPO3 needs it in "~2.7.0" that means: (>=2.7 <= 2.8).
I figured out the issue, but I have no idea how to solve it. I only have one solution but it is not that great, it's forking TYPO3 and editing the composer.json. But that is the very last option.
Does anyone else have a good approach on how to fix this?
You can use version 8.x of TYPO3. This version uses as requirement "symfony/console": ">=2.7 <3.1",which looks absolutly fine then.
8.x is very stable, you can use doctrine all over the place and it is the future.

use PHPExcel with composer and Symfony2.2

I found this on SO: How to use PHPExcel correctly with Symfony 2
This works, but I want to use it with composer.
The first part I already solved: to load PHPExcel for a special tag (the last stable release)
I don't find out how to fetch a tag with this syntax:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/umpirsky/SyliusAssortmentBundle"
}
]
So I use the Package notation:
I found out, the reference should be the tag name on github.
And the version cannot be the same value (PHPExcel_1.7.8). Seems that alphabetical characters are not allowed, so it's only the version as a number (1.7.8)
"repositories": [{
"type": "package",
"package": {
"name": "PHPOffice/PHPExcel",
"version": "1.7.8",
"source": {
"url": "https://github.com/PHPOffice/PHPExcel.git",
"type": "git",
"reference": "PHPExcel_1.7.8"
}
}
}]
The next step I didn't solve. I tried out every combination for the autoloading: psr-0, classmap, different paths, relative to project/vendor/phpexcel, update composer everytime, but nothing worked.
It only works, if I put this line
$loader->add('PHPExcel', __DIR__.'/../vendor/PHPOffice/PHPExcel/Classes');
into the app/autoload.php. I found out, that the first string (PHPExcel) can also be an empty string: ''.
Is there a differnece if I use PHPExcel or ''?
So my primary question is, how can I avoid to write this line into the autoload.php, put the equivalent commands into my project's composer.json?
Regarding your primary question, the problem is that once the package is installed, if you update the definition and add autoload stuff, then running composer update will not change anything. Composer still has the old package that was already installed in its "cache", so it uses that to generate the autoload and that fails.
To resolve this you should remove the vendor/PHPOffice/PHPExcel directly and run composer update, which will reinstall it with the latest information from your composer.json, including autoload, etc. You should specify autoloading as such:
"repositories": [{
"type": "package",
"package": {
"name": "PHPOffice/PHPExcel",
"version": "1.8.0",
"source": {
"url": "https://github.com/PHPOffice/PHPExcel.git",
"type": "git",
"reference": "1.8.0"
},
"autoload": {
"psr-0": {
"PHPExcel": "Classes/"
}
}
}
}],
"require": {
"PHPOffice/PHPExcel": "1.8.*",
...
Regarding the secondary question and '' vs 'PHPExcel': '' just says that any namespace can be found in this directory. That means the autoloader will always scan this directory to find classes, which is convenient but slower than mapping namespaces to directories explicitly. So both work, but the more specific form is preferred, especially in packages you publish publicly.

Wrap PHPWord on bundle

I just want to use PHPWord for Symfony 2. But Im new on Symfony 2.
I paste PHPWord source into my util folder bundle but there is an error loading autoloader class from PHPWord...
Question is simple, How can I "wrap" code (in this case PHPWord) in to bundle? or someway I can use it.
Any solution?
Thanks for answering, that gives me some light. Altough, This doen't work for me.
I download composer.phar and I edit my composer.json as you say: adding in my require region "phpword/phpword": "0.6.2" and creating new repository phpword...
Doesn't work, I run "php composer.phar" command but It doesn't download anything...
Any tutorial or tip to make this work?
Thank you
composer require phpoffice/phpword dev-master did the work for me.
It should download and place install PhpOffice\PHPWord under the vendor folder in your Symfony2 installation (besides modifying your composer.json automatically).
In the controller you are about to use PhpWord:
use PhpOffice\PhpWord\PhpWord;
And inside the action, you can create a new instance as follows:
$doc = new PhpWord();
You shouldn't be copying the source code yourself. Use composer to install PHPWord.
Since PHPWord doesn't use composer (yet), you'll need to define a repository in your composer.json:
{
"require": {
"phpword/phpword": "0.6.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "0.6.2",
"dist": {
"url": "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=phpword&DownloadId=138035&FileTime=129545976016270000&Build=19692",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
Than you'll be able to use PHPWord in your Symfony project (any PHP project in fact):
$word = new PHPWord();
$writer = new PHPWord_Writer_Word2007($word);
$writer->save('test.doc');
Update: I just realized the URL to download changes with time. It'd be better to replace it with something that doesn't change (if possible, otherwise host it somewhere yourself).
As the URL changes, you can use the github repository if you've no problem with the dev version :
{
"require": {
"phpword/phpword": "dev"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "dev",
"dist": {
"url": "https://github.com/PHPOffice/PHPWord/archive/develop.zip",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
You can use this simple bundle as wrapper for PhpWord:
https://packagist.org/packages/ggggino/wordbundle

mopabootstrap bundle and symfony2 issue

I am using this mopabootstrap bundle, followed all of the instructions. I am getting the following error:
An exception has been thrown during the compilation of a template ("Unable to find file "#MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-transition.js".") in "MopaBootstrapBundle::base.html.twig".
I found the thread here that seems to have an answer to my issue as well, but i tried it and it still gives me the same error. How can I fix this?
If you are using the latest version of MopaBootstrap, and Symfony 2.1 or 2.2, it seems that the twitter/bootstrap files aren't correctly installed and symlinked.
Maybe you have missed the composer.json part:
{
"scripts": {
"post-install-cmd": [
"Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap"
],
"post-update-cmd": [
"Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap"
]
}
}
from the MopaBootstrap doc
Those commands create the symlink from the vendors folder: /vendor/twitter/bootstrap
to the MopaBootstrap folder:
/vendor/mopa/bootstrap-bundle/Mopa/BootstrapBundle/Resources/bootstrap
Be sure to also install twitter/bootstrap in your composer.json:
{
"require": {
"mopa/bootstrap-bundle": "dev-master",
"twitter/bootstrap": "dev-master"
}
}

Resources