exchangeArray() public method

Populate object from array
public exchangeArray ( array $data )
$data array
Beispiel #1
0
    /**
     * Create a new API-First enabled module
     *
     * @param  array|object $data
     * @return ModuleEntity
     * @throws CreationException
     */
    public function create($data)
    {
        if (is_object($data)) {
            $data = (array) $data;
        }

        if (!isset($data['name'])) {
            throw new CreationException('Missing module name');
        }

        $version = isset($data['version']) ? $data['version'] : 1;
        $name    = $data['name'];
        $name    = str_replace('.', '\\', $name);
        if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_]*(\\\+[a-zA-Z][a-zA-Z0-9_]*)?$/', $name)) {
            throw new CreationException('Invalid module name; must be a valid PHP namespace name');
        }

        if (false === $this->modules->createModule($name, $this->modulePathSpec)) {
            throw new CreationException('Unable to create module; check your paths and permissions');
        }

        $metadata = new ModuleEntity($name);
        $metadata->exchangeArray(array(
            'versions' => array($version),
        ));
        return $metadata;
    }
Beispiel #2
0
    public function testCanSetAndRetrieveModuleDefaultVersion()
    {
        $moduleEntity = new ModuleEntity('Test\Foo');
        $this->assertSame(1, $moduleEntity->getDefaultVersion()); // initial state

        $moduleEntity->exchangeArray(array('default_version' => 123));
        $this->assertSame(123, $moduleEntity->getDefaultVersion());
    }
 protected function injectModuleResourceRelationalLinks(Model\ModuleEntity $module, $links, HalJsonModel $model)
 {
     $moduleData = $module->getArrayCopy();
     $moduleName = $moduleData['name'];
     $this->injectLinksForServicesByType('authorization', array(), $links, $moduleName);
     $this->injectLinksForServicesByType('rest', $moduleData['rest'], $links, $moduleName);
     unset($moduleData['rest']);
     $this->injectLinksForServicesByType('rpc', $moduleData['rpc'], $links, $moduleName);
     unset($moduleData['rpc']);
     $module = new Model\ModuleEntity($module->getNamespace(), array(), array(), $module->isVendor());
     $module->exchangeArray($moduleData);
     $replacement = new Entity($module, $moduleName);
     $replacement->setLinks($links);
     $model->setPayload($replacement);
 }
 /**
  * Returns list of all API-First-enabled modules
  *
  * @return array
  */
 protected function getEnabledModules()
 {
     if (is_array($this->modules)) {
         return $this->modules;
     }
     $this->modules = array();
     foreach ($this->moduleManager->getLoadedModules() as $moduleName => $module) {
         if (!$module instanceof ApigilityProviderInterface && !$module instanceof ApigilityModuleInterface) {
             continue;
         }
         if ($module instanceof ApigilityModuleInterface) {
             trigger_error('ZF\\Apigility\\ApigilityModuleInterface is deprecated,
                 use ZF\\Apigility\\Provider\\ApigilityProviderInterface instead', E_USER_DEPRECATED);
         }
         $services = $this->getServicesByModule($moduleName);
         $versions = $this->getVersionsByModule($moduleName, $module);
         $entity = new ModuleEntity($moduleName, $services['rest'], $services['rpc']);
         $entity->exchangeArray(array('versions' => $versions, 'default_version' => $this->getModuleDefaultVersion($module)));
         $this->modules[$entity->getName()] = $entity;
     }
     return $this->modules;
 }