Symfony2 using third party vendors inside a bundle - symfony

I am creating a CpanelBundle which will integrate the Cpanel xmlapi into Symfony.
I will use the class provided by CpanelInc here: https://github.com/CpanelInc/xmlapi-php.
I want to make this bundle usable across projects and also open source.
The Symfony documentation says you should not put third party libraries into your bundles. The Cpanel class also don't have a namespace and its not on composer.
I could and should put the Cpanel class in vendor folder but how can I add it to autoload and to my bundle composer.json so when I release my bundle the user will also get it?

Hello you can load this file using composer. Please see composer autoload documentation
Your composer.json can looks like:
{
"name": "my/bundle",
"autoload": {
"psr-0": {"": "src"}
},
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.1,<2.3-dev",
"CpanelInc/xmlapi-php": "*"
},
"repositories": [
{
"type": "package",
"package": {
"name": "CpanelInc/xmlapi-php",
"version": "master-dev",
"dist": {
"url": "http://github.com/CpanelInc/xmlapi-php/zipball/master",
"type": "zip"
},
"source": {
"url": "git://github.com/CpanelInc/xmlapi-php.git",
"type": "git",
"reference": "master"
},
"autoload": {
"files" : ['xmlapi.php']
}
}
}
]
}
Will be even better when you just create composer.json and add it for CpanelInc/xmlapi-php and do PR :)

Related

Webpack bundle repository not found

