Exemplo n.º 1
0
 /**
  * Get a drest manager instance
  * @param  ORM\EntityManager    $em
  * @param  Configuration        $config
  * @param  \Drest\Event\Manager $evm
  * @return Manager              $dm
  */
 public function _getDrestManager(ORM\EntityManager $em = null, Configuration $config = null, EventManager $evm = null)
 {
     if (is_null($config)) {
         $config = $this->_getDefaultDrestConfig();
     }
     $em = is_null($em) ? $this->_getTestEntityManager() : $em;
     $emr = \Drest\EntityManagerRegistry::getSimpleManagerRegistry($em);
     $dm = Manager::create($emr, $config, $evm);
     return $dm;
 }
Exemplo n.º 2
0
$loader->add('Action', __DIR__ . '/../');
$loader->add('MyEvents', __DIR__ . '/../');
// Create an example doctrine application
$ormConfig = new \Doctrine\ORM\Configuration();
$pathToEntities = array(__DIR__ . '/../Entities');
$ORMDriver = $ormConfig->newDefaultAnnotationDriver($pathToEntities, false);
$ormConfig->setMetadataDriverImpl($ORMDriver);
// Do proxy stuff
$ormConfig->setProxyDir(__DIR__ . '/Entities/Proxies');
$ormConfig->setProxyNamespace('Entities\\Proxies');
$ormConfig->setAutoGenerateProxyClasses(true);
$em = \Doctrine\ORM\EntityManager::create(array('host' => 'localhost', 'user' => 'developer', 'password' => 'developer', 'dbname' => 'drest', 'driver' => 'pdo_mysql'), $ormConfig);
/********************START SETTING UP DREST CONFIGURATION***************************/
$drestConfig = new Configuration();
$drestConfig->setDetectContentOptions(array(Configuration::DETECT_CONTENT_HEADER => 'Accept', Configuration::DETECT_CONTENT_EXTENSION => true, Configuration::DETECT_CONTENT_PARAM => 'format'));
$drestConfig->setExposureDepth(3);
$drestConfig->setExposeRequestOption(Configuration::EXPOSE_REQUEST_PARAM_GET, 'expose');
$drestConfig->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
//$drestConfig->setDebugMode(true);
$drestConfig->addPathsToConfigFiles($pathToEntities);
// Set up event manager
$evm = new Event\Manager();
//$evm->addEventListener(array('preServiceAction', 'postServiceAction', 'preRouting', 'postRouting', 'preDispatch', 'postDispatch'), new MyEvents\MyEvent());
// Set up the service action registry
$serviceActions = new Drest\Service\Action\Registry();
$serviceActions->register(new Action\Custom(), ['Entities\\User::get_user2', 'Entities\\User::get_user3']);
$emr = \Drest\EntityManagerRegistry::getSimpleManagerRegistry($em);
$drestManager = \Drest\Manager::create($emr, $drestConfig, $evm, $serviceActions);
echo $drestManager->dispatch();
//echo $drestManager->dispatch(null, null, 'Entities\User::get_user', array('id' => 1));
//echo $drestManager->dispatch(new \Zend\Http\PhpEnvironment\Request(), new Zend\Http\PhpEnvironment\Response());