Как включить или автоматически загрузить внешние библиотеки в расширение TYPO3 Extbase? + Инъекция зависимости?

Я разрабатываю расширение TYPO3 4.6 с Extbase 1.4 и пытаюсь включить внешнюю библиотеку. Библиотека, в моем случаеfacebook PHP SDKнаходится под$_EXTKEY/Resources/PHP/facebook-php-sdk/facebook.php, Я хотел бы, чтобы библиотека автоматически загружалась и автоматически вставляла (Dependecy Injection) там, где она мне нужна.

Некоторые комментарии, которые я нашел в Интернете, предполагают, что нужно включать библиотеки с require_once ():

http://forge.typo3.org/issues/33142

if it's just a tiny helper library, it's intended to be stored in {PackageRoot}/Resources/PHP/{libraryName} and just included via require. is this suspected by the problem however? if the FLOW3 package mainly represents the foreing library at all, like it's the case in Imagine or Swift package, the library code is put below {PackageRoot}/Classes directly."

http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2011-July/009946.html

"I would include the class (using require_once) from within a specific action to handle this. That way you have access over those functions and the class becomes your library."

Я попробовал это, и это работает так:

<?php
require_once( t3lib_extMgm::extPath('extkey') . 'Resources/PHP/facebook-php-sdk/facebook.php');

class Tx_WsLogin_Domain_Repository_FacebookUserRepository extends Tx_WsLogin_Domain_Repository_UserRepository {

protected $facebook;

public function __construct() {
    $this->setFacebook(new Facebook(array(
        'appId' =>'',
        'secret' => '')
    ));
    parent::__construct();
}

public function setFacebook(Facebook $facebook) {
    $this->facebook = $facebook;
}


public function sampleFunction() {
    $userId = $this->facebook->getUser();
}

}
?>

Но как я могу заставить его автоматически загружаться и автоматически вставлять библиотеку с помощью функции injectFacebook?

edit:

подобно@alex_schnitzler а также@sorenmalling упоминается об автозагрузке:

@PeterTheOne Put all the files inside ext_autoload.php and then use DI or the object manager.

@PeterTheOne put the class definition into ext_autoload.php in your extension?

Я попробовал это так (файл: ext_autoload.php):

<?php

$extPath = t3lib_extMgm::extPath('extKey');

return array(
    'facebook' => $extPath . 'Resources/PHP/facebook-php-sdk/facebook.php',
);

?>

Кажется, найти и включить правильный файл. Но когда я пытаюсь использовать Dependency Injection (например,Питер ответил) Я получаю ошибку:

not a correct info array of constructor dependencies was passed!

InvalidArgumentException thrown in file /var/syscp/webs/web1/dev/typo3_src-4.5.15/typo3/sysext/extbase/Classes/Object/Container/Container.php in line 247.

Я думаю, это потому, что конструктор класса Facebook имеет обязательный аргумент $ config.

edit2:

Я сделал то, что сказал Питер в своем ответе и с помощью@alex_schnitzler а также@sorenmalling, который указал мне на ObjectManager, мой FacebookService теперь выглядит так:

class Tx_Extkey_Service_FacebookService implements t3lib_Singleton {

/**
* @var Tx_Extbase_Object_ObjectManagerInterface
*/
protected $objectManager;

/**
 * Facebook from @link https://github.com/facebook/facebook-php-sdk facebook-php-sdk
 *
 * @var Facebook
 */
protected $facebook;

/**
* @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
*/
public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
    $this->objectManager = $objectManager;
}

/**
 * 
 */
public function initializeObject() {
    $this->facebook = $this->objectManager->create(
        'Facebook',
        array(
            'appId' =>'input appId here',
            'secret' => 'input app secret here'
        )
    );
}

/**
 * @return Facebook
 */
public function getFacebook() {
    return $this->facebook;
}

}

Для получения дополнительной помощи читайте:http://forge.typo3.org/projects/typo3v4-mvc/wiki/Dependency_Injection_(DI) части оinitializeObject() а такжеCreating Prototype Objects through the Object Manager

Ответы на вопрос(2)

Ваш ответ на вопрос