/** * Parses the context into the arguments * @param string $condition Condition string * @param array $arguments Already set arguments * @return array Provided arguments with the resolved context arguments * @throws Exception when the context arguments could not be parsed */ public function parseContextVariables($condition, array $arguments) { if (strpos($condition, '%context') === false) { return $arguments; } $matches = array(); preg_match_all('(%context([A-Za-z0-9]|\\.)*%)', $condition, $matches); if (!$matches[0]) { throw new Exception('Could not parse context argument: no arguments matched'); } $reflectionHelper = $this->model->getReflectionHelper(); foreach ($matches[0] as $variable) { $tokens = explode('.', trim($variable, '%')); array_shift($tokens); $value = null; do { $token = array_shift($tokens); if ($value === null) { $value = $this->getContext($token); } else { $value = $reflectionHelper->getProperty($value, $token); } if ($value === null) { throw new Exception('Could not parse context arguments: ' . $variable . ' could not be resolved'); } } while ($tokens); $arguments[substr($variable, 1, -1)] = $value; } return $arguments; }
/** * Constructs a new model resource adapter * @param \ride\web\WebApplication $web Instance of the web application * @param \ride\library\orm\model\Model $model Instance of the model * @param string $type Resource type for this model, defaults to model name * @return null */ public function __construct(WebApplication $web, Model $model, $type = null) { if ($type === null) { $type = $model->getName(); } $this->web = $web; $this->model = $model; $this->reflectionHelper = $model->getReflectionHelper(); $this->type = $type; $this->filterStrategies = array(); }
/** * Gets the current field value of the entry * @param \ride\library\orm\model\Model $model * @param \ride\library\orm\definition\field\ModelField $field * @param \ride\library\orm\entry\Entry $entry * @return mixed Current field value of the entry */ protected function getCurrentValue(Model $model, ModelField $field, Entry $entry) { return $model->getReflectionHelper()->getProperty($entry, $field->getName()); }