Using pre existing library in Symfony - php

I am new to Symfony. I am trying to use a pre existing library that I have used for my Payment Gateway API, with Symfony (v2.3).
Before using Symfony I would have a composer.json file in the root directory and I would simply use PHP require 'vendor/Braintree.... However with Symfony I am having a really difficult time using the library for payment gateway API by importing it to my Controller.
Note: I am using an Entity in the same controller as follows, which has a similar directory structure and works great:
use Jets\JetsBundle\Entity\Company;
This is what I tried to use the payment gateway API:
use Jets\JetsBundle\Braintree\braintree\braintree_php\lib\Braintree;
and the Braintree.php contains:
namespace Widb\WidbBundle\Braintree\braintree\braintree_php\lib;
I keep getting the following error:
FatalErrorException: Error: Class 'Jets\JetsBundle\Controller\Braintree_Configuration' not found in C:\xampp\htdocs\www\symfony\src\Jets\JetsBundle\Controller\DefaultController.php line 239
And the DefaultController.php Line 239 contains:
Braintree_Configuration::environment('sandbox');
As a side note, I didn't do anything other than drag / drop the ready configured library directory from my old server to the Symfony directory on the new server. Am I missing some configuration script or cmd set up or something?
I appreciate any assistance in this regard. I will forever be grateful is someone can help me troubleshoot this.
Here is my DefaultController.php code:
http://pastebin.com/kwisEBzL
Many thanks in advance!

