I've been using Silex for a while now without any issues. I've been able to add new services, create basic sites, etc. Unfortunately I'm stuck now on creating a new service from scratch... I'm not too sure what I'm doing wrong and I figured a nudge in the right direction would be useful right about now.
I have a basic structure like this:
cache
resources
src
-app.php
-autoload.php
-config.php
-controllers.php
-etc
vendor
-assetic
-Company
-src
-Postback.php <-- The classes I need to load
-silex
-etc
views
web
So, in app.php
:
use SilexExtension\CompanyPostbackServiceProvider;
$app->register(new CompanyPostbackServiceProvider(), array(
'company.class_path' => __DIR__ . '/../vendor/Company/src'
));
in src/autoload.php
:
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/silex/vendor', __DIR__.'/../vendor'),
'Silex' => __DIR__.'/../vendor/silex/src',
'SilexExtension' => __DIR__.'/../vendor/Silex-extentions/src',
'Assetic' => __DIR__.'/../vendor/assetic/src',
'Company' => __DIR__.'/../vendor/Company/src'
));
in silex/vendor/Silex-extensions/src/SilexExtension/CompanyPostbackServiceProvider.php
:
namespace SilexExtension;
use Silex\Application;
use Silex\ServiceProviderInterface;
class CompanyPostbackServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
if ( isset( $app['company.class_path'] ) )
{
$app['autoloader']->registerNamespace(
'Company', $app['company.class_path']
);
}
}
}
I've tried several variations of this, but calling Postback from controller.php results in no classes being found, and declaring the class methods of CompanyPostbackServiceProvider results in just the register function which belongs to Silex\Application.
Any ideas? I know I'm doing something stupid, but for some reason it just isn't clicking.
Thanks!