I have in my composer.json :
"symfony/webpack-encore-pack": "*",
In composer.lock :
{
"name": "symfony/webpack-encore-pack",
"version": "v1.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/webpack-encore-pack.git",
"reference": "8d7f51379d7ae17aea7cf501d910a11896895ac4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/webpack-encore-pack/zipball/8d7f51379d7ae17aea7cf501d910a11896895ac4",
"reference": "8d7f51379d7ae17aea7cf501d910a11896895ac4",
"shasum": ""
},
"require": {
"symfony/asset": "^3.3|^4.0"
},
"type": "symfony-pack",
"extra": {
"thanks": {
"name": "symfony/webpack-encore",
"url": "https://github.com/symfony/webpack-encore"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A pack for Symfony Encore",
"abandoned": "symfony/webpack-encore-bundle",
"time": "2018-07-16T10:15:28+00:00"
},
When I try composer install I have the error : Installing symfony/webpack-encore-pack (v1.0.3): Downloading Failed to download symfony/webpack-encore-pack from dist: The "https://api.github.com/repos/symfony/webpack-encore-pack/zipball/8d7f51379d7ae17aea7cf501d910a11896895ac4" file could not be downloaded (HTTP/1.1 404 Not Found).
I checked this URL and the file didn't exist. How can I solve this issue?
symfony/webpack-encore-pack has seen its last update more than three years ago and is abandoned. The code is no longer present on Github, so it cannot be downloaded from the location that is stored in your composer.lock (that's what https://api.github.com/repos/symfony/webpack-encore-pack/zipball/8d7f51379d7ae17aea7cf501d910a11896895ac4 does: it links to the URL of a zipped version of that package in a specific version).
According to a discussion about this, you should use symfony/webpack-encore-bundle instead. Sadly, this package is not compatible with Symfony 3.3 in any version, so you might need to update it to v3.4

How to solve this error in the name property of composer.json validation?

I got this error as i validate my composer.json file:
[Composer\Json\JsonValidationException]
"./composer.json" does not match the expected JSON schema:
- name : Does not match the regex pattern ^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$
The name Property looks like this:
"name":"lukas735/united-in-faith",
I also tried out the following alternations:
"lukas735/united-in-faith",
"lukas/united-in-faith",
"lukas735/united.in.faith",
"lukas/united.in.faith",
"lukas735/united_in_faith",
"lukas/united_in_faith",
"lukas/uif",
"lukas735/uif",
None of this worked... The regex proofer said the forward slash is placed wrong... But its composer intern so i can't change anything on that. And anyway. My strings also not got matched if i corrected that in regex proofer.
Is there anyway to let match my united-in-faith String... The name before was just an account name because a video said this vendor-name can be choosed yourself... But video was from 2016. I found no hints in internet where to find the vendor-name. So i choosed it myself.
I saw some videos and topics about this naming convention, but they all not seemed to giving an answer which solved it.
What did I wrong?
Has anybody a solution for this error?
Here is my Composer.json File:
{
"name":"lukas735/united-in-faith",
"description":"description",
"keywords": [
"united-in-faith",
"united in faith",
"united_in_faith",
"dating"
],
"homepage": "https://...",
"license": "MIT",
"authors": [
{
"name": "...",
"email": "....",
"homepage": "...",
"role": "Developer"
}
],
"repositories":[
{
"type": "package",
"package": {
"name": "lukas735/united-in-faith",
"version": "1.0.0",
"source": {
"url": "https://github.com/...",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"components/jqueryui": "^1.12",
"united-in-faith": "dev-master"
},
"autoload": {
"psr-4": {
"lukas735\\": "sites/classes"
}
},
"recommend":{
"ext-zip":"*"
},
"bin":["bin"],
"config":{
"vendor-dir":"vendor"
},
"scripts": {
"test": "phpspec run",
"format": "phpcbf --standard=psr2 src/"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}
use command 'composer init' to make a new composer.json file, use old for reference

Upgrade Twig 1.x.x to Twig 3.x.x

I'm trying to upgrade Twig 1.13.2-DEV to 3.x but don't know how to do that as on their
Website not clearly mentioned and they suggest to ask question on StackOverflow :)
I used Twig only with Symfony framework not with Custom PHP website, Right now I can see two directories in server
Twig
Twig-extensions
And inside /Twig/lib/Twig/Environment.php it display me the version
const VERSION = '1.13.2-DEV';
Can someone have idea how to upgrade Twig?
My project is not using composer.json but inside Twig folder I have this compsoer.json
"name": "twig/twig",
"type": "library",
"description": "Twig, the flexible, fast, and secure template language for PHP",
"keywords": ["templating"],
"homepage": "http://twig.sensiolabs.org",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien#symfony.com"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher#active-4.com"
}
],
"require": {
"php": ">=5.2.4"
},
"autoload": {
"psr-0" : {
"Twig_" : "lib/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.13-dev"
}
}
}

Create a 3rd part bundle and share it between projects

I made a tiny bundle that saves a lot of time when you want to create a restfull api on symfony2 using FosRestBundle and jmsSerializer.
I would like to share this bundle in my projects, but when i add it to its destination, composers returns "Your requirements could not be resolved to an installable set of packages."
I guess i made something wrong but can not find out what
I created a repo on git ( https://github.com/LeniM/apiGenericBundle )
Added the composer.json :
{
"name": "lenim/api-generic-bundle",
"type": "symfony-bundle",
"description": "Rest Api creation helper",
"keywords": ["Api", "RestApi"],
"homepage": "http://friendsofsymfony.github.com",
"license": "MIT",
"minimum-stability" : "dev",
"target-dir": "LeniM/ApiGenericBundle",
"authors": [
{
"name": "Martin Leni",
"role" : "Developer"
}
],
"require": {
"php": ">=5.3.3",
"symfony/framework-bundle": "~2.3|~3.0",
"doctrine/orm": "^2.5",
"friendsofsymfony/rest-bundle": "^1.7",
"jms/serializer-bundle": "^1.1"
},
"require-dev": {
"symfony/console": "~2.3|~3.0",
"symfony/phpunit-bridge": "~2.7|~3.0",
"symfony/validator": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0",
"willdurand/propel-typehintable-behavior": "~1.0"
},
"suggest": {
"nelmio/NelmioApiDocBundle": "More than recommanded to keep your api well documentated"
},
"autoload": {
"psr-4": { "LeniM\\ApiGenericBundle\\": "" }
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"support": {
"docs": "https://github.com/LeniM/apiGenericBundle/readme.md"
}
}
required it with its name : lenim/api-generic-bundle
Is there something else to do to register your thrid part bundle to composer ?
Thanks :)
You have to either publish this package on packagist.org or specify target repository path in particular project's composer.json file: https://getcomposer.org/doc/05-repositories.md#vcs

Symfony external library - Payone

Has anybody ever used Symfony in conjunction with payone(payone.de)?
I got the SDK and it has the folders js, locale and php.
My problem: I don't really know how to include/use them in my project(inexperienced in Symfony) because I don't know where I should place it and how to include it. I read about the auto loader but since the SDK doesn't follow the standards needed(concerning folder structure) I guess it's not the way to go.
You can autoload all classes with the psr-0 too if the classes are following the PEAR-style non-namespaced convention.
To manage the vendor download via composer, you can define a package in your composer.json directly.
{
"repositories": [
{
"type": "package",
"package": {
"name": "payone/php-sdk",
"version": "1.0.0",
"dist": {
"url": "http://github.com/PAYONE/PHP-SDK/archive/master.zip",
"type": "zip"
},
"autoload": {
"psr-0": { "Payone_": "php/" }
}
}
}
],
"require": {
"payone/php-sdk": "1.0.*"
}
}
Note: This repository type has a few limitations and should be avoided whenever possible:
Composer will not update the package unless you change the version field.

Resources