/**
  * @covers Opt_Cdf_Manager::getFormat
  * @covers Opt_Cdf_Manager::addFormat
  * @covers Opt_Cdf_Manager::setLocality
  * @covers Opt_Cdf_Manager::clearLocals
  * @expectedException Opt_NoMatchingFormat_Exception
  */
 public function testDisablingLocalDefinitions()
 {
     $locator = $this->getMock('Opt_Cdf_Locator_Interface', array('getElementLocation'));
     $locator->expects($this->exactly(2))->method('getElementLocation')->will($this->returnValue(array()));
     $this->_obj->setLocality(Opt_Cdf_Manager::AS_LOCAL);
     $this->_obj->addFormat('foo', 'bar', 'Array', array());
     $this->_obj->addFormat('joe', 'goo', 'Array', array());
     $this->assertTrue($this->_obj->getFormat('foo', 'bar', $locator) instanceof Opt_Format_Array);
     $this->_obj->clearLocals();
     $this->_obj->getFormat('joe', 'goo', $locator);
 }
Exemple #2
0
 /**
  * Loads the specified CDF file.
  *
  * @param string $filename The CDF file name.
  */
 public function load($filename)
 {
     // If the file has already been loaded, skip the parsing process.
     if (in_array($filename, $this->_loaded)) {
         return;
     }
     $this->_loaded[] = $filename;
     // Initialize the parser and lexer and parse everything.
     $lexer = new Opt_Cdf_Lexer($filename);
     $parser = new Opt_Cdf_Parser($this);
     $this->_definitions = array();
     while ($lexer->yylex()) {
         if ($lexer->token != 'w') {
             $parser->doParse($lexer->token, $lexer->value);
         }
     }
     $parser->doParse(0, 0);
     // Now register everything in the manager
     foreach ($this->_definitions as $definition) {
         foreach ($definition[0] as $group) {
             $last = reset($group);
             array_shift($group);
             // Concatenate the list for the locator
             $fullyQualifiedPath = array();
             foreach ($group as $item) {
                 if ($item[0] !== null && $item[1] !== null) {
                     $fullyQualifiedPath[] = $item[0] . '#' . $item[1];
                 } elseif ($item[0] != null) {
                     $fullyQualifiedPath[] = '#' . $item[1];
                 } else {
                     $fullyQualifiedPath[] = $item[0] . '#';
                 }
             }
             // Add the format definition to the manager
             if (isset($definition[1]['data-format'])) {
                 $this->_manager->addFormat($last[0], $last[1], $definition[1]['data-format'], $fullyQualifiedPath);
             }
         }
     }
 }
Exemple #3
0
 /**
  * Allows to export the data format configuration to the compiler.
  *
  * @param Array $list An associative array of pairs "variable => format description"
  */
 public function addFormats(array $globalCdf, array $localCdf, array $globalDefs, array $localDefs)
 {
     $manager = $this->getCdfManager();
     if (sizeof($globalCdf) > 0 || sizeof($localCdf) > 0) {
         // Initialize the loader
         if ($this->_cdfLoader === null) {
             $this->_cdfLoader = new Opt_Cdf_Loader($manager);
         }
         $manager->setLocality(Opt_Cdf_Manager::AS_GLOBAL);
         foreach ($globalCdf as $cdf) {
             $this->_cdfLoader->load($this->_tpl->cdfDir . $cdf);
         }
         foreach ($localCdf as $cdf) {
             $manager->setLocality($cdf);
             $this->_cdfLoader->load($this->_tpl->cdfDir . $cdf);
         }
         $this->_cdfManager->setLocals($localCdf);
     }
     // Now manual definitions...
     $manager->setLocality(Opt_Cdf_Manager::AS_GLOBAL);
     foreach ($globalDefs as $item => &$idList) {
         foreach ($idList as $id => $format) {
             $this->_cdfManager->addFormat($item, $id, $format, array());
         }
     }
     $manager->setLocality(Opt_Cdf_Manager::AS_LOCAL);
     foreach ($localDefs as $item => &$idList) {
         foreach ($idList as $id => $format) {
             $this->_cdfManager->addFormat($item, $id, $format, array());
         }
     }
 }