78 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
79 $this->ContextUtilities =
get_package(
'gui::context::context_utilities' ,
'last' , __FILE__ );
80 $this->CustomValidations =
get_package(
'gui::context::custom_validations' ,
'last' , __FILE__ );
81 $this->Messages =
get_package(
'page::messages' ,
'last' , __FILE__ );
82 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
83 $this->SecurityValidator =
get_package(
'security::security_validator' ,
'last' , __FILE__ );
84 $this->Trace =
get_package(
'trace' ,
'last' , __FILE__ );
114 $Tmp = $this->CachedMultyFS->file_get_contents( $ConfigFilePath );
117 catch( Exception $e )
153 $Hint = $Options->get_setting(
'context' ,
false );
155 if( $Hint !==
false &&
in_array( $Hint , $Contexts ) )
161 throw(
new Exception(
'Config was not hinted' ) );
164 catch( Exception $e )
192 if( $this->Settings ===
false )
196 $this->Settings->load_settings(
$Config );
197 $this->Config = $this->Settings->get_raw_settings();
199 catch( Exception $e )
227 $this->Config =
$Config->get_raw_settings();
229 catch( Exception $e )
261 if( $this->ContextUtilities->section_exists( $this->Config ,
'call_params_filter' ) )
263 $Filter = $this->ContextUtilities->get_section( $this->Config ,
'call_params_filter' );
264 if( $this->SecurityValidator->validate_custom_fields( $Options->get_raw_settings() ,
265 $Filter ) ===
false )
267 $this->Trace->add_trace_string(
268 "{lang:call_params_filter_not_passed} : $Filter" , COMMON
276 catch( Exception $e )
308 $this->PermitAlgorithms =
get_package(
'permit::permit_algorithms' ,
'last' , __FILE__ );
310 if( $this->ContextUtilities->section_exists( $this->Config ,
'permits_filter' ) )
312 $Filter = $this->ContextUtilities->get_section( $this->Config ,
'permits_filter' );
314 if( $this->PermitAlgorithms->fetch_permits_for_object(
false ,
'user' , $Filter ) === false )
316 $this->Trace->add_trace_string(
"{lang:permits_filter_not_passed} : $Filter" , COMMON );
323 catch( Exception $e )
355 if( $this->ContextUtilities->section_exists( $this->Config ,
'permits_validation' ) )
357 $Validation = $this->ContextUtilities->get_section( $this->Config ,
'permits_validation' );
359 if( $this->PermitAlgorithms->fetch_permits_for_object(
false ,
'user' , $Validation ) === false )
361 $this->Trace->add_trace_string(
362 "{lang:permits_validation_was_not_passed} : $Validation" , COMMON
365 $this->ContextUtilities->compile_no_permits( $Validation );
372 catch( Exception $e )
404 if( $this->ContextUtilities->section_exists( $this->Config ,
'custom_validation' ) )
406 $CustomValidation = $this->ContextUtilities->get_section( $this->Config ,
'custom_validation' );
408 if( $this->CustomValidations->custom_validation( $CustomValidation , $Options ) === false )
410 $TraceString =
"{lang:custom_validation_not_passed} : $CustomValidation";
412 $this->Trace->add_trace_string( $TraceString , COMMON );
420 catch( Exception $e )
448 private function compile_custom_validation_func( &$Options )
452 if( $this->ContextUtilities->section_exists( $this->Config ,
'custom_validation_func' ) )
454 $ValidationObject = $this->ContextUtilities->get_custom_validation_object( $this->Config );
456 $Func = $this->ContextUtilities->get_section( $this->Config ,
'custom_validation_func' );
458 if( call_user_func( array( $ValidationObject , $Func ) , $Options ) ===
false )
460 $TraceString =
"{lang:custom_validation_func_not_passed} : $Func";
462 $this->Trace->add_trace_string( $TraceString , COMMON );
470 catch( Exception $e )
502 $Func = $this->ContextUtilities->get_section( $this->Config ,
'error_func' ,
false );
503 if( $Func ===
false )
505 $ErrMsg = $this->SecurityValidator->get_error_message();
506 $ErrMsg = $ErrMsg ===
'' ?
'an_error_occured' : $ErrMsg;
507 $this->Messages->add_error_message( $ErrMsg );
508 $this->Trace->add_trace_string(
"{lang:_std_error_message} : ".$ErrMsg , COMMON );
512 $FuncBody =
'return( $Owner->'.$Func.
'( $Options ) );';
513 $NewFunc = create_function(
'$OwnerObject , $Options' , $FuncBody );
514 $NewFunc( $Owner , $Options );
518 catch( Exception $e )
550 if( method_exists( $Owner , $Func ) ===
false )
552 throw(
new Exception(
"Method \"$Func\" was not found in class ".get_class( $Owner ) ) );
555 catch( Exception $e )
575 private function cleanup_fields()
579 if( $this->ContextUtilities->section_exists( $this->Config ,
'cleanup_fields' ) )
581 $Items = explode(
',' , $this->ContextUtilities->get_section(
582 $this->Config ,
'cleanup_fields' )
584 foreach( $Items as $key => $value )
586 $this->Security->reset_p( $value ,
'' );
590 catch( Exception $e )
628 $FunctionBody =
'return( $OwnerObject->'.$Func.
'( $Options ) );';
629 $NewFunc = create_function(
'$OwnerObject , $Options' , $FunctionBody );
631 $this->Trace->add_trace_string(
"{lang:calling_method} ".get_class( $Owner ).
"->$Func" , COMMON );
633 if( $NewFunc( $Owner , $Options ) !==
false )
635 $this->cleanup_fields();
638 catch( Exception $e )
670 private function run_success_function( &$Options , &$Owner )
674 $Func = $this->ContextUtilities->get_section( $this->Config ,
'success_func' ,
'_std_redirect' );
676 if( $Func ===
'_std_redirect' )
678 $Url = $this->ContextUtilities->get_section( $this->Config ,
'redirect_url' ,
false );
682 $FunctionBody =
'return( _std_redirect( "'.$Url.
'" , $OwnerObject ) );';
684 $NewFunc = create_function(
'$OwnerObject' , $FunctionBody );
694 $this->ContextUtilities->compile_success_messages( $Options );
696 catch( Exception $e )
724 private function run_filters( &$Options )
733 if( $this->ContextUtilities->compile_get_post_filter( $this->Config , $Options ) === false )
745 catch( Exception $e )
777 private function run_execution( &$Options , &$Owner )
781 if( $this->run_filters( $Options , $Owner ) ===
false ||
787 if( $this->ContextUtilities->compile_get_post_validation( $this->Config , $Options ) )
790 $this->compile_custom_validation_func( $Options ) === false )
795 $this->run_success_function( $Options , $Owner );
802 catch( Exception $e )
838 $this->Trace->start_group(
"Context::execute for class \"".get_class( $Owner ).
"\"" );
840 $Result = $this->run_execution( $Options , $Owner );
841 $Msg =
'{lang:'.( $Result ?
'state_was_processed' :
'state_was_not_processed' ).
'}';
842 $this->Trace->add_trace_string( $Msg , COMMON );
843 $this->Trace->end_group();
846 catch( Exception $e )