src/Admin/Model/DoctrineRestServiceModel.php
/**
     * Create a new service using the details provided
     *
     * @param NewDoctrineServiceEntity $details
     * @return DoctrineRestServiceEntity
     * @throws CreationException
     */
Create a new service using the details provided
@param NewDoctrineServiceEntity $details
@return DoctrineRestServiceEntity
@throws CreationException
Create a new service using the details provided @param NewDoctrineServiceEntity $details @return DoctrineRestServiceEntity @throws CreationException
public function createService(NewDoctrineServiceEntity $details)
    {
        $resourceName = ucfirst($details->serviceName);
        if (! preg_match('/^[a-zA-Z][a-zA-Z0-9_]*(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $resourceName)) {
            throw new CreationException('Invalid resource name; must be a valid PHP namespace name.');
        }
        if (! $this->getServiceManager()->has($details->objectManager)) {
            throw new CreationException(
                'Invalid object manager specified. Must be declared in the service manager.',
                422
            );
        }
        $entity = new DoctrineRestServiceEntity();
        $entity->exchangeArray($details->getArrayCopy());
        $mediaType = $this->createMediaType();
        $resourceClass = $details->resourceClass ?: $this->createResourceClass($resourceName, $details);
        $collectionClass = $details->collectionClass ?: $this->createCollectionClass($resourceName);
        $serviceName = $details->serviceName ?: $resourceName;
        $entityClass = $details->entityClass;
        if (! $entityClass || ! class_exists($entityClass)) {
            throw new CreationException('entityClass is required and must exist');
        }
        $module = $details->module ?: $this->module;
        $controllerService = $details->controllerServiceName ?: $this->createControllerServiceName($resourceName);
        $routeName = $details->routeName ?: $this->createRoute(
            $resourceName,
            $details->routeMatch,
            $details->routeIdentifierName,
            $controllerService
        );
        $hydratorName  = $details->hydratorName ?: $this->createHydratorName($resourceName);
        $objectManager = $details->objectManager ?: 'doctrine.entitymanager.orm_default';
        $entity->exchangeArray([
            'service_name'            => $serviceName,
            'collection_class'        => $collectionClass,
            'controller_service_name' => $controllerService,
            'entity_class'            => $entityClass,
            'hydrator_name'           => $hydratorName,
            'module'                  => $module,
            'resource_class'          => $resourceClass,
            'route_name'              => $routeName,
            'accept_whitelist'        => [
                $mediaType,
                'application/hal+json',
                'application/json',
            ],
            'content_type_whitelist'  => [
                $mediaType,
                'application/json',
            ],
            'object_manager' => $objectManager,
        ]);
        $this->createRestConfig($entity, $controllerService, $resourceClass, $routeName);
        $this->createContentNegotiationConfig($entity, $controllerService);
        $this->createHalConfig($entity, $entityClass, $collectionClass, $routeName);
        $this->createDoctrineConfig($entity, $entityClass, $collectionClass, $routeName);
        $this->createDoctrineHydratorConfig($entity, $entityClass, $collectionClass, $routeName);
        $this->getEventManager()->trigger(
            __FUNCTION__,
            $this,
            [
                'entity' => $entity,
                'configResource' => $this->configResource,
            ]
        );
        return $entity;
    }
public function createService ( NewDoctrineServiceEntity $ details ) { $ resourceName = ucfirst ( $ details -> serviceName ) ; if ( ! preg_match ( '/^[a-zA-Z][a-zA-Z0-9_]*(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/' , $ resourceName ) ) { throw new CreationException ( 'Invalid resource name; must be a valid PHP namespace name.' ) ; } if ( ! $ this -> getServiceManager ( ) -> has ( $ details -> objectManager ) ) { throw new CreationException ( 'Invalid object manager specified. Must be declared in the service manager.' , 422 ) ; } $ entity = new DoctrineRestServiceEntity ( ) ; $ entity -> exchangeArray ( $ details -> getArrayCopy ( ) ) ; $ mediaType = $ this -> createMediaType ( ) ; $ resourceClass = $ details -> resourceClass ? : $ this -> createResourceClass ( $ resourceName , $ details ) ; $ collectionClass = $ details -> collectionClass ? : $ this -> createCollectionClass ( $ resourceName ) ; $ serviceName = $ details -> serviceName ? : $ resourceName ; $ entityClass = $ details -> entityClass ; if ( ! $ entityClass || ! class_exists ( $ entityClass ) ) { throw new CreationException ( 'entityClass is required and must exist' ) ; } $ module = $ details -> module ? : $ this -> module ; $ controllerService = $ details -> controllerServiceName ? : $ this -> createControllerServiceName ( $ resourceName ) ; $ routeName = $ details -> routeName ? : $ this -> createRoute ( $ resourceName , $ details -> routeMatch , $ details -> routeIdentifierName , $ controllerService ) ; $ hydratorName = $ details -> hydratorName ? : $ this -> createHydratorName ( $ resourceName ) ; $ objectManager = $ details -> objectManager ? : 'doctrine.entitymanager.orm_default' ; $ entity -> exchangeArray ( [ 'service_name' => $ serviceName , 'collection_class' => $ collectionClass , 'controller_service_name' => $ controllerService , 'entity_class' => $ entityClass , 'hydrator_name' => $ hydratorName , 'module' => $ module , 'resource_class' => $ resourceClass , 'route_name' => $ routeName , 'accept_whitelist' => [ $ mediaType , 'application/hal+json' , 'application/json' , ] , 'content_type_whitelist' => [ $ mediaType , 'application/json' , ] , 'object_manager' => $ objectManager , ] ) ; $ this -> createRestConfig ( $ entity , $ controllerService , $ resourceClass , $ routeName ) ; $ this -> createContentNegotiationConfig ( $ entity , $ controllerService ) ; $ this -> createHalConfig ( $ entity , $ entityClass , $ collectionClass , $ routeName ) ; $ this -> createDoctrineConfig ( $ entity , $ entityClass , $ collectionClass , $ routeName ) ; $ this -> createDoctrineHydratorConfig ( $ entity , $ entityClass , $ collectionClass , $ routeName ) ; $ this -> getEventManager ( ) -> trigger ( __FUNCTION__ , $ this , [ 'entity' => $ entity , 'configResource' => $ this -> configResource , ] ) ; return $ entity ; }
Create a new service using the details provided
 @param NewDoctrineServiceEntity $details
 @return DoctrineRestServiceEntity
 @throws CreationException
Create a new service using the details provided @param NewDoctrineServiceEntity $details @return DoctrineRestServiceEntity @throws CreationException