This Braintree project seems to be PSR-0, so you should be able to use it pretty easily.
Don't do this:
use Jets\JetsBundle\Braintree\braintree\braintree_php\lib\Braintree;
There is no such namespace.
Include the Braintree project using Composer (notice they have the PSR-0 autoloading config already: https://github.com/braintree/braintree_php/blob/master/composer.json).
EDIT: add this to your composer.json and don't forget to run composer update (or php composer.phar update)
Update 2: As pointed out in the comments, it is a good idea to use a stable tag/branch. That way, if there are breaking changes, you can make sure to fix them before updating. So always check the version of the library (2.23 may not be the latest version any more).
"require": {
...
"braintree/braintree_php": "~2.23"
},
The autoloader should pickup all of the classes if you use the global namespace (notice the leading slash):
\Braintree_Configuration::environment('sandbox');
Let me know if this works.
Side note, you should probably create a bundle that does the configuration for you in a centralized place.

You really missed out one of the first comments.. which was spot on and will most likely take away alot of headaches.
Follow the instructions given at https://github.com/cometcult/CometCultBraintreeBundle, this is a bundle that provides "Braintree". A bundle in this case actually is a "module" you can hook in, and configure by configuration files.
Relevant commands that are missing for handling composer:
http://getcomposer.org/doc/03-cli.md#install
http://getcomposer.org/doc/03-cli.md#require
As soon as you have finished it up you should take a look at the bottom two parts, besides conifgurating everything.
$factory = $this->get('comet_cult_braintree.factory');
$customerService = $factory->get('customer');
If you need more help let me know

I'm don't uderstand what you actually try to do in your DefaultController.php, but I have some assumptions.
UPD:
FIRST and SECOND point was deleted.
THIRD:
When you trying to make use Jets\JetsBundle\Braintree\braintree\braintree_php\lib\Braintree; you have load only class Braintree from file Braintree.php. Not whole file with another data like require_once instructions.
FOURTH:
/vendor directory of Symfony2 projects usually contains third-part libs. So you can put your lib here.
Hope some of this points helps you.
P.S. Sorry for poor English.

Related

Phinx Class Not Found PHP

So I'm trying to set up Phinx a database migrations tool in Slim however, I'm having a little trouble getting the migration to work properly it keeps giving me this error Fatal error: Class 'App\Database\Migrations\Migration' not found in C:\Users\Hassan\Desktop\www\sites\hassanaljadooa\database\migrations\20170804115407_created_user_table.php on line 7 when ever I try to migrate.
I know it has to do with the Migrations class but I spell checked it multiple times I couldn't find any typos in class, and I'm quite frankly lost this error just shouldn't exist from my point of view.
To make life easy for anyone trying to help, here's the link to the bitbucket repo hosting my entire source code for this project https://hassanaljadooa#bitbucket.org/hassanaljadooa/hassanaljadooa.git just clone this repo and start looking.
The main files to look at are phinx.php in the root of the directory, app/database/migration.php, and the database/migrations folder.
side note:: im using psr-4 to load classes.
Thanks in advance.
Try to add the composer autoloader to phinx.php
<?php
require_once __DIR__ . '/vendor/autoload.php';

The google-api-php-client autoupload.php file is missing, anyone have a copy?

Here's the code, https://github.com/google/google-api-php-client/
Here's the file that's missing, https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php
I know it's possible to create this file with composer, but was just wondering if anyone has it available.
I'm also concerned that this alone might not make the software work, as I've tried to do it the manual way and the Class it can't reference is "GuzzleHttp\Collection" which is accessed in PHP with "use GuzzleHttp\Collection". I don't know how adding "autoload.php" will help referencing a file that's not part of the "google-api-php-client".
Does anyone actually have this software working in PHP, it says Beta?
I found it using Google Cache,
http://webcache.googleusercontent.com/search?q=cache:992oyuQ76a0J:https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php+&cd=1&hl=en&ct=clnk&gl=us
This file should be load from vendor directory
// include your composer dependencies
require_once 'vendor/autoload.php';

registering Bundle to symfony kernel

Instead of Using composer I download zip file of a bundle and extract this bundle to my symfony project. I change all relative address for example I change all namespace Trsteel\CkeditorBundle; to namespace Acme\TrsteelCkeditorBundle; for doing this I searched the downloaded directory for every Trsteel\CkeditorBundle and change all of them to Acme\TrsteelCkeditorBundle now when I want to use this Bundle on my project I register this bundle to my appKernel.php of symfony project But I reached this error
Error: Class 'Acme\TrsteelCkeditorBundle\TrsteelCkeditorBundle' not found in /Users/kingkong/Documents/workspace/dev/Project/SRC/app/AppKernel.php line 45
File names should be the same as namespace structure, capitalization may be an issue, so check that.
You may want to place the bundle in this way - "Acme\Trsteel\CkeditorBundle\CkeditorBundle"
Check whether you have actually changed the folder structure from Trsteel\CkeditorBundle to Acme\TrsteelCkeditorBundle. And also check your routing files as well. (I assume you have done the routing part as the error won't say that it can't get to that location.)
Cheers!

Symfony: getting Class not found error

I am trying to learn Symfony 2. I'm trying to follow the example in the Symfony book (Page 17). I have downloaded and unpacked Symfony in my working directory.
The absolute path to the file I'm trying to use is in: symfony\vendor\symfony\symfony\src\Symfony\Component\HttpFoundation\Request.php
However following the books example closely, I just put:
use Symfony\Component\HttpFoundation\Request
Either way, both these approaches did not work for me.
Using the books approach I'm getting the following error:
Fatal error: Class 'Symfony\Component\HttpFoundation\Request' not found in C:/...
Using my approach with the longer path, I'm still getting this error, when I use include to navigate to the long path, the file is found but I'm getting some other error (just wanted to verify I'm able to get to the file, which I am).
I appreciate any advice in overcoming this problem. Many thanks in advance!
in PHP use statement requires Fully Qualified Class Name, not directory. So use Symfony\Component\HttpFoundation\Request is just fine.
If you decided to try these "examples" you will have to require autoload.php file first. It is located in your vendors directory.
So if you make file named "myfile" in symfony web folder it should start like this:
<?php
require '../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
Run - > composer update
Run the Path -> ./vendor/bin/upgrade-carbon
Then Will fixed this issue in laravel

Modular Zend Framework app & Doctrine integration and usage

I need help, cause I am little stuck on this.
I have set up a modular Zend Framework app. Also using -- https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD- -- i integrated Doctrine 2.
My directory structure is like this:
-aplication/
--default/ --module1
---config
---controllers/
---forms/
---models/
---templates/
---test/
--maintenance --module2
---config
---controllers/
---forms/
---models/
---templates/
---test/
-config
--Bootstrap.php
--aplication.ini
-library/
--Zend/
--Doctrine/
--doctrine.php
--cli-config.php
-sites/
--site1/
---index.php
I have my databse created. I will use some tools to generate YAML files from database.
The next step I want is to generate model classes from these YAML files.
I spend days searching, but I just coudn't find solution to generate classes to models folder of each module. OK, so I would solve the problem by generating these classes in one directory and then move it to their 'original' destination (models folders).
I need help on how to generate these classes. I am developing in Windows, and that is where I want to generate this.
I suppose I have to open cms, point to location of doctrine.php (in library folder) and enter command php doctrine.php + some arguments. But when I do that i have:
[InvalidArgumentException]
There are no commands defined in the "" namespace.
What am I missing? What am I doing wrong?
I will also try to contact author of these files https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD- to ask for explanation.
Thanks in advance. I would really appreciate your help.
If you need I can write some of my code from Bootstrap and application.ini if you need.
Try to generate the class from YML file .It is possible to use MySQL workbench to sync the database tables and then use the MySQL workbench YML file generator plugin to generate the YML files . Hope it helps.

Categories