Symfony2/Composer use package - symfony

I'm trying to use the payone PHP-SDK from http://github.com/PAYONE/PHP-SDK/archive/master.zip
I included it in my composer.json like this:
"require": {
"payone/php-sdk": "1.0.*"
},
"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/" }
}
}
}
]
My question: How do I use it in my controller?

Please note the PayOne SDK uses PEAR style classnames ( i.e. Vendor_Folder_Classname ) and not the PSR-0 convention with namespaces. pear style autoloading is compatible with composer's psr-0 autoloading.
Make sure you prefix the classnames with \ or add a use statement on top of your controller class.
See igor's answer here.
To instantiate a new builder object use something like:
class MyController
{
public function myAction()
{
$conig = new \PayOne_Config(array(/* settings */));
$builder = new \PayOne_Builder($config);
// now use the builder
}
The PayOne_Autoload and PayOne_Bootstrap classes are only needed for setting up autoloading which is in your case handlded by composer.

Related

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"
}
}
}

How to override bower_component main property on bower install?

I'm using a grunt plugin called bower-concat. This plugin takes all your bower_component packages and concatenates them into a single file. It does this by looking at each component's bower.json file's "main" attribute. I'd like to modify my font-awesome's bower.json "main" attribute from
{
"name": "font-awesome",
"description": "Font Awesome",
...,
"main": [
"less/font-awesome.less",
"scss/font-awesome.scss"
]
...
}
to this, which allows my grunt-bower-concat plugin to work.
{
"name": "font-awesome",
"description": "Font Awesome",
...,
"main": [
"./css/font-awesome.css",
"./fonts/*"
]
...
}
By following this post here (https://roots.io/using-bootstrap-with-bower-how-to-override-bower-packages/), I thought I'd be able to override this attribute like so in my app's bower.json file to achieve the desired result upon bower install ...
{
"name": "MyApp"
"dependencies": {
"font-awesome": "~4.4.0"
},
"overrides": {
"font-awesome": {
"main": [
"./css/font-awesome.css",
"./fonts/*"
]
}
}
}
Unfortunately, this doesn't appear to override font-awesome's "main" attribute. Can anyone point out what I'm missing?

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.

Symfony2 using third party vendors inside a bundle

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 :)

How do I correctly declare a Dependency to another Bundle within a Bundle?

I am trying to use a Bundle inside a Bundle but somehow it is failig.
"repositories": [
{
"type": "vcs",
"url": "https://github.com/myname/mybundle"
}
],
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
(...)
"myname/mybundle": "*"
},
this seems to work so far. But I can't figure out how to declare another dependency within "myname/mybundle".
I tried the following in the composer.json file of myname/mybundle but none of them worked :(
"repositories": [
{
"type": "vcs",
"url": "url": "https://github.com/drymek/PheanstalkBundle"
}
],
"require": {
(...)
"drymek/PheanstalkBundle": "dev-master"
}
and
"repositories": [
{
"type": "package",
"package": {
"name": "drymek/PheanstalkBundle",
"version": "dev-master",
"source": {
"url": "https://github.com/drymek/PheanstalkBundle.git",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
(...)
"drymek/PheanstalkBundle": "dev-master"
}
when I rum composer.phar update all i get is
- myname/mybundle dev-master requires drymek/pheanstalkbundle dev-master -> no matching package found.
Okay I've found an answer here
It states: Repositories are not resolved recursively. You can only add them to your main composer.json. Repository declarations of dependencies' composer.jsons are ignored.
That's too bad... but now at least I know where to put my dependeny (in the root composer.json file)
For bundle dependencies, please see my library https://github.com/AshleyDawson/MultiBundle. As an example, extend the MultiBundle and implement the getBundles() method, like so:
<?php
namespace Acme\MyBundle;
use AshleyDawson\MultiBundle\AbstractMultiBundle;
class AcmeMyBundle extends AbstractMultiBundle
{
/**
* Optional: define a protected constructor to stop instantiation outside of registerInto()
*/
protected function __construct()
{
}
/**
* Define bundles that this bundle depends on
*/
protected static function getBundles()
{
return array(
new Acme\FooBundle\AcmeFooBundle(),
new Acme\BarBundle\AcmeBarBundle(),
);
}
}
And then in the AppKernel register the bundle and it's dependencies:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...,
);
// Register my bundle and its dependencies
\Acme\MyBundle\AcmeMyBundle::registerInto($bundles);
// ...
}
}

Resources