本文整理汇总了PHP中PhutilTypeSpec::checkMap方法的典型用法代码示例。如果您正苦于以下问题:PHP PhutilTypeSpec::checkMap方法的具体用法?PHP PhutilTypeSpec::checkMap怎么用?PHP PhutilTypeSpec::checkMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhutilTypeSpec
的用法示例。
在下文中一共展示了PhutilTypeSpec::checkMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newFromDictionary
public static function newFromDictionary(HarbormasterBuildTarget $build_target, array $dict)
{
$obj = self::initializeNewUnitMessage($build_target);
$spec = self::getParameterSpec();
$spec = ipull($spec, 'type');
// We're just going to ignore extra keys for now, to make it easier to
// add stuff here later on.
$dict = array_select_keys($dict, array_keys($spec));
PhutilTypeSpec::checkMap($dict, $spec);
$obj->setEngine(idx($dict, 'engine', ''));
$obj->setNamespace(idx($dict, 'namespace', ''));
$obj->setName($dict['name']);
$obj->setResult($dict['result']);
$obj->setDuration((double) idx($dict, 'duration'));
$path = idx($dict, 'path');
if (strlen($path)) {
$obj->setProperty('path', $path);
}
$coverage = idx($dict, 'coverage');
if ($coverage) {
$obj->setProperty('coverage', $coverage);
}
$details = idx($dict, 'details');
if ($details) {
$obj->setProperty('details', $details);
}
return $obj;
}
示例2: executeAcquireLease
protected function executeAcquireLease(DrydockResource $resource, DrydockLease $lease)
{
// Because preallocated resources are manually created, we should verify
// we have all the information we need.
PhutilTypeSpec::checkMap($resource->getAttributesForTypeSpec(array('platform', 'host', 'port', 'credential', 'path')), array('platform' => 'string', 'host' => 'string', 'port' => 'string', 'credential' => 'string', 'path' => 'string'));
$v_platform = $resource->getAttribute('platform');
$v_path = $resource->getAttribute('path');
// Similar to DrydockLocalHostBlueprint, we create a folder
// on the remote host that the lease can use.
$lease_id = $lease->getID();
// Can't use DIRECTORY_SEPERATOR here because that is relevant to
// the platform we're currently running on, not the platform we are
// remoting to.
$separator = '/';
if ($v_platform === 'windows') {
$separator = '\\';
}
// Clean up the directory path a little.
$base_path = rtrim($v_path, '/');
$base_path = rtrim($base_path, '\\');
$full_path = $base_path . $separator . $lease_id;
$cmd = $lease->getInterface('command');
$cmd->execx('mkdir %s', $full_path);
$lease->setAttribute('path', $full_path);
}
示例3: readBookConfiguration
protected function readBookConfiguration($book_path)
{
if ($book_path === null) {
throw new PhutilArgumentUsageException('Specify a Diviner book configuration file with --book.');
}
$book_data = Filesystem::readFile($book_path);
$book = json_decode($book_data, true);
if (!is_array($book)) {
throw new PhutilArgumentUsageException("Book configuration '{$book_path}' is not in JSON format.");
}
PhutilTypeSpec::checkMap($book, array('name' => 'string', 'title' => 'optional string', 'short' => 'optional string', 'preface' => 'optional string', 'root' => 'optional string', 'uri.source' => 'optional string', 'rules' => 'optional map<regex, string>', 'exclude' => 'optional regex|list<regex>', 'groups' => 'optional map<string, map<string, wild>>'));
// If the book specifies a "root", resolve it; otherwise, use the directory
// the book configuration file lives in.
$full_path = dirname(Filesystem::resolvePath($book_path));
if (empty($book['root'])) {
$book['root'] = '.';
}
$book['root'] = Filesystem::resolvePath($book['root'], $full_path);
if (!preg_match('/^[a-z][a-z-]*\\z/', $book['name'])) {
$name = $book['name'];
throw new PhutilArgumentUsageException("Book configuration '{$book_path}' has name '{$name}', but book names " . "must include only lowercase letters and hyphens.");
}
foreach (idx($book, 'groups', array()) as $group) {
PhutilTypeSpec::checkmap($group, array('name' => 'string', 'include' => 'optional regex|list<regex>'));
}
$this->bookConfigPath = $book_path;
$this->config = $book;
}
示例4: validateOption
public function validateOption(PhabricatorConfigOption $option, $value)
{
if (!is_array($value)) {
throw new Exception(pht('Logo configuration is not valid: value must be a dictionary.'));
}
PhutilTypeSpec::checkMap($value, array('logoImagePHID' => 'optional string|null', 'wordmarkText' => 'optional string|null'));
}
示例5: validateConfiguration
public static function validateConfiguration($config)
{
if (!is_array($config)) {
throw new Exception(pht('Configuration is not valid. Maniphest points configuration must ' . 'be a dictionary.'));
}
PhutilTypeSpec::checkMap($config, array('enabled' => 'optional bool', 'label' => 'optional string', 'action' => 'optional string'));
}
示例6: buildFieldList
/**
* @task apps
*/
public static function buildFieldList($base_class, array $spec, $object, array $options = array())
{
PhutilTypeSpec::checkMap($options, array('withDisabled' => 'optional bool'));
$field_objects = id(new PhutilSymbolLoader())->setAncestorClass($base_class)->loadObjects();
$fields = array();
$from_map = array();
foreach ($field_objects as $field_object) {
$current_class = get_class($field_object);
foreach ($field_object->createFields($object) as $field) {
$key = $field->getFieldKey();
if (isset($fields[$key])) {
throw new Exception(pht("Both '%s' and '%s' define a custom field with " . "field key '%s'. Field keys must be unique.", $from_map[$key], $current_class, $key));
}
$from_map[$key] = $current_class;
$fields[$key] = $field;
}
}
foreach ($fields as $key => $field) {
if (!$field->isFieldEnabled()) {
unset($fields[$key]);
}
}
$fields = array_select_keys($fields, array_keys($spec)) + $fields;
if (empty($options['withDisabled'])) {
foreach ($fields as $key => $field) {
$config = idx($spec, $key, array()) + array('disabled' => $field->shouldDisableByDefault());
if (!empty($config['disabled'])) {
if ($field->canDisableField()) {
unset($fields[$key]);
}
}
}
}
return $fields;
}
示例7: loadDictionary
public function loadDictionary($path)
{
$root = $this->getProjectRoot();
$path = Filesystem::resolvePath($path, $root);
$dict = phutil_json_decode(Filesystem::readFile($path));
PhutilTypeSpec::checkMap($dict, array('rules' => 'map<string, map<string, string>>'));
$rules = $dict['rules'];
$this->dictionaries[] = $path;
$this->exactWordRules = array_merge($this->exactWordRules, idx($rules, 'exact', array()));
$this->partialWordRules = array_merge($this->partialWordRules, idx($rules, 'partial', array()));
}
示例8: buildTestEngines
public function buildTestEngines()
{
$working_copy = $this->getWorkingCopy();
$config_path = $working_copy->getProjectPath('.arcunit');
if (!Filesystem::pathExists($config_path)) {
throw new ArcanistUsageException(pht("Unable to find '%s' file to configure test engines. Create an " . "'%s' file in the root directory of the working copy.", '.arcunit', '.arcunit'));
}
$data = Filesystem::readFile($config_path);
$config = null;
try {
$config = phutil_json_decode($data);
} catch (PhutilJSONParserException $ex) {
throw new PhutilProxyException(pht("Expected '%s' file to be a valid JSON file, but " . "failed to decode '%s'.", '.arcunit', $config_path), $ex);
}
$test_engines = $this->loadAvailableTestEngines();
try {
PhutilTypeSpec::checkMap($config, array('engines' => 'map<string, map<string, wild>>'));
} catch (PhutilTypeCheckException $ex) {
throw new PhutilProxyException(pht("Error in parsing '%s' file.", $config_path), $ex);
}
$built_test_engines = array();
$all_paths = $this->getPaths();
foreach ($config['engines'] as $name => $spec) {
$type = idx($spec, 'type');
if ($type !== null) {
if (empty($test_engines[$type])) {
throw new ArcanistUsageException(pht("Test engine '%s' specifies invalid type '%s'. " . "Available test engines are: %s.", $name, $type, implode(', ', array_keys($test_engines))));
}
$test_engine = clone $test_engines[$type];
} else {
// We'll raise an error below about the invalid "type" key.
// TODO: Can we just do the type check first, and simplify this a bit?
$test_engine = null;
}
try {
PhutilTypeSpec::checkMap($spec, array('type' => 'string', 'include' => 'optional regex | list<regex>', 'exclude' => 'optional regex | list<regex>'));
} catch (PhutilTypeCheckException $ex) {
throw new PhutilProxyException(pht("Error in parsing '%s' file, for test engine '%s'.", '.arcunit', $name), $ex);
}
if ($all_paths) {
$include = (array) idx($spec, 'include', array());
$exclude = (array) idx($spec, 'exclude', array());
$paths = $this->matchPaths($all_paths, $include, $exclude);
$test_engine->setPaths($paths);
}
$built_test_engines[] = $test_engine;
}
return $built_test_engines;
}
示例9: validateOption
public function validateOption(PhabricatorConfigOption $option, $value)
{
if (!is_array($value)) {
throw new Exception(pht('Keyring configuration is not valid: value must be a ' . 'list of encryption keys.'));
}
foreach ($value as $index => $spec) {
if (!is_array($spec)) {
throw new Exception(pht('Keyring configuration is not valid: each entry in the list must ' . 'be a dictionary describing an encryption key, but the value ' . 'with index "%s" is not a dictionary.', $index));
}
}
$map = array();
$defaults = array();
foreach ($value as $index => $spec) {
try {
PhutilTypeSpec::checkMap($spec, array('name' => 'string', 'type' => 'string', 'material.base64' => 'string', 'default' => 'optional bool'));
} catch (Exception $ex) {
throw new Exception(pht('Keyring configuration has an invalid key specification (at ' . 'index "%s"): %s.', $index, $ex->getMessage()));
}
$name = $spec['name'];
if (isset($map[$name])) {
throw new Exception(pht('Keyring configuration is invalid: it describes multiple keys ' . 'with the same name ("%s"). Each key must have a unique name.', $name));
}
$map[$name] = true;
if (idx($spec, 'default')) {
$defaults[] = $name;
}
$type = $spec['type'];
switch ($type) {
case 'aes-256-cbc':
if (!function_exists('openssl_encrypt')) {
throw new Exception(pht('Keyring is configured with a "%s" key, but the PHP OpenSSL ' . 'extension is not installed. Install the OpenSSL extension ' . 'to enable encryption.', $type));
}
$material = $spec['material.base64'];
$material = base64_decode($material, true);
if ($material === false) {
throw new Exception(pht('Keyring specifies an invalid key ("%s"): key material ' . 'should be base64 encoded.', $name));
}
if (strlen($material) != 32) {
throw new Exception(pht('Keyring specifies an invalid key ("%s"): key material ' . 'should be 32 bytes (256 bits) but has length %s.', $name, new PhutilNumber(strlen($material))));
}
break;
default:
throw new Exception(pht('Keyring configuration is invalid: it describes a key with ' . 'type "%s", but this type is unknown.', $type));
}
}
if (count($defaults) > 1) {
throw new Exception(pht('Keyring configuration is invalid: it describes multiple default ' . 'encryption keys. No more than one key may be the default key. ' . 'Keys currently configured as defaults: %s.', implode(', ', $defaults)));
}
}
示例10: validateTransactions
public function validateTransactions($object, array $xactions)
{
$errors = array();
if (!$xactions) {
return $errors;
}
$old = mpull($object->getPaths(), 'getRef');
foreach ($xactions as $xaction) {
$new = $xaction->getNewValue();
// Check that we have a list of paths.
if (!is_array($new)) {
$errors[] = $this->newInvalidError(pht('Path specification must be a list of paths.'), $xaction);
continue;
}
// Check that each item in the list is formatted properly.
$type_exception = null;
foreach ($new as $key => $value) {
try {
PhutilTypeSpec::checkMap($value, array('repositoryPHID' => 'string', 'path' => 'string', 'excluded' => 'optional wild'));
} catch (PhutilTypeCheckException $ex) {
$errors[] = $this->newInvalidError(pht('Path specification list contains invalid value ' . 'in key "%s": %s.', $key, $ex->getMessage()), $xaction);
$type_exception = $ex;
}
}
if ($type_exception) {
continue;
}
// Check that any new paths reference legitimate repositories which
// the viewer has permission to see.
list($rem, $add) = PhabricatorOwnersPath::getTransactionValueChanges($old, $new);
if ($add) {
$repository_phids = ipull($add, 'repositoryPHID');
$repositories = id(new PhabricatorRepositoryQuery())->setViewer($this->getActor())->withPHIDs($repository_phids)->execute();
$repositories = mpull($repositories, null, 'getPHID');
foreach ($add as $ref) {
$repository_phid = $ref['repositoryPHID'];
if (isset($repositories[$repository_phid])) {
continue;
}
$errors[] = $this->newInvalidError(pht('Path specification list references repository PHID "%s", ' . 'but that is not a valid, visible repository.', $repository_phid));
}
}
}
return $errors;
}
示例11: validateOption
public function validateOption(PhabricatorConfigOption $option, $value)
{
if (!is_array($value)) {
throw new Exception(pht('Database cluster configuration is not valid: value must be a ' . 'list of database hosts.'));
}
foreach ($value as $index => $spec) {
if (!is_array($spec)) {
throw new Exception(pht('Database cluster configuration is not valid: each entry in the ' . 'list must be a dictionary describing a database host, but ' . 'the value with index "%s" is not a dictionary.', $index));
}
}
$masters = array();
$map = array();
foreach ($value as $index => $spec) {
try {
PhutilTypeSpec::checkMap($spec, array('host' => 'string', 'role' => 'string', 'port' => 'optional int', 'user' => 'optional string', 'pass' => 'optional string', 'disabled' => 'optional bool'));
} catch (Exception $ex) {
throw new Exception(pht('Database cluster configuration has an invalid host ' . 'specification (at index "%s"): %s.', $index, $ex->getMessage()));
}
$role = $spec['role'];
$host = $spec['host'];
$port = idx($spec, 'port');
switch ($role) {
case 'master':
case 'replica':
break;
default:
throw new Exception(pht('Database cluster configuration describes an invalid ' . 'host ("%s", at index "%s") with an unrecognized role ("%s"). ' . 'Valid roles are "%s" or "%s".', $spec['host'], $index, $spec['role'], 'master', 'replica'));
}
if ($role === 'master') {
$masters[] = $host;
}
// We can't guarantee that you didn't just give the same host two
// different names in DNS, but this check can catch silly copy/paste
// mistakes.
$key = "{$host}:{$port}";
if (isset($map[$key])) {
throw new Exception(pht('Database cluster configuration is invalid: it describes the ' . 'same host ("%s") multiple times. Each host should appear only ' . 'once in the list.', $host));
}
$map[$key] = true;
}
if (count($masters) > 1) {
throw new Exception(pht('Database cluster configuration is invalid: it describes multiple ' . 'masters. No more than one host may be a master. Hosts currently ' . 'configured as masters: %s.', implode(', ', $masters)));
}
}
示例12: newFromDictionary
public static function newFromDictionary(HarbormasterBuildTarget $build_target, array $dict)
{
$obj = self::initializeNewLintMessage($build_target);
$spec = array('path' => 'string', 'line' => 'optional int', 'char' => 'optional int', 'code' => 'string', 'severity' => 'string', 'name' => 'string', 'description' => 'optional string');
// We're just going to ignore extra keys for now, to make it easier to
// add stuff here later on.
$dict = array_select_keys($dict, array_keys($spec));
PhutilTypeSpec::checkMap($dict, $spec);
$obj->setPath($dict['path']);
$obj->setLine(idx($dict, 'line'));
$obj->setCharacterOffset(idx($dict, 'char'));
$obj->setCode($dict['code']);
$obj->setSeverity($dict['severity']);
$obj->setName($dict['name']);
$description = idx($dict, 'description');
if (strlen($description)) {
$obj->setProperty('description', $description);
}
return $obj;
}
示例13: execute
public function execute(PhutilArgumentParser $args)
{
$viewer = $this->getViewer();
echo tsprintf("%s\n", pht('Reading list of hints from stdin...'));
$hints = file_get_contents('php://stdin');
if ($hints === false) {
throw new PhutilArgumentUsageException(pht('Failed to read stdin.'));
}
try {
$hints = phutil_json_decode($hints);
} catch (Exception $ex) {
throw new PhutilArgumentUsageException(pht('Expected a list of hints in JSON format: %s', $ex->getMessage()));
}
$repositories = array();
foreach ($hints as $idx => $hint) {
if (!is_array($hint)) {
throw new PhutilArgumentUsageException(pht('Each item in the list of hints should be a JSON object, but ' . 'the item at index "%s" is not.', $idx));
}
try {
PhutilTypeSpec::checkMap($hint, array('repository' => 'string|int', 'old' => 'string', 'new' => 'optional string|null', 'hint' => 'string'));
} catch (Exception $ex) {
throw new PhutilArgumentUsageException(pht('Unexpected hint format at index "%s": %s', $idx, $ex->getMessage()));
}
$repository_identifier = $hint['repository'];
$repository = idx($repositories, $repository_identifier);
if (!$repository) {
$repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withIdentifiers(array($repository_identifier))->executeOne();
if (!$repository) {
throw new PhutilArgumentUsageException(pht('Repository identifier "%s" (in hint at index "%s") does not ' . 'identify a valid repository.', $repository_identifier, $idx));
}
$repositories[$repository_identifier] = $repository;
}
PhabricatorRepositoryCommitHint::updateHint($repository->getPHID(), $hint['old'], idx($hint, 'new'), $hint['hint']);
echo tsprintf("%s\n", pht('Updated hint for "%s".', $hint['old']));
}
}
示例14: validateProperties
public function validateProperties(array $properties)
{
PhutilTypeSpec::checkMap($properties, array('epoch' => 'int'));
}
示例15: addColumn
public function addColumn($key, array $column)
{
PhutilTypeSpec::checkMap($column, array('title' => 'string', 'align' => 'optional string'));
$this->columns[$key] = $column;
return $this;
}