/**
  * Behaviour to adopt when an instancer of Switcher is destroyed by PHP.
  * 
  * @access public
  */
 public function __destruct()
 {
     ClassProxy::$ressourcesDelegatedTo = array();
     ResourceProxy::$ressourcesDelegatedTo = array();
     PropertyProxy::$ressourcesDelegatedTo = array();
 }
 /**
  * Clears the caches without immediately recalculating them
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function clearCaches()
 {
     self::$_properties = null;
     self::$_classes = null;
     self::$_resources = array();
     self::$_resources_loaded = false;
     ClassProxy::$ressourcesDelegatedTo = array();
     ResourceProxy::$ressourcesDelegatedTo = array();
     PropertyProxy::$ressourcesDelegatedTo = array();
     // remove hard-api-property cache.
     $cache = \common_cache_FileCache::singleton();
     $cache->remove('hard-api-property');
 }
 public function testHardPropertyModifications()
 {
     $this->hardify();
     $this->createData();
     $dbWrapper = core_kernel_classes_DbWrapper::singleton();
     $movieClass = $this->targetMovieClass;
     $workClass = $this->targetWorkClass;
     $authorProperty = $this->targetAuthorProperty;
     $producerProperty = $this->targetProducerProperty;
     $actorsProperty = $this->targetActorsProperty;
     $labelProperty = new core_kernel_classes_Property(RDFS_LABEL);
     $referencer = ResourceReferencer::singleton();
     $propertyProxy = PropertyProxy::singleton();
     // Retrieve interesting resources.
     $instances = $workClass->searchInstances(array($authorProperty->getUri() => 'Leonardo da Vinci'), array('like' => false, 'recursive' => false));
     $monaLisa = current($instances);
     $instances = $movieClass->searchInstances(array($labelProperty->getUri() => 'The Lord of the Rings'), array('like' => false, 'recursive' => false));
     $lordOfTheRings = current($instances);
     $instances = $movieClass->searchInstances(array($labelProperty->getUri() => 'The Hobbit'), array('like' => true, 'recursive' => false));
     $theHobbit = current($instances);
     if (empty($monaLisa) || empty($lordOfTheRings) || empty($theHobbit)) {
         $this->fail("Unable to retrieve instances that will be used in the following tests.");
     } else {
         // Try to create a new scalar property after hardification.
         $testProperty = $movieClass->createProperty('after hardify property');
         $testPropertyShortName = Utils::getShortName($testProperty);
         $testPropertyLocations = $referencer->propertyLocation($testProperty);
         $movieClassLocations = $referencer->classLocations($movieClass);
         $movieClassTable = $movieClassLocations[0]['table'];
         $movieClassTableColumns = array();
         foreach ($dbWrapper->getColumnNames($movieClassTable) as $col) {
             $movieClassTableColumns[] = $col->getName();
         }
         $workClassLocations = $referencer->classLocations($workClass);
         $workClassTable = $movieClassLocations[0]['table'];
         $workClassTableColumns = $dbWrapper->getColumnNames($workClassTable);
         $testPropertyShortName = Utils::getShortName($testProperty);
         $authorPropertyShortName = Utils::getShortName($authorProperty);
         // test delegation and presence of the column.
         $this->assertFalse($testProperty->isMultiple());
         $this->assertTrue(in_array($testPropertyShortName, $movieClassTableColumns));
         $this->assertIsA($propertyProxy->getImpToDelegateTo($testProperty), 'oat\\generisHard\\models\\hardsql\\Property');
         // set language dependency of the test property to true.
         $testProperty->setLgDependent(true);
         $this->assertTrue($testProperty->isLgDependent());
         $movieClassTableColumns = array();
         foreach ($dbWrapper->getColumnNames($movieClassTable) as $col) {
             $movieClassTableColumns[] = $col->getName();
         }
         $this->assertFalse(in_array($testPropertyShortName, $movieClassTableColumns));
         // create some property values for the test property.
         $testMovie = $movieClass->createInstance('A Test Movie');
         $testMovie->setPropertyValue($testProperty, 'EN-TestPropertyValue-1');
         $testMovie->setPropertyValueByLg($testProperty, 'EN-TestPropertyValue-2', DEFAULT_LANG);
         $testMovie->setPropertyValueByLg($testProperty, 'FR-TestPropertyValue-1', 'FR');
         $testPropertyValues = $testMovie->getPropertyValues($testProperty);
         $this->assertEquals(count($testPropertyValues), 2);
         // Only EN values will come back.
         $testPropertyValues = $testMovie->getPropertyValuesByLg($testProperty, DEFAULT_LANG);
         $this->assertEquals(count($testPropertyValues->sequence), 2);
         $testPropertyValues = $testMovie->getPropertyValuesByLg($testProperty, 'FR');
         $this->assertEquals(count($testPropertyValues->sequence), 1);
         // set back the language dependency of the test property to false.
         $testProperty->setLgDependent(false);
         $this->assertFalse($testProperty->isLgDependent());
         $movieClassTableColumns = array();
         foreach ($dbWrapper->getColumnNames($movieClassTable) as $col) {
             $movieClassTableColumns[] = $col->getName();
         }
         $this->assertTrue(in_array($testPropertyShortName, $movieClassTableColumns));
         $testPropertyValues = $testMovie->getPropertyValues($testProperty);
         $this->assertEquals(count($testPropertyValues), 1);
         // set the author property to multiple.
         $this->assertTrue(in_array($authorPropertyShortName, $movieClassTableColumns));
         $this->assertFalse($authorProperty->isMultiple());
         $authorProperty->setMultiple(true);
         $this->assertTrue($authorProperty->isMultiple());
         $movieClassTableColumns = array();
         foreach ($dbWrapper->getColumnNames($movieClassTable) as $col) {
             $movieClassTableColumns[] = $col->getName();
         }
         $this->assertFalse(in_array($authorPropertyShortName, $movieClassTableColumns));
         // Add a fake value to make it multi valued
         $theHobbit->setPropertyValue($authorProperty, 'The Clone of Peter Jackson');
         $authors = $theHobbit->getPropertyValues($authorProperty);
         $this->assertEquals(count($authors), 2);
         $this->assertEquals(current($authors), 'Peter Jackson');
         next($authors);
         $this->assertEquals(current($authors), 'The Clone of Peter Jackson');
         $authors = $monaLisa->getPropertyValues($authorProperty);
         $this->assertEquals(count($authors), 1);
         $this->assertEquals(current($authors), 'Leonardo da Vinci');
         // reset the author property to scalar.
         $authorProperty->setMultiple(false);
         $this->assertFalse($authorProperty->isMultiple());
         $movieClassTableColumns = array();
         foreach ($dbWrapper->getColumnNames($movieClassTable) as $col) {
             $movieClassTableColumns[] = $col->getName();
         }
         $this->assertTrue(in_array($authorPropertyShortName, $movieClassTableColumns));
         $authors = $theHobbit->getPropertyValues($authorProperty);
         $this->assertEquals(count($authors), 1);
         $this->assertEquals(current($authors), 'Peter Jackson');
     }
 }