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
 /**
  * Recursive function to generate default expose columns
  *
  * @param array                     $fields    - array to be populated recursively (referenced)
  * @param string                    $class     - name of the class to process
  * @param EntityManagerRegistry     $emr       - entity manager registry used to fetch class information
  * @param integer                   $depth     - maximum depth you want to travel through the relations
  * @param integer                   $fetchType - The fetch type to be used
  * @param integer|null              $fetchType - The required fetch type of the relation
  */
 protected function processExposeDepth(&$fields, $class, EntityManagerRegistry $emr, $depth = 0, $fetchType = null)
 {
     $this->registered_expose_classes[] = $class;
     if ($depth > 0) {
         /** @var \Doctrine\ORM\Mapping\ClassMetaData $metaData */
         $metaData = $emr->getManagerForClass($class)->getClassMetadata($class);
         $fields = $metaData->getColumnNames();
         if ($depth - 1 > 0) {
             --$depth;
             foreach ($metaData->getAssociationMappings() as $key => $assocMapping) {
                 if (!in_array($assocMapping['targetEntity'], $this->registered_expose_classes) && (is_null($fetchType) || $assocMapping['fetch'] == $fetchType)) {
                     $this->processExposeDepth($fields[$key], $assocMapping['targetEntity'], $emr, $depth, $fetchType);
                 }
             }
         }
     }
 }
Exemplo n.º 3
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());