Open Journal Systems
3.3.0
|
Public Member Functions | |
addMissingMultilingualValues ($schemaName, $values, $localeKeys) | |
addPropValidationRules ($rules, $ruleKey, $propSchema) | |
coerce ($value, $type, $schema) | |
formatValidationErrors ($errorBag, $schema, $locales) | |
get ($schemaName, $forceReload=false) | |
getDefault ($propSchema, $localeParams=null, $localeKey=null) | |
getFullProps ($schemaName) | |
getLocaleDefaults ($schemaName, $locale, $localeParams) | |
getMultilingualProps ($schemaName) | |
getRequiredProps ($schemaName) | |
getSummaryProps ($schemaName) | |
getValidationRules ($schemaName, $allowedLocales) | |
merge ($baseSchema, $additionalSchema) | |
sanitize ($schemaName, $props) | |
setDefaults ($schemaName, $object, $supportedLocales, $primaryLocale, $localeParams=array()) | |
Definition at line 33 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::addMissingMultilingualValues | ( | $schemaName, | |
$values, | |||
$localeKeys | |||
) |
Add multilingual props for missing values
This method will take a set of property values and add empty entries for any locales that are missing. Given the following:
$values = [ 'title' => [ 'en_US' => 'The Journal of Public Knowledge', ] ]
If the locales en_US and fr_CA are requested, it will return the following:
$values = [ 'title' => [ 'en_US' => 'The Journal of Public Knowledge', 'fr_CA' => '', ] ]
This is primarily used to ensure API responses present a consistent data structure regardless of which properties have values.
$schemaName | string One of the SCHEMA_... constants |
$values | array Key/value list of entity properties |
$$localeKeys | array List of locale keys expected in the result |
Definition at line 568 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::addPropValidationRules | ( | $rules, | |
$ruleKey, | |||
$propSchema | |||
) |
Compile the validation rules for a single property's schema
$propSchema | object The property schema |
Definition at line 320 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::coerce | ( | $value, | |
$type, | |||
$schema | |||
) |
Coerce a value to a variable type
It will leave null values alone.
$value | mixed |
$type | string boolean, integer, number, string, array, object |
$schema | object A schema defining this property |
Definition at line 244 of file PKPSchemaService.inc.php.
References fatalError().
PKP\Services\PKPSchemaService::formatValidationErrors | ( | $errorBag, | |
$schema, | |||
$locales | |||
) |
Format validation errors
This method receives a (Laravel) MessageBag object and formats an error array to match the entity's schema. It converts Laravel's dot notation for objects and arrays:
[ foo.en_US: ['Error message'], foo.fr_CA: ['Error message'], bar.0.baz: ['Error message'], ]
Into an assoc array, collapsing subproperty errors into their parent prop:
[ foo: [ en_US: ['Error message'], fr_CA: ['Error message'], ], bar: ['Error message'], ]
$errorBag | \Illuminate\Support\MessageBag |
$schema | object The entity schema |
Definition at line 385 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::get | ( | $schemaName, | |
$forceReload = false |
|||
) |
Get a schema
$schemaName | string One of the SCHEMA_... constants |
$forceReload | boolean Optional. Compile the schema again from the source files, bypassing any cached version. |
Definition at line 52 of file PKPSchemaService.inc.php.
References BASE_SYS_DIR, HookRegistry\call(), fatalError(), and PKP\Services\PKPSchemaService\merge().
PKP\Services\PKPSchemaService::getDefault | ( | $propSchema, | |
$localeParams = null , |
|||
$localeKey = null |
|||
) |
Get a default value for a property based on the schema
$propSchema | object The schema definition for this property |
$localeParams | array\null Optional. Key/value params for the translation strings |
$localeKey | string|null Optional. The locale to translate into |
Definition at line 497 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::getFullProps | ( | $schemaName | ) |
Get all properties of a schema
Gets the complete list of properties of a schema which are considered part of the full view presented in an API.
$schemaName | string One of the SCHEMA_... constants |
Definition at line 150 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::getLocaleDefaults | ( | $schemaName, | |
$locale, | |||
$localeParams | |||
) |
Get the default values for a specific locale
$schemaName | string One of the SCHEMA_... constants |
$locale | string The locale key to get values for. Example: en_US |
$localeParams | array Key/value params for the translation strings |
Definition at line 474 of file PKPSchemaService.inc.php.
References AppLocale\requireComponents().
PKP\Services\PKPSchemaService::getMultilingualProps | ( | $schemaName | ) |
Get multilingual properties of a schema
$schemaName | string One of the SCHEMA_... constants |
Definition at line 184 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::getRequiredProps | ( | $schemaName | ) |
Get required properties of a schema
$schemaName | string One of the SCHEMA_... constants |
Definition at line 169 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::getSummaryProps | ( | $schemaName | ) |
Get the summary properties of a schema
Gets the properties of a schema which are considered part of the summary view presented in an API.
$schemaName | string One of the SCHEMA_... constants |
Definition at line 129 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::getValidationRules | ( | $schemaName, | |
$allowedLocales | |||
) |
Get the validation rules for the properties of a schema
These validation rules are returned in a format that is ready to be passed into ValidatorFactory::make().
$schemaName | string One of the SCHEMA_... constants |
$allowedLocales | array List of allowed locale keys. |
Definition at line 297 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::merge | ( | $baseSchema, | |
$additionalSchema | |||
) |
Merge two schemas
Merges the properties of two schemas, updating the title, description, and properties definitions.
If both schemas contain definitions for the same property, the property definition in the additional schema will override the base schema.
$baseSchema | object The base schema |
$additionalSchema | object The additional schema properties to apply to $baseSchema. |
Definition at line 100 of file PKPSchemaService.inc.php.
Referenced by PKP\Services\PKPSchemaService\get().
PKP\Services\PKPSchemaService::sanitize | ( | $schemaName, | |
$props | |||
) |
Sanitize properties according to a schema
This method coerces properties to their appropriate type, and strips out properties that are not specified in the schema.
$schemaName | string One of the SCHEMA_... constants |
$props | array Properties to be sanitized |
Definition at line 207 of file PKPSchemaService.inc.php.
PKP\Services\PKPSchemaService::setDefaults | ( | $schemaName, | |
$object, | |||
$supportedLocales, | |||
$primaryLocale, | |||
$localeParams = array() |
|||
) |
Set default values for an object
Get default values from an object's schema and set them for the passed object.
localeParams are used to populate translation strings where default values rely on them. For example, a locale string like the following:
"This email was sent on behalf of {$contextName}."
Will expect a $localeParams value like this:
['contextName' => 'Journal of Public Knowledge']
$schemaName | string One of the SCHEMA_... constants |
$object | DataObject The object to be modified |
$supportedLocales | array List of locale keys that shoud receive default content. Example: ['en_US', 'fr_CA'] |
$primaryLocale | string Example: en_US |
$localeParams | array Key/value params for the translation strings |
Definition at line 432 of file PKPSchemaService.inc.php.
References AppLocale\requireComponents().