/**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param $name
  * @param $requestedName
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $config = $serviceLocator->get('Config');
     $zohoConfig = $config['zoho'];
     $resourceConfig = $config['zoho']['resources'][$requestedName];
     $resource = new Resource($zohoConfig['auth_token'], $zohoConfig['organization_id']);
     $resource->setPath($resourceConfig['path']);
     $resource->setCollectionName($resourceConfig['collectionName']);
     $entityClass = array_key_exists('entityClass', $resourceConfig) ? $resourceConfig['entityClass'] : str_replace('Resource', 'Entity', $requestedName);
     $resource->setEntityClass($entityClass);
     $resource->setEntityName($resourceConfig['entityName']);
     if (isset($resourceConfig['input-filter']) && is_array($resourceConfig['input-filter'])) {
         $inputFilterFactory = new InputFilterFactory();
         $inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']);
         $resource->setInputFilter($inputFilter);
     }
     $hydratorManager = $serviceLocator->get('HydratorManager');
     $hydratorName = str_replace('Entity', 'Hydrator', $entityClass);
     if ($hydratorManager->has($hydratorName)) {
         $hydrator = $hydratorManager->get($hydratorName);
     } else {
         $hydrator = new ClassMethods();
     }
     $resource->setHydrator($hydrator);
     return $resource;
 }
 /**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param $name
  * @param $requestedName
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $config = $serviceLocator->get('Config');
     $zohoConfig = $config['zoho'];
     $resourceConfig = $config['zoho']['resources'][$requestedName];
     $resource = new Resource($zohoConfig['auth_token'], $zohoConfig['organization_id']);
     $resource->setPath($resourceConfig['path']);
     $resource->setCollectionName($resourceConfig['collectionName']);
     $entityClass = array_key_exists('entityClass', $resourceConfig) ? $resourceConfig['entityClass'] : str_replace('Resource', 'Entity', $requestedName);
     $resource->setEntityClass($entityClass);
     $resource->setEntityName($resourceConfig['entityName']);
     if (isset($resourceConfig['input-filter']) && is_array($resourceConfig['input-filter'])) {
         $inputFilterFactory = new InputFilterFactory();
         $inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']);
         $resource->setInputFilter($inputFilter);
     }
     $hydratorManager = $serviceLocator->get('HydratorManager');
     $hydratorName = str_replace('Entity', 'Hydrator', $entityClass);
     if ($hydratorManager->has($hydratorName)) {
         $hydrator = $hydratorManager->get($hydratorName);
     } else {
         $hydrator = new ClassMethods();
     }
     if (isset($resourceConfig['strategies'])) {
         foreach ($resourceConfig['strategies'] as $field => $strategyKey) {
             if (!$serviceLocator->has($strategyKey)) {
                 throw new ServiceNotCreatedException(sprintf('Invalid strategy %s for field %s', $strategyKey, $field));
             }
             $strategy = $serviceLocator->get($strategyKey);
             if (!$strategy instanceof StrategyInterface) {
                 throw new ServiceNotCreatedException(sprintf('Invalid strategy class %s for field %s', get_class($strategy), $field));
             }
             $hydrator->addStrategy($field, $strategy);
         }
     }
     $resource->setHydrator($hydrator);
     return $resource;
 }