/**
  * @param callable[] $factoryFunctions An associative array mapping types to factory
  * functions. Type names must use the "PT:" prefix for property types (data types),
  * and "VT:" for value types, to be compatible with the convention used by
  * DispatchingValueFormatter.
  * The factory functions will be called with two parameters, the desired target
  * type (see the SnakFormatter::FORMAT_XXX constants) and a FormatterOptions object.
  * The factory function must return an instance of ValueFormatter suitable for the given target
  * format, or null if no formatter for the requested target format is known.
  *
  * @param Language $defaultLanguage
  * @param LanguageFallbackChainFactory $fallbackChainFactory
  */
 public function __construct(array $factoryFunctions, Language $defaultLanguage, LanguageFallbackChainFactory $fallbackChainFactory)
 {
     Assert::parameterElementType('callable', $factoryFunctions, '$factoryFunctions');
     $this->factoryFunctions = $factoryFunctions;
     $this->defaultLanguage = $defaultLanguage;
     $this->languageFallbackChainFactory = $fallbackChainFactory;
 }
 /**
  * @param callable[] $snakFormatterConstructorCallbacks An associative array mapping property
  *        data type IDs to callbacks. The callbacks will be invoked with two parameters: the
  *        desired output format, and the FormatterOptions. Each callback must return an
  *        instance of SnakFormatter.
  * @param OutputFormatValueFormatterFactory $valueFormatterFactory
  * @param PropertyDataTypeLookup $propertyDataTypeLookup
  * @param DataTypeFactory $dataTypeFactory
  */
 public function __construct(array $snakFormatterConstructorCallbacks, OutputFormatValueFormatterFactory $valueFormatterFactory, PropertyDataTypeLookup $propertyDataTypeLookup, DataTypeFactory $dataTypeFactory)
 {
     Assert::parameterElementType('callable', $snakFormatterConstructorCallbacks, '$snakFormatterConstructorCallbacks');
     $this->snakFormatterConstructorCallbacks = $snakFormatterConstructorCallbacks;
     $this->valueFormatterFactory = $valueFormatterFactory;
     $this->propertyDataTypeLookup = $propertyDataTypeLookup;
     $this->dataTypeFactory = $dataTypeFactory;
 }
 /**
  * Adds data type definitions. The new definitions are merged with the existing definitions.
  * If a data type in $dataTypeDefinitions was already defined, the old definition is not
  * replaced but the definitions are merged.
  *
  * @param array[] $dataTypeDefinitions An associative array mapping property data type ids
  * (with the prefix "PT:") and value types (with the prefix "VT:") to data type definitions.
  * Each data type definitions are associative arrays, refer to the class level documentation
  * for details.
  */
 public function registerDataTypes(array $dataTypeDefinitions)
 {
     Assert::parameterElementType('array', $dataTypeDefinitions, '$dataTypeDefinitions');
     foreach ($dataTypeDefinitions as $id => $def) {
         Assert::parameter(strpos($id, ':'), "\$dataTypeDefinitions[{$id}]", 'Key must start with a prefix like "PT:" or "VT:".');
         if (isset($this->dataTypeDefinitions[$id])) {
             $this->dataTypeDefinitions[$id] = array_merge($this->dataTypeDefinitions[$id], $dataTypeDefinitions[$id]);
         } else {
             $this->dataTypeDefinitions[$id] = $dataTypeDefinitions[$id];
         }
     }
 }
 /**
  * @param Title $title
  * @param array $params
  */
 public function __construct(Title $title, array $params)
 {
     parent::__construct('wikibase-addUsagesForPage', $title, $params);
     Assert::parameter(isset($params['pageId']) && is_int($params['pageId']) && $params['pageId'] > 0, '$params["pageId"]', 'must be a positive integer');
     Assert::parameter(isset($params['usages']) && is_array($params['usages']) && !empty($params['usages']), '$params["usages"]', 'must be a non-empty array');
     Assert::parameter(isset($params['touched']) && is_string($params['touched']) && $params['touched'] !== '', '$params["touched"]', 'must be a timestamp string');
     Assert::parameterElementType('array', $params['usages'], '$params["usages"]');
     $this->pageId = $params['pageId'];
     $this->usages = $params['usages'];
     $this->touched = $params['touched'];
     $wikibaseClient = WikibaseClient::getDefaultInstance();
     $usageUpdater = $wikibaseClient->getStore()->getUsageUpdater();
     $idParser = $wikibaseClient->getEntityIdParser();
     $this->overrideServices($usageUpdater, $idParser);
 }
Пример #5
0
 public function testParameterElementType_bad()
 {
     $this->setExpectedException('Wikimedia\\Assert\\ParameterTypeException');
     Assert::parameterElementType('string', 'foo', 'test');
 }
 /**
  * @param EntityChangeFactory $changeFactory
  * @param ChangeTransmitter[] $changeTransmitters
  */
 public function __construct(EntityChangeFactory $changeFactory, array $changeTransmitters)
 {
     Assert::parameterElementType('Wikibase\\Repo\\Notifications\\ChangeTransmitter', $changeTransmitters, '$changeTransmitters');
     $this->changeFactory = $changeFactory;
     $this->changeTransmitters = $changeTransmitters;
 }
 /**
  * @param callable[] $factoryCallbacks Factory callback functions as returned by
  *        DataTypeDefinitions::getRdfBuilderFactoryCallbacks(). Callbacks will be invoked
  *        with the signature ($mode, RdfVocabulary, EntityMentionListener) and must
  *        return a ValueSnakRdfBuilder (or null).
  */
 public function __construct(array $factoryCallbacks)
 {
     Assert::parameterElementType('callable', $factoryCallbacks, '$factoryCallbacks');
     $this->factoryCallbacks = $factoryCallbacks;
 }
 /**
  * @param int[] $ids
  *
  * @return Change[]
  */
 public function loadByChangeIds($ids)
 {
     Assert::parameterElementType('integer', $ids, '$ids');
     return $this->loadChanges(array('change_id' => $ids), array(), __METHOD__);
 }
Пример #9
0
 /**
  * Registers multiple services (aka a "wiring").
  *
  * @param array $serviceInstantiators An associative array mapping service names to
  *        instantiator functions.
  */
 public function applyWiring(array $serviceInstantiators)
 {
     Assert::parameterElementType('callable', $serviceInstantiators, '$serviceInstantiators');
     foreach ($serviceInstantiators as $name => $instantiator) {
         $this->defineService($name, $instantiator);
     }
 }
 /**
  * @param ValueSnakRdfBuilder[] $valueBuilders ValueSnakRdfBuilder objects keyed by data type
  * (with prefix "PT:") or value type (with prefix "VT:").
  */
 public function __construct(array $valueBuilders)
 {
     Assert::parameterElementType('Wikibase\\Rdf\\ValueSnakRdfBuilder', $valueBuilders, '$valueBuilders');
     $this->valueBuilders = $valueBuilders;
 }
 /**
  * @param callable[] $validatorBuilders
  */
 public function __construct(array $validatorBuilders)
 {
     Assert::parameterElementType('callable', $validatorBuilders, '$validatorBuilders');
     $this->validatorBuilders = $validatorBuilders;
 }