php SMW-StoreFactory类(方法)实例源码

下面列出了php SMW-StoreFactory 类(方法)源码代码实例,从而了解它的用法。

作者:whysass    项目:kmwik   
/**
  * @since  1.9
  */
 protected function loadAtInstantiation()
 {
     /**
      * Settings object definition
      *
      * @since  1.9
      *
      * @return Settings
      */
     $this->registerObject('Settings', function () {
         return Settings::newFromGlobals();
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * Store object definition
      *
      * @since  1.9
      *
      * @return Store
      */
     $this->registerObject('Store', function (DependencyBuilder $builder) {
         return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore'));
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * CacheHandler object definition
      *
      * @since  1.9
      *
      * @return CacheHandler
      */
     $this->registerObject('CacheHandler', function (DependencyBuilder $builder) {
         return CacheHandler::newFromId($builder->newObject('Settings')->get('smwgCacheType'));
     }, DependencyObject::SCOPE_SINGLETON);
 }

作者:brandonphuon    项目:mediawik   
protected function getTypeProperties($typeLabel)
 {
     global $wgRequest, $smwgTypePagingLimit;
     if ($smwgTypePagingLimit <= 0) {
         return '';
         // not too useful, but we comply to this request
     }
     $from = $wgRequest->getVal('from');
     $until = $wgRequest->getVal('until');
     $typeValue = DataValueFactory::getInstance()->newTypeIDValue('__typ', $typeLabel);
     if (!$typeValue->isValid()) {
         return $this->msg('smw-special-types-no-such-type')->escaped();
     }
     $store = \SMW\StoreFactory::getStore();
     $options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
     $diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
     if (!$options->ascending) {
         $diWikiPages = array_reverse($diWikiPages);
     }
     $result = '';
     if (count($diWikiPages) > 0) {
         $pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
         $title = $this->getTitleFor('Types', $typeLabel);
         $title->setFragment('#SMWResults');
         // Make navigation point to the result list.
         $navigation = $pageLister->getNavigationLinks($title);
         $resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
         $typeName = $typeValue->getLongWikiText();
         $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMessage('smw_type_header', $typeName)->text() . "</h2>\n<p>" . wfMessage('smw_typearticlecount')->numParams($resultNumber)->text() . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
     }
     return $result;
 }

作者:ReachingOu    项目:SemanticMediaWik   
/**
  * @since  1.9
  */
 protected function loadAtInstantiation()
 {
     /**
      * Settings object definition
      *
      * @since  1.9
      *
      * @return Settings
      */
     $this->registerObject('Settings', function () {
         return Settings::newFromGlobals();
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * Store object definition
      *
      * @since  1.9
      *
      * @return Store
      */
     $this->registerObject('Store', function (DependencyBuilder $builder) {
         return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore'));
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * @since  1.9
      *
      * @return Cache
      */
     $this->registerObject('Cache', function (DependencyBuilder $builder) {
         return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache();
     }, DependencyObject::SCOPE_SINGLETON);
 }

作者:whysass    项目:kmwik   
/**
  * Returns the HTML which is added to $wgOut after the article text.
  *
  * @return string
  */
 protected function getHtml()
 {
     if ($this->limit > 0) {
         // limit==0: configuration setting to disable this completely
         $store = StoreFactory::getStore();
         $concept = $store->getConceptCacheStatus($this->getDataItem());
         $description = new ConceptDescription($this->getDataItem());
         $query = SMWPageLister::getQuery($description, $this->limit, $this->from, $this->until);
         $queryResult = $store->getQueryResult($query);
         $diWikiPages = $queryResult->getResults();
         if ($this->until !== '') {
             $diWikiPages = array_reverse($diWikiPages);
         }
         $errors = $queryResult->getErrors();
     } else {
         $diWikiPages = array();
         $errors = array();
     }
     $pageLister = new SMWPageLister($diWikiPages, null, $this->limit, $this->from, $this->until);
     $this->mTitle->setFragment('#SMWResults');
     // Make navigation point to the result list.
     $navigation = $pageLister->getNavigationLinks($this->mTitle);
     $titleText = htmlspecialchars($this->mTitle->getText());
     $resultNumber = min($this->limit, count($diWikiPages));
     // Concept cache information
     if ($concept instanceof DIConcept && $concept->getCacheStatus() === 'full') {
         $cacheInformation = Html::element('span', array('class' => 'smw-concept-cache-information'), ' ' . $this->getContext()->msg('smw-concept-cache-text', $this->getContext()->getLanguage()->formatNum($concept->getCacheCount()), $this->getContext()->getLanguage()->date($concept->getCacheDate()), $this->getContext()->getLanguage()->time($concept->getCacheDate()))->text());
     } else {
         $cacheInformation = '';
     }
     return Html::element('br', array('id' => 'smwfootbr')) . Html::element('a', array('name' => 'SMWResults'), null) . Html::rawElement('div', array('id' => 'mw-pages'), Html::rawElement('h2', array(), $this->getContext()->msg('smw_concept_header', $titleText)->text()) . Html::element('span', array(), $this->getContext()->msg('smw_conceptarticlecount', $resultNumber)->parse()) . smwfEncodeMessages($errors) . ' ' . $navigation . $cacheInformation . $pageLister->formatList());
 }

作者:WolfgangFah    项目:SemanticMediaWik   
public function testGetters()
 {
     $diType = SMWDataItem::TYPE_NUMBER;
     $name = 'smw_di_number';
     $instance = new TableDefinition($diType, $name);
     $this->assertInternalType('array', $instance->getFields(StoreFactory::getStore('SMWSQLStore3')));
     $this->assertEquals($diType, $instance->getDiType());
     $this->assertEquals($name, $instance->getName());
 }

作者:yusufchan    项目:ap   
/**
  * Helper function to get the SMW data store for different versions
  * of SMW.
  */
 public static function getSMWStore()
 {
     if (class_exists('\\SMW\\StoreFactory')) {
         // SMW 1.9+
         return \SMW\StoreFactory::getStore();
     } else {
         return smwfGetStore();
     }
 }

作者:WolfgangFah    项目:SemanticMediaWik   
/**
  * @dataProvider propertyObjectProvider
  */
 public function testPhpSerialization($property, $dataItem)
 {
     $instance = StubSemanticData::newFromSemanticData(new SemanticData(new DIWikiPage('Foo', NS_MAIN)), $this->store);
     $instance->addPropertyObjectValue($property, $dataItem);
     StoreFactory::setDefaultStoreForUnitTest($this->store);
     $serialization = serialize($instance);
     $this->assertEquals($instance->getHash(), unserialize($serialization)->getHash());
     StoreFactory::clear();
 }

作者:whysass    项目:kmwik   
/**
  * @test TableDefinition::getFields
  * @test TableDefinition::getDiType
  * @test TableDefinition::getName
  *
  * @since 1.9
  */
 public function testGetters()
 {
     $diType = SMWDataItem::TYPE_NUMBER;
     $name = 'smw_di_number';
     $instance = $this->newInstance($diType, $name);
     $this->assertInternalType('array', $instance->getFields(StoreFactory::getStore('SMWSQLStore3')), 'Asserts that getFields() returns an array');
     $this->assertEquals($diType, $instance->getDiType(), 'Asserts that getDiType() returns the corret object');
     $this->assertEquals($name, $instance->getName(), 'Asserts that getName() returns the corret object');
 }

作者:whysass    项目:kmwik   
/**
  * @dataProvider getCacheNonCacheDataProvider
  */
 public function testCacheNoCacheOnSQLStore(array $test, array $expected, array $info)
 {
     $store = StoreFactory::getStore('SMWSQLStore3');
     // Sample A
     $instance = $this->newInstance($store, $test['A']['property'], $test['A']['count'], $test['cacheEnabled']);
     $this->assertEquals($expected['A'], $instance->getResults(), $info['msg']);
     // Sample B
     $instance = $this->newInstance($store, $test['B']['property'], $test['B']['count'], $test['cacheEnabled']);
     $this->assertEquals($expected['B'], $instance->getResults(), $info['msg']);
     $this->assertEquals($test['cacheEnabled'], $instance->isCached());
 }

作者:whysass    项目:kmwik   
protected function setUp()
 {
     $this->store = StoreFactory::getStore();
     if (!$this->store instanceof SPARQLStore) {
         $this->markTestSkipped("Requires a SPARQLStore instance");
     }
     $this->sparqlDatabase = $this->store->getConnection();
     if (!$this->sparqlDatabase->setConnectionTimeoutInSeconds(5)->ping()) {
         $this->markTestSkipped("Can't connect to the SparlDatabase");
     }
 }

作者:WolfgangFah    项目:SemanticMediaWik   
protected function setupStore($source, $expectedToRun = 0)
 {
     $storeId = isset($GLOBALS['smwgQuerySources'][$source]) ? $GLOBALS['smwgQuerySources'][$source] : null;
     $queryResult = $this->getMockBuilder('SMWQueryResult')->disableOriginalConstructor()->getMock();
     $queryResult->expects($this->exactly($expectedToRun))->method('getCount')->will($this->returnValue(0));
     $queryResult->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
     $store = StoreFactory::getStore($storeId);
     if (method_exists($store, 'setQueryResult')) {
         $store->setQueryResult($queryResult);
     }
     return $store;
 }

作者:WolfgangFah    项目:SemanticMediaWik   
public function testProcessOnSQLStore()
 {
     $userLanguage = $this->getMockBuilder('\\Language')->disableOriginalConstructor()->getMock();
     ApplicationFactory::getInstance()->registerObject('Store', StoreFactory::getStore());
     $extraStats = array();
     $version = '1.21';
     $instance = new SpecialStatsAddExtra($extraStats, $version, $userLanguage);
     $this->assertTrue($instance->process());
     // This is a "cheap" check against the SQLStore as it could return any
     // value therefore we use a message key as only known constant to verify
     // that the matching process was successful
     $this->assertTrue($this->matchArray($extraStats, 'smw-statistics-property-instance'));
 }

作者:WolfgangFah    项目:SemanticMediaWik   
private function registerCallbackHandlers($callbackLoader)
 {
     $callbackLoader->registerExpectedReturnType('Settings', '\\SMW\\Settings');
     $callbackLoader->registerCallback('Settings', function () use($callbackLoader) {
         return Settings::newFromGlobals();
     });
     $callbackLoader->registerExpectedReturnType('Store', '\\SMW\\Store');
     $callbackLoader->registerCallback('Store', function () use($callbackLoader) {
         return StoreFactory::getStore($callbackLoader->singleton('Settings')->get('smwgDefaultStore'));
     });
     $callbackLoader->registerExpectedReturnType('Cache', '\\Onoi\\Cache\\Cache');
     $callbackLoader->registerCallback('Cache', function () {
         return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache();
     });
     $callbackLoader->registerCallback('NamespaceExaminer', function () use($callbackLoader) {
         return NamespaceExaminer::newFromArray($callbackLoader->singleton('Settings')->get('smwgNamespacesWithSemanticLinks'));
     });
     $callbackLoader->registerExpectedReturnType('ParserData', '\\SMW\\ParserData');
     $callbackLoader->registerCallback('ParserData', function (\Title $title, \ParserOutput $parserOutput) {
         return new ParserData($title, $parserOutput);
     });
     $callbackLoader->registerCallback('MessageFormatter', function (\Language $language) {
         return new MessageFormatter($language);
     });
     $callbackLoader->registerExpectedReturnType('PageCreator', '\\SMW\\MediaWiki\\PageCreator');
     $callbackLoader->registerCallback('PageCreator', function () {
         return new PageCreator();
     });
     $callbackLoader->registerExpectedReturnType('TitleCreator', '\\SMW\\MediaWiki\\TitleCreator');
     $callbackLoader->registerCallback('TitleCreator', function () {
         return new TitleCreator();
     });
     $callbackLoader->registerExpectedReturnType('WikiPage', '\\WikiPage');
     $callbackLoader->registerCallback('WikiPage', function (\Title $title) {
         return \WikiPage::factory($title);
     });
     $callbackLoader->registerExpectedReturnType('ContentParser', '\\SMW\\ContentParser');
     $callbackLoader->registerCallback('ContentParser', function (\Title $title) {
         return new ContentParser($title);
     });
     $callbackLoader->registerExpectedReturnType('JobFactory', '\\SMW\\MediaWiki\\Jobs\\JobFactory');
     $callbackLoader->registerCallback('JobFactory', function () {
         return new JobFactory();
     });
     $callbackLoader->registerExpectedReturnType('FactboxFactory', '\\SMW\\Factbox\\FactboxFactory');
     $callbackLoader->registerCallback('FactboxFactory', function () {
         return new FactboxFactory();
     });
 }

作者:whysass    项目:kmwik   
/**
  * @see Maintenance::execute
  */
 public function execute()
 {
     if (!defined('SMW_VERSION')) {
         $this->output("You need to have SMW enabled in order to use this maintenance script!\n\n");
         exit;
     }
     $store = StoreFactory::getStore();
     $statsTable = new PropertyStatisticsTable($store->getConnection('mw.db'), \SMWSQLStore3::PROPERTY_STATISTICS_TABLE);
     // Need to instantiate an extra object here since we cannot make this class itself
     // into a MessageReporter since the maintenance script does not load the interface in time.
     $reporter = new ObservableMessageReporter();
     $reporter->registerReporterCallback(array($this, 'reportMessage'));
     $statisticsRebuilder = new SimplePropertyStatisticsRebuilder($store, $reporter);
     $statisticsRebuilder->rebuild($statsTable);
 }

作者:whysass    项目:kmwik   
protected function setUp()
 {
     $this->store = StoreFactory::getStore();
     if (!$this->store instanceof SPARQLStore) {
         $this->markTestSkipped("Requires a SPARQLStore instance");
     }
     $sparqlDatabase = $this->store->getConnection();
     if (!$sparqlDatabase->setConnectionTimeoutInSeconds(5)->ping()) {
         $this->markTestSkipped("Can't connect to the SPARQL database");
     }
     $sparqlDatabase->deleteAll();
     $this->queryResultValidator = new QueryResultValidator();
     $this->semanticDataFactory = new SemanticDataFactory();
     $this->dataValueFactory = DataValueFactory::getInstance();
 }

作者:FlorianS    项目:SemanticMediaWik   
protected function getTypeProperties($typeLabel)
 {
     global $wgRequest, $smwgTypePagingLimit;
     if ($smwgTypePagingLimit <= 0) {
         return '';
         // not too useful, but we comply to this request
     }
     $from = $wgRequest->getVal('from');
     $until = $wgRequest->getVal('until');
     $typeValue = DataValueFactory::getInstance()->newTypeIDValue('__typ', $typeLabel);
     $this->getOutput()->prependHTML($this->getTypesLink());
     if (!$typeValue->isValid()) {
         return $this->msg('smw-special-types-no-such-type')->escaped();
     }
     $store = \SMW\StoreFactory::getStore();
     $options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
     $diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
     if (!$options->ascending) {
         $diWikiPages = array_reverse($diWikiPages);
     }
     $escapedTypeLabel = htmlspecialchars($typeValue->getWikiValue());
     $canonicalLabel = DataTypeRegistry::getInstance()->findCanonicalLabelById($typeValue->getDataItem()->getFragment());
     $typeKey = 'smw-sp-types' . strtolower($typeValue->getDataItem()->getFragment());
     $messageKey = wfMessage($typeKey)->exists() ? $typeKey : 'smw-sp-types-default';
     $result = \Html::rawElement('div', array('class' => 'smw-sp-types-intro' . $typeKey), wfMessage($messageKey, str_replace('_', ' ', $escapedTypeLabel))->parse() . ' ' . wfMessage('smw-sp-types-help', str_replace(' ', '_', $canonicalLabel))->parse());
     $result .= $this->displayExtraInformationAbout($typeValue);
     if (count($diWikiPages) > 0) {
         $pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
         $title = $this->getTitleFor('Types', $typeLabel);
         $title->setFragment('#SMWResults');
         // Make navigation point to the result list.
         $navigation = $pageLister->getNavigationLinks($title);
         $resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
         $typeName = $typeValue->getLongWikiText();
         $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMessage('smw_type_header', $typeName)->text() . "</h2>\n<p>" . wfMessage('smw_typearticlecount')->numParams($resultNumber)->text() . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
     }
     return $result;
 }

作者:hangy    项目:SemanticMediaWik   
/**
  * @see SMWDataValue::loadDataItem()
  *
  * @param $dataitem SMWDataItem
  *
  * @return boolean
  */
 protected function loadDataItem(SMWDataItem $dataItem)
 {
     if (!$dataItem instanceof SMWDIBlob) {
         return false;
     }
     $this->m_dataitem = $dataItem;
     $this->m_diProperties = array();
     foreach (explode(';', $dataItem->getString()) as $propertyKey) {
         $property = null;
         try {
             $property = new SMWDIProperty($propertyKey);
         } catch (SMWDataItemException $e) {
             $property = new SMWDIProperty('Error');
             $this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text());
         }
         if ($property instanceof SMWDIProperty) {
             // Find a possible redirect
             $this->m_diProperties[] = StoreFactory::getStore()->getRedirectTarget($property);
         }
     }
     $this->m_caption = false;
     return true;
 }

作者:jongfel    项目:SemanticMediaWik   
/**
  * Retrieve a copy of the semantic data for a wiki page, possibly filtering
  * it so that only essential properties are included (in some cases, we only
  * want to export stub information about a page).
  * We make a copy of the object since we may want to add more data later on
  * and we do not want to modify the store's result which may be used for
  * caching purposes elsewhere.
  */
 protected function getSemanticData(SMWDIWikiPage $diWikiPage, $core_props_only)
 {
     // Issue 619
     // Resolve the redirect target and return a container with information
     // about the redirect
     if ($diWikiPage->getTitle() !== null && $diWikiPage->getTitle()->isRedirect()) {
         try {
             $redirectTarget = $this->getDeepRedirectTargetResolver()->findRedirectTargetFor($diWikiPage->getTitle());
         } catch (\Exception $e) {
             $redirectTarget = null;
         }
         // Couldn't resolve the redirect which is most likely caused by a
         // circular redirect therefore we give up
         if ($redirectTarget === null) {
             return null;
         }
         $semData = new SemanticData($diWikiPage);
         $semData->addPropertyObjectValue(new DIProperty('_REDI'), DIWikiPage::newFromTitle($redirectTarget));
         return $semData;
     }
     $semdata = \SMW\StoreFactory::getStore()->getSemanticData($diWikiPage, $core_props_only ? array('__spu', '__typ', '__imp') : false);
     // advise store to retrieve only core things
     if ($core_props_only) {
         // be sure to filter all non-relevant things that may still be present in the retrieved
         $result = new SMWSemanticData($diWikiPage);
         foreach (array('_URI', '_TYPE', '_IMPO') as $propid) {
             $prop = new SMW\DIProperty($propid);
             $values = $semdata->getPropertyValues($prop);
             foreach ($values as $dv) {
                 $result->addPropertyObjectValue($prop, $dv);
             }
         }
     } else {
         $result = clone $semdata;
     }
     return $result;
 }

作者:whysass    项目:kmwik   
protected function tearDown()
 {
     StoreFactory::clear();
 }

作者:ReachingOu    项目:SemanticMediaWik   
/**
  * Find the property's type ID, either by looking up its predefined ID
  * (if any) or by retrieving the relevant information from the store.
  * If no type is stored for a user defined property, the global default
  * type will be used.
  *
  * @return string type ID
  */
 public function findPropertyTypeID()
 {
     global $smwgPDefaultType;
     if (!isset($this->m_proptypeid)) {
         if ($this->isUserDefined()) {
             // normal property
             $diWikiPage = new SMWDIWikiPage($this->getKey(), SMW_NS_PROPERTY, '');
             $typearray = StoreFactory::getStore()->getPropertyValues($diWikiPage, new self('_TYPE'));
             if (count($typearray) >= 1) {
                 // some types given, pick one (hopefully unique)
                 $typeDataItem = reset($typearray);
                 if ($typeDataItem instanceof SMWDIUri) {
                     $this->m_proptypeid = $typeDataItem->getFragment();
                 } else {
                     $this->m_proptypeid = $smwgPDefaultType;
                     // This is important. If a page has an invalid assignment to "has type", no
                     // value will be stored, so the elseif case below occurs. But if the value
                     // is retrieved within the same run, then the error value for "has type" is
                     // cached and thus this case occurs. This is why it is important to tolerate
                     // this case -- it is not necessarily a DB error.
                 }
             } elseif (count($typearray) == 0) {
                 // no type given
                 $this->m_proptypeid = $smwgPDefaultType;
             }
         } else {
             // pre-defined property
             $this->m_proptypeid = PropertyRegistry::getInstance()->getPredefinedPropertyTypeId($this->m_key);
         }
     }
     return $this->m_proptypeid;
 }


问题


面经


文章

微信
公众号

扫码关注公众号