/** * Runs the validators. * @return Errors the validation errors if any */ public function validate() { $reflection = Reflections::instance()->get(get_class($this->model)); // create array of validators to use from valid functions merged with the static properties $this->validators = array_intersect(array_keys($reflection->getStaticProperties()), self::$VALIDATION_FUNCTIONS); if (empty($this->validators)) { return $this->record; } $inflector = Inflector::instance(); foreach ($this->validators as $validate) { $func = $inflector->variablize($validate); $this->{$func}($reflection->getStaticPropertyValue($validate)); } return $this->record; }
public function __construct($class_name) { $this->class = Reflections::instance()->add($class_name)->get($class_name); // if connection name property is null the connection manager will use the default connection $connection = $this->class->getStaticPropertyValue('connection', null); $this->conn = ConnectionManager::get_connection($connection); $this->set_table_name(); $this->set_sequence_name(); $this->get_meta_data(); $this->set_primary_key(); $this->set_delegates(); $this->set_setters_and_getters(); $this->callback = new CallBack($class_name); $this->callback->register('before_save', function (Model $model) { $model->set_timestamps(); }, array('prepend' => true)); $this->callback->register('after_save', function (Model $model) { $model->reset_dirty(); }, array('prepend' => true)); }
/** * Runs the validators. * * @return Errors the validation errors if any */ public function validate() { foreach ($this->validators as $validate) { $definition = $this->klass->getStaticPropertyValue($validate); $this->{$validate}(wrap_strings_in_arrays($definition)); } $modelReflection = Reflections::instance()->get($this->model); if ($modelReflection->hasMethod('validate') && $modelReflection->getMethod('validate')->isPublic()) { $this->model->validate(); } $this->record->clearModel(); return $this->record; }
/** * Creates a CallBack. * * @param string $model_class_name The name of a {@link Model} class * @return CallBack */ public function __construct($model_class_name) { $this->klass = Reflections::instance()->get($model_class_name); foreach (static::$VALID_CALLBACKS as $name) { // look for excplitily defined static callback if ($definition = $this->klass->getStaticPropertyValue($name, null)) { if (!is_array($definition)) { $definition = array($definition); } foreach ($definition as $method_name) { $this->register($name, $method_name); } } elseif ($this->klass->hasMethod($name)) { $this->register($name, $name); } } }
public function set_date_class($date_class) { try { $klass = Reflections::instance()->add($date_class)->get($date_class); } catch (\ReflectionException $e) { throw new ConfigException("Cannot find date class"); } if (!$klass->hasMethod('format') || !$klass->getMethod('format')->isPublic()) { throw new ConfigException('Given date class must have a "public format($format = null)" method'); } if (!$klass->hasMethod('createFromFormat') || !$klass->getMethod('createFromFormat')->isPublic()) { throw new ConfigException('Given date class must have a "public static createFromFormat($format, $time)" method'); } $this->date_class = $date_class; }
/** * Sets the logger object for future SQL logging * * @param object $logger * @return void * @throws ConfigException if Logger objecct does not implement public log() */ public function set_logger($logger) { $klass = Reflections::instance()->add($logger)->get($logger); if (!$klass->getMethod('log') || !$klass->getMethod('log')->isPublic()) { throw new ConfigException("Logger object must implement a public log method"); } $this->logger = $logger; }
/** * Runs the validators. * * @return Errors the validation errors if any */ public function validate() { $reflection = Reflections::instance()->get(get_class($this->model)); foreach ($this->validators as $validate) { $this->{$validate}($reflection->getStaticPropertyValue($validate)); } $this->record->clear_model(); return $this->record; }
protected function setClassName($class_name) { if (!$this->utils->hasAbsoluteNamespace($class_name) && isset($this->options['namespace'])) { $class_name = $this->options['namespace'] . '\\' . $class_name; } $reflection = Reflections::instance()->add($class_name)->get($class_name); if (!$reflection->isSubClassOf('Activerecord\\Model')) { throw new ExceptionRelationship("'{$class_name}' must extend from Activerecord\\Model"); } $this->class_name = $class_name; }
/** * Sets the logger object for future SQL logging * * @param object $logger * @return void * @throws ConfigException if Logger objecct does not implement public log() */ public function setLogger($logger) { $reflect = Reflections::instance()->add($logger)->get($logger); /* if (!$reflect->getMethod('log') || !$reflect->getMethod('log')->isPublic()) { throw new ExceptionConfig("Logger object must implement a public log method"); } * */ if (!$reflect->getMethod('debug') || !$reflect->getMethod('debug')->isPublic()) { throw new ExceptionConfig("Logger object must implement a public debug method"); } $this->logger = $logger; }
public function __construct($class_name) { $this->class = Reflections::instance()->add($class_name)->get($class_name); $this->reestablishConnection(false); $this->setTableName(); $this->getMetaData(); $this->setPrimaryKey(); $this->setSequenceName(); $this->setDelegates(); $this->setCache(); $this->setSettersAndGetters(); $this->callback = new CallBack($class_name); $this->callback->register('before_save', function (Model $model) { $model->setTimestamps(); }, ['prepend' => true]); $this->callback->register('after_save', function (Model $model) { $model->resetDirty(); }, ['prepend' => true]); }
/** * Creates a CallBack. * * @param string $model_class_name The name of a {@link Model} class * @return CallBack */ public function __construct($model_class_name) { $this->reflect = Reflections::instance()->get($model_class_name); foreach (static::$valid_callbacks as $name) { // look for explicitly defined static callback if ($definition = $this->reflect->getStaticPropertyValue($name, null)) { if (!\is_array($definition)) { $definition = [$definition]; } foreach ($definition as $method_name) { $this->register($name, $method_name); } } elseif ($this->reflect->hasMethod($name)) { $this->register($name, $name); } } }