Missing Classes from Silverstripe Omnipay - silverstripe

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([...
}
}

Related

Including a Symfony bundle from a subtree : how to expand autoload path?

I'm using a bundle from a subtree, so I can't modify the structure nor the placement of it. I currently am trying to get it included in autoloading process, and am failing miserably with the "class not found" error message.
Currently, my project tree (made with Symfony 3.2) is :
|- app
|- src
|- MyappBundle
|- external
|- Author
|-UserBundle
|- Controller
|- [...]
|- AuthorUserBundle.php
AuthorUserBundle.php contains :
namespace Author\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AuthorUserBundle extends Bundle
{
}
To include this bundle, I added in app/AppKernel.php :
new Author\UserBundle\AuthorUserBundle(),
I also added to app/autoload.php, before AnnotationRegistry::registerLoader :
$loader->add('Author',__DIR__.'/../src/external');
I don't master the namespaces imbrications, especially regarding the depth of call, but I tried many variations in autoload.php (like '/../src/external/Author') or AppKernel.php (Author\UserBundle\AuthorUserBundle\AuthorUserBundle()) ending all with the same error message "Class not found".
What did I miss ?
Sorry for the newbie question, I tried alone first, thank you for your time.
P.S. : the external directory can't be removed, the git subtree process doesn't allow to operate in a non empty directory.
You shouldn't use git subtree to include 3rd party code. Add a composer.json to your AuthorUserBundle with all needed autoloading and dependencies. A minimal example (replace ^3.0 with ^2.7 if you still use Symfony 2.7/2.8):
{
"name": "author/user-bundle",
"license": "proprietary",
"type": "library",
"require": {
"symfony/framework-bundle": "^3.0"
},
"autoload": {
"psr-4": {
"Author\\UserBundle\\": ""
},
}
}
And require it in your main project as private repository. Please add git tags to and follow semantic versioning.
Assuming your bundle is then called author/user-bundle (composer name), add the following to your projects composer.json:
{
"require": {
"author/user-bundle": "^1.0"
},
"repositories": [
{
"type": "vcs",
"url": "git#git.example.author/user-bundle.git"
}
]
}
Edit 1: added composer.json for AuthorUserBundle repository.
I would give a try to addPsr4 method instead
$loader->addPsr4('Author\\UserBundle\\', __DIR__.'/../src/external/Author/UserBundle');

is it possible to use PHpspec with behat?, or just PhPunit with behat? (Symfony)

I'm playing a little with Behat these days, the thing is that I don't know if I can use PHPspec with Behat to "assert" all the stuff, this one is so readable that I would like to use it. In my case I'm using Symfony.
If not, how can I use Asserts from PHPunit in Behat. I couldn't for now, I installed PHPUnit with composer, but in the Behat Documentation they require a file, but the scenario is lightly different (they didn't installed it by using composer, is not in Vendor directory)
URL from DOC: http://docs.behat.org/quick_intro.html#more-about-features
, the require_once is little elegant.
Any idea?, any answer?, thanks!
You can bring phpspec's matchers to behat with the expect helper.
Few examples of use:
// matches if $something === 'something'
expect($something)->toBe('something');
// matches if $article->isActive() returns true
expect($article)->toBeActive();
// matches if $article->hasComments() returns false
expect($article)->notToHaveComments();
You most certainly can use Bahat with PHPUnit. I didn't try with PHPSpec, but I'm certain it's possible if you can access the logic that performs assertions. Typically any test framework would expose that logic for the "outside users".
/**
* #Then /^the magic should happen$/
*/
public function assertUnicornsExist()
{
// Make standard assertions through static calls…
PHPUnit_Framework_TestCase::assertTrue(true);
}
Not sure I get the full picture with regards to installation, but if you're using composer you can simply configure the "autoload" part to include your sources and contexts (if they are separate). Mine works pretty much out of the box:
{
"require": {
"behat/behat": "dev-master",
"behat/mink": "dev-master",
"behat/mink-extension": "dev-master",
"behat/mink-browserkit-driver": "dev-master",
"behat/mink-goutte-driver": "dev-master",
"phpunit/dbunit": "*"
},
"autoload": {
"psr-0": {
"": "src/"
}
}
}
Then you just include the vendor/autoload.php. I recommend adding in a bootstrap that would run once using the #BeforeSuite hook.
/**
* #BeforeSuite
*/
public static function setUpSuite(BeforeSuiteScope $scope)
{
// if not bootstrapped already, then include bootstrap with init'ing the autoloader, etc…
}
Also, if you're starting off with Behat 3 – the docs are not there yet, use http://behat.readthedocs.org/en/latest/. They contain the latest essentials and some decent examples.
Of course it's possible. You can use behat to describe how something should behave and phpspec for more detailed things. Good example is here: http://code.tutsplus.com/tutorials/a-bdd-workflow-with-behat-and-phpspec--cms-21601

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