40if ( ! defined(
'XCUBE_CORE_PATH' ) ) {
41 define(
'XCUBE_CORE_PATH', __DIR__ );
44require_once XCUBE_CORE_PATH .
'/XCube_Root.class.php';
46require_once XCUBE_CORE_PATH .
'/XCube_Property.class.php';
47require_once XCUBE_CORE_PATH .
'/XCube_Validator.class.php';
48require_once XCUBE_CORE_PATH .
'/XCube_FormFile.class.php';
110 $root =& XCube_Root::getSingleton();
111 $this->mContext =& $root->getContext();
112 $this->mUser =& $this->mContext->getUser();
144 if (
null === $this->_mToken ) {
145 mt_srand( (
int) (microtime(
true ) * 100000) );
146 $root =& XCube_Root::getSingleton();
147 $salt = $root->getSiteConfig(
'Cube',
'Salt' );
148 $this->_mToken = md5( $salt . uniqid( random_int(0, mt_getrandmax()),
true ) );
183 public function set() {
184 if ( isset( $this->mFormProperties[ func_get_arg( 0 ) ] ) ) {
185 if ( func_num_args() === 2 ) {
186 $value = func_get_arg( 1 );
187 $this->mFormProperties[ func_get_arg( 0 ) ]->setValue( $value );
188 } elseif ( func_num_args() === 3 ) {
189 $index = func_get_arg( 1 );
190 $value = func_get_arg( 2 );
191 $this->mFormProperties[ func_get_arg( 0 ) ]->setValue( $index, $value );
200 if ( isset( $this->mFormProperties[ func_get_arg( 0 ) ] ) ) {
201 if ( func_num_args() === 2 ) {
202 $this->mFormProperties[ func_get_arg( 0 ) ]->setValue( func_get_arg( 1 ) );
203 } elseif ( func_num_args() === 3 ) {
204 $this->mFormProperties[ func_get_arg( 0 ) ]->setValue( func_get_arg( 1 ), func_get_arg( 2 ) );
222 public function get( $key, $index = null ) {
223 return isset( $this->mFormProperties[ $key ] ) ? $this->mFormProperties[ $key ]->getValue( $index ) :
null;
233 public function getVar( $key, $index =
null ) {
234 return $this->
get( $key, $index );
268 foreach ( array_keys( $this->mFormProperties ) as $name ) {
269 if ( $this->mFormProperties[ $name ]->hasFetchControl() ) {
270 $this->mFormProperties[ $name ]->fetch( $this );
272 $value = $this->mContext->mRequest->getRequest( $name );
273 $this->mFormProperties[ $name ]->set( $value );
275 $methodName =
'fetch' . ucfirst( $name );
276 if ( method_exists( $this, $methodName ) ) {
278 $this->$methodName();
299 $token = $_REQUEST[ $key ] ??
null;
303 if ( ! isset( $_SESSION[
'XCUBE_TOKEN'][ $this->
getTokenName() ] ) ) {
305 } elseif ( $_SESSION[
'XCUBE_TOKEN'][ $this->
getTokenName() ] != $token ) {
306 unset( $_SESSION[
'XCUBE_TOKEN'][ $this->
getTokenName() ] );
312 if (
null === $message ) {
313 $this->mErrorFlag =
true;
322 unset( $_SESSION[
'XCUBE_TOKEN'][ $this->
getTokenName() ] );
347 foreach ( array_keys( $this->mFormProperties ) as $name ) {
348 if ( isset( $this->mFieldProperties[ $name ] ) ) {
349 if ( $this->mFormProperties[ $name ]->isArray() ) {
350 foreach ( array_keys( $this->mFormProperties[ $name ]->mProperties ) as $_name ) {
351 $this->mFieldProperties[ $name ]->validate( $this->mFormProperties[ $name ]->mProperties[ $_name ] );
354 $this->mFieldProperties[ $name ]->validate( $this->mFormProperties[ $name ] );
362 foreach ( array_keys( $this->mFormProperties ) as $name ) {
363 $methodName =
'validate' . ucfirst( $name );
364 if ( method_exists( $this, $methodName ) ) {
366 $this->$methodName();
377 return ( count( $this->mErrorMessages ) > 0 || $this->mErrorFlag );
387 $this->mErrorMessages[] = $message;
413 public function load( &$obj ) {
489 $this->mForm =& $form;
501 foreach ( $dependsArr as $dependName ) {
503 if (
null !== $instance ) {
504 $this->mDepends[ $dependName ] =& $instance;
528 if ( func_num_args() >= 2 ) {
529 $args = func_get_args();
530 $this->mMessages[ $args[0] ][
'message'] = $args[1];
531 for ( $i = 0; isset( $args[ $i + 2 ] ); $i ++ ) {
532 $this->mMessages[ $args[0] ][
'args'][ $i ] = $args[ $i + 2 ];
556 if ( ! isset( $this->mMessages[ $name ] ) ) {
560 $message = $this->mMessages[ $name ][
'message'];
562 if ( isset( $this->mMessages[ $name ][
'args'] ) ) {
583 public function addVar( $name, $value ) {
584 $this->mVariables[ $name ] = $value;
599 if ( is_array( $this->mDepends ) && count( $this->mDepends ) > 0 ) {
600 foreach ( $this->mDepends as $name => $depend ) {
601 if ( ! $depend->isValid( $form, $this->mVariables ) ) {
604 $this->mForm->mErrorFlag =
true;
607 $this->mForm->addErrorMessage( $this->
renderMessage( $name ) );
640 if ( ! is_array( $_cache ) ) {
644 if ( ! isset( $_cache[ $dependName ] ) ) {
646 $class_name =
'XCube_' . ucfirst( $dependName ) .
'Validator';
647 if ( XC_CLASS_EXISTS( $class_name ) ) {
648 $_cache[ $dependName ] =
new $class_name();
651 die(
"This is an error message of Alpha or Beta series. {$dependName} Validator is not found." );
655 return $_cache[ $dependName ];
static & factoryClass(string $dependName)
[Abstract] Used for validating member property values of XCube_ActionForm.
$mVariables
Hash-Map Array - std::map<string, mixed>
setDependsByArray( $dependsArr)
Initializes the list of validators for this field property with the list of dependency rule names.
validate(&$form)
Validates the form property with the validators that the field's property contains.
addVar( $name, $value)
Adds a virtual variable used by validators.
$mForm
XCube_ActionForm - Parent form contains this field property.
addMessage( $name, $message)
Adds an error message that will be used if the validation of the "$name" rule fails.
renderMessage(string $name)
Gets the error message rendered by XCube_Utils::formaString().
__construct(&$form)
Constructor.
$mDepends
XCube_Validator[] - std::map<string, XCube_Validator*>
static formatString()
[Static] Formats string with special care for international.