protected function views_oai_pmh_request::parse_arguments in Views OAI-PMH 7.3
Parse the given arguments, initializing each argument's corresponding member variable if the argument is valid, or appending an error when it is not.
1 call to views_oai_pmh_request::parse_arguments()
- views_oai_pmh_request::__construct in includes/
request.inc - Constructs the object based on $_REQUEST data.
File
- includes/
request.inc, line 238 - Represents an OAI-PMH request.
Class
- views_oai_pmh_request
- Class views_oai_pmh_request.
Code
protected function parse_arguments($args, $required = array(), $optional = array()) {
$possible = array_merge($required, $optional);
// Preserve original value of every authorized tag.
foreach ($possible as $arg) {
if (isset($args[$arg])) {
$this->original_args[$arg] = $args[$arg];
}
}
// Parse resumption token.
if (isset($args['resumptionToken']) && in_array('resumptionToken', $possible)) {
if (count($args) > 1) {
$this->errors[] = new views_oai_pmh_error_exclusive_argument('resumptionToken');
}
else {
$this->resumption_token = $args['resumptionToken'];
}
// No more arguments to check since resumptionToken is exclusive.
return;
}
// Check required arguments.
foreach ($required as $arg) {
if (!isset($args[$arg])) {
$this->errors[] = new views_oai_pmh_error_missing_argument($arg);
}
}
// Check for extraneous arguments.
foreach (array_keys($args) as $arg) {
if (!in_array($arg, $possible)) {
$this->errors[] = new views_oai_pmh_error_bad_argument($arg);
// Prevent further error reports about the same argument.
unset($args[$arg]);
}
}
// Check for the 'set' argument (unsupported).
if (isset($args['set'])) {
$this->errors[] = new views_oai_pmh_error_no_set_hierarchy();
}
// Check date arguments.
$from_granularity = 0;
$until_granularity = 0;
if (isset($args['from'])) {
if (!($from_granularity = $this
->check_date_format($args['from']))) {
$this->errors[] = new views_oai_pmh_error_bad_value('from', $args['from']);
}
}
if (isset($args['until'])) {
if (!($until_granularity = $this
->check_date_format($args['until']))) {
$this->errors[] = new views_oai_pmh_error_bad_value('until', $args['until']);
}
}
if ($from_granularity && $until_granularity && $from_granularity != $until_granularity) {
$this->errors[] = new views_oai_pmh_error_bad_value('until', $args['until']);
}
else {
if ($from_granularity) {
$this->from = $args['from'];
}
if ($until_granularity) {
$this->until = $args['until'];
}
}
// Check identifier argument.
if (isset($args['identifier'])) {
$matches = array();
if (preg_match('/^' . preg_quote($this
->make_record_identifier_prefix()) . '([0-9]+)$/', $args['identifier'], $matches)) {
$this->nid = $matches[1];
}
else {
$this->errors[] = new views_oai_pmh_error_invalid_id($args['identifier']);
}
}
}