Exemplo n.º 1
0
Arquivo: index.php Projeto: 360i/sonno
// up and running.
use Sonno\Configuration\Driver\AnnotationDriver, Sonno\Annotation\Reader\DoctrineReader, Sonno\Application\Application, Sonno\Http\Request\Request, Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\AnnotationRegistry;
// Configure Doctrine's annotation reader. For more information see the
// following link:
// http://doctrine-project.org/docs/common/2.1/en/reference/annotations.html
$doctrineReader = new AnnotationReader();
AnnotationRegistry::registerAutoloadNamespace('Sonno\\Annotation', realpath(__DIR__ . '/../../../src'));
// Sonno ships with one Annotation reader adapter, and that supports Doctrine's
// Annotation reader. Sonno's adapter-based architecture allows for developers
// to write Annotation readers using any library. The
// Sonno\Annotation\Reader\ReaderInterface is provided so different readers can
// use different engines.
$annotationReader = new DoctrineReader($doctrineReader);
// An array of Resource classes must be provided so the AnnotationDriver knows
// where to find annotated resource classes.
$resources = array('Sonno\\Example\\Resource\\HelloResource');
// Sonno\Configuration\Configuration objects are retrieved through Configuration
// Drivers. A driver must implement the
// Sonno\Configuration\Driver\DriverInterface interface. Sonno ships with a
// driver that parses annotations, but future versions will ship with config
// drivers for XML, YAML, and anything else that may make sense.
$driver = new AnnotationDriver($resources, $annotationReader);
$config = $driver->parseConfig();
// It's also possible to set other config options, such as the base path.
// $config->setBasePath('/api/rest/v1');
// The application class requires a Sonno\Configuration\Configuration object
// to run. This object can be cached so annotations don't have to be read and
// parsed on every request. It's also not necessary that this config object
// is created using annotations.
$application = new Application($config);
$application->run(Request::getInstanceOfCurrentRequest());
Exemplo n.º 2
0
 /**
  * Test registering and then unregistering all response filter callbacks
  * for a specific status code, and ensure that they are not executed.
  *
  * @return void
  * @runInSeparateProcess
  */
 public function testUnregisterAllFilterCallbacks()
 {
     $config = $this->buildMockConfiguration(array(array('path' => '/test', 'httpMethod' => 'GET', 'resourceClassName' => 'Sonno\\Test\\Application\\Asset\\TestResource', 'resourceMethodName' => 'causeError', 'produces' => array('text/plain'), 'contexts' => array(), 'pathParams' => array(), 'queryParams' => array())), '/service/v1');
     $request = $this->buildMockRequest('GET', '/service/v1/nonexistent');
     $app = new Application($config);
     $app->registerResponseFilter(404, function ($request, $response) {
         /** @var $response \Sonno\Http\Response\Response */
         $response->setHeaders(array('Content-Type' => 'text/html'));
     });
     $app->registerResponseFilter(404, function ($request, $response) {
         /** @var $response \Sonno\Http\Response\Response */
         $response->setContent('Sorry, but that resource does not exist');
     });
     $app->unregisterResponseFilter(404);
     $response = $app->run($request);
     $this->assertNull($response->getContent());
 }