The correct way to use external libraries without PSR-0 in a Symfony2 project

I am working on an application that will connect to the Intuit Quickbooks API through their REST PHP SDK. In basic PHP, everything works for me without problems, since I upload files as follows:

require_once('../api/config.php');  // Default V3 PHP SDK (v2.0.1) from IPP
require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
require_once(PATH_SDK_ROOT . 'DataService/DataService.php');
require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');

Now I need to use the libraries in the Symfony2 controller from the Bundle, and from here comes my doubt, how can I achieve this easily? I read a lot of documents link1 , Component loader Symfony Class and some others, but even this is completely incomprehensible to me. At the moment, I created this structure in my folder /vendor, as shown in the figure:

vendor structure

The file config.phpthat your can see there has this code:

/**
 * This file allows custom configuration of paths for XSD2PHP dependencies and
 * POPO classes.  Rarely necessary, but possible.
 *
 * @author Intuit Partner Platform Team
 * @version 1.0
 */

// Determine parent path for SDK
$sdkDir = __DIR__ . DIRECTORY_SEPARATOR;

if (!defined('PATH_SDK_ROOT'))
    define('PATH_SDK_ROOT', $sdkDir);

// Specify POPO class path; typically a direct child of the SDK path
if (!defined('POPO_CLASS_PATH'))
    define('POPO_CLASS_PATH', $sdkDir . 'Data');

// Include XSD2PHP dependencies for marshalling and unmarshalling
use com\mikebevz\xsd2php;
require_once(PATH_SDK_ROOT . 'Dependencies/XSD2PHP/src/com/mikebevz/xsd2php/Php2Xml.php');
require_once(PATH_SDK_ROOT . 'Dependencies/XSD2PHP/src/com/mikebevz/xsd2php/Bind.php');

// Includes all POPO classes; these are the source, dest, or both of the marshalling
set_include_path(get_include_path() . PATH_SEPARATOR . POPO_CLASS_PATH);
foreach (glob(POPO_CLASS_PATH.'/*.php') as $filename)
    require_once($filename);

// Specify the prefix pre-pended to POPO class names.  If you modify this value, you
// also need to rebuild the POPO classes, with the same prefix
if (!defined('PHP_CLASS_PREFIX'))
    define('PHP_CLASS_PREFIX',    'IPP');

, , , QBO PHP SDK, :

  • , Symfony2, ..?
  • PSR-0, Symfony Loader Component ?
  • - , ?
+4
1

Symfony Composer. , SDK , Composer .

composer.json. .

classmap composer.json autoload:

"autoload": {
    "classmap": ['src/'],
},

Composer src/ . , - .

, - PSR0, .

PSR0-ify , , namespace use . , , SDK.

autoload composer.json, :

"autoload": {
    "psr-0": {
        "QBO\\": "src/"
    }
},

API consolibyte/quickbooks-php ... .

+4

Source: https://habr.com/ru/post/1543230/


All Articles