22 protected static $key =
'contents/validators/';
29 if (isset ( self::$cache )) {
31 if (self::$cache->exists (
$key )) {
32 return self::$cache->fetch (
$key );
38 protected static function getHash($class) {
39 return \hash (
'sha1', $class );
43 return self::$key . \str_replace (
'\\', \DS, $classname );
46 protected static function store($model, $validators) {
47 CacheManager::$cache->store ( self::getModelCacheKey ( $model ), $validators,
'validators' );
50 protected static function fetch($model) {
52 if (CacheManager::$cache->exists (
$key )) {
53 return CacheManager::$cache->fetch (
$key );
58 public static function clearCache($model =
null, $group =
'') {
59 if (isset ( self::$cache )) {
60 if (isset ( $model )) {
62 self::$cache->remove (
$key );
64 self::$cache->clear ();
71 $types = \array_flip ( self::$validatorTypes );
72 foreach ( $members as $accessor => $validators ) {
73 foreach ( $validators as $validatorInstance ) {
74 $typeV = $types [get_class ( $validatorInstance )];
75 if (! isset ( $excludedValidators [$typeV] )) {
76 $valid = $validatorInstance->validate_ ( $instance->$accessor () );
77 if ($valid !==
true) {
88 $types = \array_flip ( self::$validatorTypes );
89 foreach ( $members as $accessor => $validators ) {
90 $member = \lcfirst ( \ltrim (
'get', $accessor ) );
91 foreach ( $validators as $validatorInstance ) {
92 $typeV = $types [get_class ( $validatorInstance )];
93 if (! isset ( $excludedValidators [$typeV] )) {
94 $result [$member] += $validatorInstance->asUI ();
108 $class = \get_class ( $instance );
114 $class = \get_class ( $instance );
116 foreach ( $members as $member => $validators ) {
117 $accessor =
'get' . \ucfirst ( $member );
118 if (\method_exists ( $instance, $accessor )) {
119 foreach ( $validators as $validator ) {
121 if ($validatorInstance !==
false) {
122 $validatorInstance->setValidationParameters ( $member, $validator [
'constraints'] ?? [ ], $validator [
'severity'] ??
null, $validator [
'message'] ??
null);
123 if ($group ===
'' || (isset ( $validator [
'group'] ) && $validator [
'group'] === $group)) {
124 self::$instanceValidators [$class] [$accessor] [] = $validatorInstance;
125 $result [$accessor] [] = $validatorInstance;
131 self::$cache->store ( self::getHash ( $class . $group ), $result );
135 if (isset ( self::$validatorTypes [$type] )) {
136 $class = self::$validatorTypes [$type];
137 return new $class ();
139 Logger::warn (
'validation',
"Validator $type does not exists!" );
Manager for caches (Router, Rest, models).
static getModelCacheKey($classname)
static initInstancesValidators($instance, $members, $group='')
static getCacheValidators($instance, $group='')
static getUIConstraintsFromCache_($instance, $members, $excludedValidators=[])
static initCacheInstanceValidators($instance, $group='')
Initializes the cache (SessionCache) for the class of instance.
static store($model, $validators)
static clearCache($model=null, $group='')
static validateFromCache_($instance, $members, $excludedValidators=[])
static getValidatorInstance($type)
static getClassCacheValidators($class, $group='')
Abstract class for logging Ubiquity\log$Logger This class is part of Ubiquity.