idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
16,200
public function isLanguageIncludedInRoutes ( $ state = null ) { if ( isset ( $ state ) ) { $ this -> languageIncludedInRoutes = ( bool ) $ state ; } return $ this -> languageIncludedInRoutes ; }
Determine if languages are included in a route .
16,201
protected function applyCallback ( stdClass $ schema ) : stdClass { if ( is_callable ( $ this -> callback ) ) { $ result = call_user_func_array ( $ this -> callback , [ Convert :: objectToArray ( $ schema ) ] ) ; if ( is_null ( $ result ) ) { throw new InvalidArgumentException ( 'Callback returned `null`. Did you forget to `return $schema;`?' ) ; } if ( $ result !== false ) { return Convert :: arrayToObject ( $ result ) ; } } return $ schema ; }
Apply the optional callback .
16,202
public function checkFieldsActivation ( ) { foreach ( $ this -> getFormObject ( ) -> getConfiguration ( ) -> getFields ( ) as $ field ) { if ( false === $ this -> result -> fieldIsDeactivated ( $ field ) ) { $ this -> checkFieldActivation ( $ field ) ; } } return $ this ; }
This function will take care of deactivating the validation for fields that do not match their activation condition .
16,203
public function addCache ( CacheInterface $ cache ) { $ this -> cacheMap [ $ cache -> getName ( ) ] = $ cache ; $ this -> cacheNames [ ] = $ cache -> getName ( ) ; }
Adds a Cache
16,204
public function query ( $ cql , array $ values = [ ] , $ consistency = ConsistencyEnum :: CONSISTENCY_QUORUM ) { if ( $ this -> batchQuery && in_array ( substr ( $ cql , 0 , 6 ) , [ 'INSERT' , 'UPDATE' , 'DELETE' ] ) ) { $ this -> appendQueryToStack ( $ cql , $ values ) ; return true ; } if ( empty ( $ values ) ) { $ response = $ this -> connection -> sendRequest ( RequestFactory :: query ( $ cql , $ consistency ) ) ; } else { $ response = $ this -> connection -> sendRequest ( RequestFactory :: prepare ( $ cql ) ) ; $ responseType = $ response -> getType ( ) ; if ( $ responseType !== OpcodeEnum :: RESULT ) { throw new QueryException ( $ response -> getData ( ) ) ; } else { $ preparedData = $ response -> getData ( ) ; } $ response = $ this -> connection -> sendRequest ( RequestFactory :: execute ( $ preparedData , $ values , $ consistency ) ) ; } if ( $ response -> getType ( ) === OpcodeEnum :: ERROR ) { throw new CassandraException ( $ response -> getData ( ) ) ; } else { $ data = $ response -> getData ( ) ; if ( $ data instanceof Rows ) { return $ data -> asArray ( ) ; } } return ! empty ( $ data ) ? $ data : $ response -> getType ( ) === OpcodeEnum :: RESULT ; }
Send query into database
16,205
protected function getFormzConfiguration ( ) { $ rootConfigurationArray = $ this -> getFormObject ( ) -> getConfiguration ( ) -> getRootConfiguration ( ) -> toArray ( ) ; $ cleanFormzConfigurationArray = [ 'view' => $ rootConfigurationArray [ 'view' ] ] ; return ArrayService :: get ( ) -> arrayToJavaScriptJson ( $ cleanFormzConfigurationArray ) ; }
Returns a JSON array containing the FormZ configuration .
16,206
private function setDefaultConfiguration ( ) : void { $ this -> parameterBag -> set ( 'app.devmode' , false ) ; $ this -> parameterBag -> set ( 'container.dumper.inline_class_loader' , true ) ; $ this -> config -> addPass ( $ this -> parameterBag ) ; }
Configures the default parameters and appends the handler
16,207
public function dump ( ) { $ methods = $ this -> specification -> getMethods ( ) ; $ result = '<?php/* * This file is part of PHP Selenium Library. * (c) Alexandre Salomé <alexandre.salome@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */namespace Selenium;/** * Browser class containing all methods of Selenium Server, with documentation. * * This class was generated, do not modify it. * * @author Alexandre Salomé <alexandre.salome@gmail.com> */class GeneratedBrowser extends BaseBrowser{' ; foreach ( $ methods as $ method ) { $ result .= $ this -> dumpMethod ( $ method ) . "\n\n" ; } $ result .= "}" ; return $ result ; }
Dumps to source code
16,208
protected function dumpMethod ( Method $ method ) { $ builder = new MethodBuilder ( ) ; $ documentation = $ method -> getDescription ( ) . "\n\n" ; $ signature = array ( ) ; foreach ( $ method -> getParameters ( ) as $ parameter ) { $ builder -> addParameter ( $ parameter -> getName ( ) ) ; $ documentation .= "@param string $" . $ parameter -> getName ( ) . " " . $ parameter -> getDescription ( ) . "\n\n" ; $ signature [ ] = '$' . $ parameter -> getName ( ) ; } $ signature = implode ( ', ' , $ signature ) ; if ( $ method -> isAction ( ) ) { $ documentation .= '@return \Selenium\Browser Fluid interface' ; $ body = '$this->driver->action("' . $ method -> getName ( ) . '"' . ( $ signature ? ', ' . $ signature : '' ) . ');' . "\n" ; $ body .= "\n" ; $ body .= "return \$this;" ; } else { $ returnType = $ method -> getReturnType ( ) ; if ( $ returnType === 'boolean' ) { $ getMethod = 'getBoolean' ; } elseif ( $ returnType === 'string' ) { $ getMethod = 'getString' ; } elseif ( $ returnType === 'string[]' ) { $ getMethod = 'getStringArray' ; } elseif ( $ returnType === 'number' ) { $ getMethod = 'getNumber' ; $ returnType = 'integer' ; if ( 0 === strpos ( $ method -> getReturnDescription ( ) , 'of ' ) ) { $ returnType .= ' number' ; } } $ documentation .= '@return ' . $ returnType . ' ' . $ method -> getReturnDescription ( ) ; $ body = 'return $this->driver->' . $ getMethod . '("' . $ method -> getName ( ) . '"' . ( $ signature ? ', ' . $ signature : '' ) . ');' ; } $ builder -> setName ( $ method -> getName ( ) ) ; $ builder -> setBody ( $ body ) ; $ builder -> setDocumentation ( $ documentation ) ; return $ builder -> buildCode ( ) ; }
Dumps a method .
16,209
private function createCache ( array $ config , ContainerBuilder $ container ) { $ type = $ config [ 'type' ] ; if ( array_key_exists ( $ type , $ this -> cacheFactories ) ) { $ id = sprintf ( 'tbbc_cache.%s_cache' , $ config [ 'name' ] ) ; $ this -> cacheFactories [ $ type ] -> create ( $ container , $ id , $ config ) ; return $ id ; } }
Creates a single cache service
16,210
private function createCacheFactories ( ) { if ( null !== $ this -> cacheFactories ) { return $ this -> cacheFactories ; } $ tempContainer = new ContainerBuilder ( ) ; $ loader = new Loader \ XmlFileLoader ( $ tempContainer , new FileLocator ( __DIR__ . '/../Resources/config' ) ) ; $ loader -> load ( 'cache_factories.xml' ) ; $ cacheFactories = array ( ) ; foreach ( $ tempContainer -> findTaggedServiceIds ( 'tbbc_cache.cache_factory' ) as $ id => $ factories ) { foreach ( $ factories as $ factory ) { if ( ! isset ( $ factory [ 'cache_type' ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Service "%s" must define a "cache_type" attribute for "tbbc_cache.cache_factory" tag' , $ id ) ) ; } $ factoryService = $ tempContainer -> get ( $ id ) ; $ cacheFactories [ str_replace ( '-' , '_' , strtolower ( $ factory [ 'cache_type' ] ) ) ] = $ factoryService ; } } return $ this -> cacheFactories = $ cacheFactories ; }
Creates the cache factories
16,211
public function sanitizeValidatorResult ( Result $ result , $ validationName ) { $ newResult = new Result ; $ this -> sanitizeValidatorResultMessages ( 'error' , $ result -> getFlattenedErrors ( ) , $ newResult , $ validationName ) ; $ this -> sanitizeValidatorResultMessages ( 'warning' , $ result -> getFlattenedWarnings ( ) , $ newResult , $ validationName ) ; $ this -> sanitizeValidatorResultMessages ( 'notice' , $ result -> getFlattenedNotices ( ) , $ newResult , $ validationName ) ; return $ newResult ; }
This function will go through all errors warnings and notices and check if they are instances of FormzMessageInterface . If not they are converted in order to have more informations that are needed later .
16,212
public function filterMessages ( array $ messages , array $ supportedMessages , $ canCreateNewMessages = false ) { $ addValueToArray = function ( array & $ a ) { foreach ( $ a as $ k => $ v ) { if ( false === isset ( $ v [ 'value' ] ) ) { $ a [ $ k ] [ 'value' ] = '' ; } if ( false === isset ( $ v [ 'extension' ] ) ) { $ a [ $ k ] [ 'extension' ] = '' ; } } return $ a ; } ; $ messagesArray = [ ] ; foreach ( $ messages as $ key => $ message ) { if ( $ message instanceof FormzMessage ) { $ message = $ message -> toArray ( ) ; } $ messagesArray [ $ key ] = $ message ; } $ addValueToArray ( $ messagesArray ) ; $ addValueToArray ( $ supportedMessages ) ; $ messagesResult = $ supportedMessages ; ArrayUtility :: mergeRecursiveWithOverrule ( $ messagesResult , $ messagesArray , ( bool ) $ canCreateNewMessages ) ; return $ messagesResult ; }
Will return an array by considering the supported messages and filling the supported ones with the given values .
16,213
public function render ( ElementInterface $ formElement , $ value = '' , $ attributes = array ( ) ) { $ this -> checkDependencies ( ) ; $ config = $ this -> di -> get ( 'config' ) ; if ( empty ( $ this -> templateName ) && ! empty ( $ config -> forms -> templates -> default_name ) ) { $ this -> templateName = $ config -> forms -> templates -> default_name ; } $ this -> variables [ 'element' ] = $ formElement ; $ this -> variables [ 'value' ] = $ value ; $ this -> variables [ 'attributes' ] = $ attributes ; $ partial = $ this -> generatePartial ( ) ; return $ partial ; }
Render form element with current templatePath and templateName . If templatePath or templateName are not set render default .
16,214
private function checkDependencies ( ) { if ( ! ( $ this -> di instanceof DiInterface ) ) { throw new DiNotSetException ( ) ; } if ( ! $ this -> di -> has ( 'view' ) ) { throw new ViewNotSetException ( ) ; } if ( ! $ this -> di -> has ( 'assets' ) ) { throw new InvalidAssetsManagerException ( ) ; } }
Check for required DI services .
16,215
protected function getFilePath ( string $ path ) : string { if ( empty ( $ path ) ) { $ path = $ this -> fileName ; } return $ path ; }
Get file path string
16,216
protected function getDistributionFilePath ( string $ path ) : string { $ postfix = self :: DIST_FILENAME_POSTFIX ; if ( empty ( $ path ) ) { $ path = $ this -> fileName ; } $ pathinfo = pathinfo ( $ path ) ; $ postfixIndex = strlen ( $ pathinfo [ 'filename' ] ) - strlen ( $ postfix ) ; $ isDistributionFile = substr ( $ pathinfo [ 'filename' ] , $ postfixIndex ) === $ postfix ; if ( ! $ isDistributionFile ) { $ extension = ! empty ( $ pathinfo [ 'extension' ] ) ? '.' . $ pathinfo [ 'extension' ] : '' ; $ path = $ pathinfo [ 'filename' ] . $ postfix . $ extension ; } return $ path ; }
Get file path string for the corresponding distribution file
16,217
protected function validatePath ( string $ path ) : void { if ( empty ( $ path ) ) { $ this -> fail ( new InvalidArgumentException ( "Path is not specified" ) ) ; } if ( ! is_string ( $ path ) ) { $ this -> fail ( new InvalidArgumentException ( "Path is not a string" ) ) ; } }
Validate path string
16,218
protected function addFileExtension ( string $ path ) : string { $ extension = pathinfo ( $ path , PATHINFO_EXTENSION ) ; if ( empty ( $ extension ) ) { $ path .= $ this -> extension ; } return $ path ; }
Add default extension if path doesn t have one
16,219
protected function getSubmittedFormValues ( ) { $ result = [ ] ; $ formName = $ this -> getFormObject ( ) -> getName ( ) ; $ originalRequest = $ this -> getControllerContext ( ) -> getRequest ( ) -> getOriginalRequest ( ) ; if ( null !== $ originalRequest && $ originalRequest -> hasArgument ( $ formName ) ) { $ result = $ originalRequest -> getArgument ( $ formName ) ; } return $ result ; }
Will fetch the values of the fields of the submitted form if a form has been submitted .
16,220
private function encryptAndRenderCookies ( $ resCookies ) { $ renderable = [ ] ; foreach ( $ resCookies as $ cookie ) { if ( is_string ( $ cookie ) ) { $ cookie = SetCookie :: fromSetCookieString ( $ cookie ) ; } if ( $ cookie instanceof SetCookie ) { $ val = $ cookie -> getValue ( ) ; if ( $ val instanceof OpaqueProperty ) { $ val = $ val -> getValue ( ) ; } if ( ! in_array ( $ cookie -> getName ( ) , $ this -> unencryptedCookies ) ) { $ val = $ this -> encryption -> encrypt ( $ val ) ; } $ renderable [ $ cookie -> getName ( ) ] = ( string ) $ cookie -> withValue ( $ val ) ; } } return $ renderable ; }
Parse all cookies set on the response
16,221
public function formatTimepoint ( $ time , $ format ) { if ( $ time instanceof TimePoint ) { return $ time -> format ( $ format , $ this -> displayTimezone ) ; } if ( $ time instanceof DateTime ) { $ formatted = clone $ time ; $ formatted -> setTimezone ( new DateTimeZone ( $ this -> displayTimezone ) ) ; return $ formatted -> format ( $ format ) ; } return '' ; }
Format a DateTime or TimePoint . Invalid values will output an empty string .
16,222
public function processRequest ( RequestInterface $ request , ResponseInterface $ response ) { $ this -> result = new AjaxResult ; try { $ this -> processRequestParent ( $ request , $ response ) ; } catch ( Exception $ exception ) { if ( false === $ this -> protectedRequestMode ) { throw $ exception ; } $ this -> result -> clear ( ) ; $ errorMessage = ExtensionService :: get ( ) -> isInDebugMode ( ) ? $ this -> getDebugMessageForException ( $ exception ) : ContextService :: get ( ) -> translate ( self :: DEFAULT_ERROR_MESSAGE_KEY ) ; $ error = new Error ( $ errorMessage , 1490176818 ) ; $ this -> result -> addError ( $ error ) ; $ this -> result -> setData ( 'errorCode' , $ exception -> getCode ( ) ) ; } ob_clean ( ) ; $ this -> injectResultInResponse ( ) ; }
Will process the request but also prevent any external message to be displayed and catch any exception that could occur during the validation .
16,223
protected function initializeActionMethodValidators ( ) { $ this -> initializeActionMethodValidatorsParent ( ) ; $ request = $ this -> getRequest ( ) ; if ( false === $ request -> hasArgument ( 'name' ) ) { throw MissingArgumentException :: ajaxControllerNameArgumentNotSet ( ) ; } if ( false === $ request -> hasArgument ( 'className' ) ) { throw MissingArgumentException :: ajaxControllerClassNameArgumentNotSet ( ) ; } $ className = $ request -> getArgument ( 'className' ) ; if ( false === class_exists ( $ className ) ) { throw ClassNotFoundException :: ajaxControllerFormClassNameNotFound ( $ className ) ; } if ( false === in_array ( FormInterface :: class , class_implements ( $ className ) ) ) { throw InvalidArgumentTypeException :: ajaxControllerWrongFormType ( $ className ) ; } $ this -> arguments -> addNewArgument ( $ request -> getArgument ( 'name' ) , $ className , true ) ; }
Will take care of adding a new argument to the request based on the form name and the form class name found in the request arguments .
16,224
public function runAction ( $ name , $ className , $ fieldName , $ validatorName ) { $ this -> formName = $ name ; $ this -> formClassName = $ className ; $ this -> fieldName = $ fieldName ; $ this -> validatorName = $ validatorName ; $ this -> form = $ this -> getForm ( ) ; $ this -> formObject = $ this -> getFormObject ( ) ; $ this -> formObject -> setForm ( $ this -> form ) ; $ this -> validation = $ this -> getFieldValidation ( ) ; $ validatorDataObject = new ValidatorDataObject ( $ this -> formObject , $ this -> validation ) ; $ validator = Core :: instantiate ( $ this -> validation -> getClassName ( ) , $ this -> validation -> getOptions ( ) , $ validatorDataObject ) ; $ fieldValue = ObjectAccess :: getProperty ( $ this -> form , $ this -> fieldName ) ; $ result = $ validator -> validate ( $ fieldValue ) ; $ this -> result -> merge ( $ result ) ; }
Main action that will process the field validation .
16,225
protected function normalize ( array $ data , string $ prefix = null ) : array { if ( $ prefix ) { $ prefix .= '.' ; } $ result = [ ] ; foreach ( $ data as $ item ) { $ value = [ 'label' => ( string ) $ item [ 'label' ] , 'inactive' => ( bool ) $ item [ 'inactive' ] ] ; if ( ! empty ( $ item [ 'children' ] ) ) { $ value [ 'children' ] = $ this -> normalize ( $ item [ 'children' ] , $ prefix . $ item [ 'value' ] ) ; } $ result [ $ prefix . $ item [ 'value' ] ] = $ value ; } return $ result ; }
Method that restructures list options csv data for better handling .
16,226
protected function filter ( array $ data ) : array { $ result = [ ] ; foreach ( $ data as $ key => $ value ) { if ( $ value [ 'inactive' ] ) { continue ; } $ result [ $ key ] = $ value ; if ( isset ( $ value [ 'children' ] ) ) { $ result [ $ key ] [ 'children' ] = $ this -> filter ( $ value [ 'children' ] ) ; } } return $ result ; }
Method that filters list options excluding non - active ones
16,227
protected function flatten ( array $ data ) : array { $ result = [ ] ; foreach ( $ data as $ key => $ value ) { $ item = [ 'label' => $ value [ 'label' ] , 'inactive' => $ value [ 'inactive' ] ] ; $ result [ $ key ] = $ item ; if ( isset ( $ value [ 'children' ] ) ) { $ result = array_merge ( $ result , $ this -> flatten ( $ value [ 'children' ] ) ) ; } } return $ result ; }
Flatten list options .
16,228
protected function setOptions ( array $ options = [ ] ) : void { $ this -> options = $ options ; $ this -> configName = empty ( $ options [ 'cacheConfig' ] ) ? static :: DEFAULT_CONFIG : ( string ) $ options [ 'cacheConfig' ] ; $ this -> skipCache = empty ( $ this -> options [ 'cacheSkip' ] ) ? false : ( bool ) $ this -> options [ 'cacheSkip' ] ; }
Set cache options
16,229
public function getKey ( array $ params ) : string { $ params [ ] = $ this -> options ; $ params = json_encode ( $ params ) ; $ params = $ params ? : microtime ( ) ; $ params = md5 ( $ params ) ; $ result = $ this -> name . '_' . $ params ; return $ result ; }
Generate cache key
16,230
public function readFrom ( string $ key ) { $ result = false ; if ( $ this -> skipCache ( ) ) { $ this -> warnings [ ] = 'Skipping read from cache' ; return $ result ; } $ cachedData = CakeCache :: read ( $ key , $ this -> getConfig ( ) ) ; if ( ! $ this -> isValidCache ( $ cachedData ) ) { CakeCache :: delete ( $ key , $ this -> getConfig ( ) ) ; return $ result ; } $ result = $ cachedData [ 'data' ] ; return $ result ; }
Read cached value from a given key
16,231
protected function getLogicalResult ( callable $ logicalAndFunction , callable $ logicalOrFunction ) { switch ( $ this -> operator ) { case ConditionParser :: LOGICAL_AND : $ result = call_user_func ( $ logicalAndFunction ) ; break ; case ConditionParser :: LOGICAL_OR : $ result = call_user_func ( $ logicalOrFunction ) ; break ; default : throw InvalidConfigurationException :: wrongBooleanNodeOperator ( $ this -> operator ) ; } return $ result ; }
Global function to get the result of a logical operation the processor does not matter .
16,232
protected function processLogicalOrPhp ( PhpConditionDataObject $ dataObject ) { return $ this -> leftNode -> getPhpResult ( $ dataObject ) || $ this -> rightNode -> getPhpResult ( $ dataObject ) ; }
Will process a logical or operation on the two given nodes .
16,233
public function requireDefaultRecords ( ) { parent :: requireDefaultRecords ( ) ; if ( ! self :: config ( ) -> create_default_pages ) { return ; } if ( ! file_exists ( ASSETS_PATH ) ) { mkdir ( ASSETS_PATH ) ; } $ code = self :: $ defaults [ 'ErrorCode' ] ; $ page = UtilityPage :: get ( ) -> filter ( 'ErrorCode' , $ code ) -> first ( ) ; $ pageExists = ! empty ( $ page ) ; if ( ! $ pageExists ) { $ page = UtilityPage :: get ( ) -> first ( ) ; $ pageExists = ( $ page && $ page -> exists ( ) ) ; $ page = UtilityPage :: create ( array ( 'Title' => _t ( 'MaintenanceMode.TITLE' , 'Undergoing Scheduled Maintenance' ) , 'URLSegment' => _t ( 'MaintenanceMode.URLSEGMENT' , 'offline' ) , 'MenuTitle' => _t ( 'MaintenanceMode.MENUTITLE' , 'Utility Page' ) , 'Content' => _t ( 'MaintenanceMode.CONTENT' , '<h1>We&rsquo;ll be back soon!</h1>' . '<p>Sorry for the inconvenience but ' . 'our site is currently down for scheduled maintenance. ' . 'If you need to you can always <a href="mailto:#">contact us</a>, ' . 'otherwise we&rsquo;ll be back online shortly!</p>' . '<p>&mdash; The Team</p>' ) , 'ParentID' => 0 ) ) ; $ page -> write ( ) ; $ page -> copyVersionToStage ( Versioned :: DRAFT , Versioned :: LIVE ) ; } if ( ! self :: config ( ) -> enable_static_file ) { return ; } $ success = true ; if ( ! $ page -> hasStaticPage ( ) ) { $ success = $ page -> writeStaticPage ( ) ; } elseif ( $ pageExists ) { return ; } if ( $ success ) { DB :: alteration_message ( sprintf ( '%s error Utility Page created' , $ code ) , 'created' ) ; } else { DB :: alteration_message ( sprintf ( '%s error Utility page could not be created. Please check permissions' , $ code ) , 'error' ) ; } }
Create default Utility Page setup Ensures that there is always a 503 Utility page by checking if there s an instance of ErrorPage with a 503 error code . If there is not one is created when the DB is built .
16,234
public static function get_top_level_templates ( ) { $ ss_templates_array = array ( ) ; $ current_theme_path = THEMES_PATH . '/' . Config :: inst ( ) -> get ( 'SSViewer' , 'theme' ) ; $ search_dir_array = array ( MAINTENANCE_MODE_PATH . '/templates' , $ current_theme_path . '/templates' ) ; foreach ( $ search_dir_array as $ directory ) { foreach ( glob ( "{$directory}/*.ss" ) as $ template_path ) { $ template = basename ( $ template_path , '.ss' ) ; $ ss_templates_array [ $ template ] = $ template ; } } return $ ss_templates_array ; }
This function returns an array of top - level theme templates
16,235
public function getInstanceFromClassName ( $ className , $ name ) { if ( false === class_exists ( $ className ) ) { throw ClassNotFoundException :: wrongFormClassName ( $ className ) ; } if ( false === in_array ( FormInterface :: class , class_implements ( $ className ) ) ) { throw InvalidArgumentTypeException :: wrongFormType ( $ className ) ; } $ cacheIdentifier = $ this -> getCacheIdentifier ( $ className , $ name ) ; if ( false === isset ( $ this -> instances [ $ cacheIdentifier ] ) ) { $ cacheInstance = CacheService :: get ( ) -> getCacheInstance ( ) ; if ( $ cacheInstance -> has ( $ cacheIdentifier ) ) { $ instance = $ cacheInstance -> get ( $ cacheIdentifier ) ; } else { $ instance = $ this -> createInstance ( $ className , $ name ) ; $ cacheInstance -> set ( $ cacheIdentifier , $ instance ) ; } $ formzConfigurationObject = $ this -> configurationFactory -> getFormzConfiguration ( ) -> getObject ( true ) ; if ( false === $ formzConfigurationObject -> hasForm ( $ instance -> getClassName ( ) , $ instance -> getName ( ) ) ) { $ formzConfigurationObject -> addForm ( $ instance ) ; } $ this -> instances [ $ cacheIdentifier ] = $ instance ; } return $ this -> instances [ $ cacheIdentifier ] ; }
Will create an instance of FormObject based on a class which implements the interface FormInterface .
16,236
protected function createInstance ( $ className , $ name ) { $ formConfiguration = $ this -> typoScriptService -> getFormConfiguration ( $ className ) ; $ instance = Core :: instantiate ( FormObject :: class , $ className , $ name , $ formConfiguration ) ; $ this -> insertObjectProperties ( $ instance ) ; $ instance -> getHash ( ) ; return $ instance ; }
Creates and initializes a new FormObject instance .
16,237
protected function insertObjectProperties ( FormObject $ instance ) { $ className = $ instance -> getClassName ( ) ; $ reflectionService = GeneralUtility :: makeInstance ( ReflectionService :: class ) ; $ reflectionProperties = $ reflectionService -> getClassPropertyNames ( $ className ) ; $ classReflection = new \ ReflectionClass ( $ className ) ; $ publicProperties = $ classReflection -> getProperties ( \ ReflectionProperty :: IS_PUBLIC ) ; foreach ( $ reflectionProperties as $ property ) { if ( false === in_array ( $ property , self :: $ ignoredProperties ) && false === $ reflectionService -> isPropertyTaggedWith ( $ className , $ property , self :: IGNORE_PROPERTY ) && ( ( true === in_array ( $ property , $ publicProperties ) ) || $ reflectionService -> hasMethod ( $ className , 'get' . ucfirst ( $ property ) ) ) ) { $ instance -> addProperty ( $ property ) ; } } unset ( $ publicProperties ) ; }
Will insert all the accessible properties of the given instance .
16,238
public function addTerm ( $ term_id ) { $ term = ( $ term_id instanceof Term ) ? $ term_id : Term :: findOrFail ( $ term_id ) ; $ term_relation = [ 'term_id' => $ term -> id , 'vocabulary_id' => $ term -> vocabulary_id , ] ; return $ this -> related ( ) -> save ( new TermRelation ( $ term_relation ) ) ; }
Add an existing term to the inheriting model
16,239
public function hasTerm ( $ term_id ) { $ term = ( $ term_id instanceof Term ) ? $ term_id : Term :: findOrFail ( $ term_id ) ; $ term_relation = [ 'term_id' => $ term -> id , 'vocabulary_id' => $ term -> vocabulary_id , ] ; return ( $ this -> related ( ) -> where ( 'term_id' , $ term_id ) -> count ( ) ) ? TRUE : FALSE ; }
Check if the Model instance has the passed term as an existing relation
16,240
public function getTermsByVocabularyName ( $ name ) { $ vocabulary = \ Taxonomy :: getVocabularyByName ( $ name ) ; return $ this -> related ( ) -> where ( 'vocabulary_id' , $ vocabulary -> id ) -> get ( ) ; }
Get all the terms for a given vocabulary that are linked to the current Model .
16,241
public function getTermsByVocabularyNameAsArray ( $ name ) { $ vocabulary = \ Taxonomy :: getVocabularyByName ( $ name ) ; $ term_relations = $ this -> related ( ) -> where ( 'vocabulary_id' , $ vocabulary -> id ) -> get ( ) ; $ data = [ ] ; foreach ( $ term_relations as $ term_relation ) { $ data [ $ term_relation -> term -> id ] = $ term_relation -> term -> name ; } return $ data ; }
Get all the terms for a given vocabulary that are linked to the current Model as a key value pair array .
16,242
public function removeTerm ( $ term_id ) { $ term_id = ( $ term_id instanceof Term ) ? $ term_id -> id : $ term_id ; return $ this -> related ( ) -> where ( 'term_id' , $ term_id ) -> delete ( ) ; }
Unlink the given term with the current model object
16,243
public function applyBehavioursOnSubmittedForm ( ControllerContext $ controllerContext ) { if ( $ this -> formObject -> formWasSubmitted ( ) ) { $ request = $ controllerContext -> getRequest ( ) -> getOriginalRequest ( ) ; $ formName = $ this -> formObject -> getName ( ) ; if ( $ request && $ request -> hasArgument ( $ formName ) ) { $ behavioursManager = GeneralUtility :: makeInstance ( BehavioursManager :: class ) ; $ originalForm = $ request -> getArgument ( $ formName ) ; $ formProperties = $ behavioursManager -> applyBehaviourOnPropertiesArray ( $ originalForm , $ this -> formObject -> getConfiguration ( ) ) ; $ request -> setArgument ( $ formName , $ formProperties ) ; } } }
Will loop on the submitted form fields and apply behaviours if their configuration contains .
16,244
public function getActivationConditionTreeForField ( Field $ field ) { $ key = $ field -> getName ( ) ; if ( false === array_key_exists ( $ key , $ this -> fieldsTrees ) ) { $ this -> fieldsTrees [ $ key ] = $ this -> getConditionTree ( $ field -> getActivation ( ) ) ; } $ this -> fieldsTrees [ $ key ] -> injectDependencies ( $ this , $ field -> getActivation ( ) ) ; return $ this -> fieldsTrees [ $ key ] ; }
Returns the condition tree for a given field instance giving access to CSS JavaScript and PHP transpiled results .
16,245
public function getActivationConditionTreeForValidation ( Validation $ validation ) { $ key = $ validation -> getParentField ( ) -> getName ( ) . '->' . $ validation -> getName ( ) ; if ( false === array_key_exists ( $ key , $ this -> validationsTrees ) ) { $ this -> validationsTrees [ $ key ] = $ this -> getConditionTree ( $ validation -> getActivation ( ) ) ; } $ this -> validationsTrees [ $ key ] -> injectDependencies ( $ this , $ validation -> getActivation ( ) ) ; return $ this -> validationsTrees [ $ key ] ; }
Returns the condition tree for a given validation instance giving access to CSS JavaScript and PHP transpiled results .
16,246
public function calculateAllTrees ( ) { $ fields = $ this -> formObject -> getConfiguration ( ) -> getFields ( ) ; foreach ( $ fields as $ field ) { $ this -> getActivationConditionTreeForField ( $ field ) ; foreach ( $ field -> getValidation ( ) as $ validation ) { $ this -> getActivationConditionTreeForValidation ( $ validation ) ; } } }
Function that will calculate all trees from fields and their validation rules .
16,247
public function exceptionHandler ( $ e ) : void { $ this -> setError ( ( int ) $ e -> getCode ( ) , ( string ) $ e -> getMessage ( ) , ( string ) $ e -> getFile ( ) , ( int ) $ e -> getLine ( ) , ( string ) get_class ( $ e ) , $ e -> getTrace ( ) ) ; View :: render ( '500.php' , ( object ) $ this -> errors ) ; }
exception handler .
16,248
public function fatalHandler ( ) : void { $ errors = error_get_last ( ) ; if ( is_array ( $ errors ) ) { $ this -> setError ( ( int ) $ errors [ 'type' ] , ( string ) $ errors [ 'message' ] , ( string ) $ errors [ 'file' ] , ( int ) $ errors [ 'line' ] , 'FatalErrorException' ) ; View :: render ( '500.php' , ( object ) $ this -> errors ) ; return ; } }
error handler method .
16,249
public function migrateModels ( $ models ) { $ this -> set ( function ( $ c ) use ( $ models ) { $ c -> notice ( 'Preparing to migrate models' ) ; $ p = $ c -> app -> db ; foreach ( $ models as $ model ) { if ( ! is_object ( $ model ) ) { $ model = $ this -> factory ( $ model ) ; $ p -> add ( $ model ) ; } $ m = new \ atk4 \ schema \ Migration \ MySQL ( $ model ) ; $ result = $ m -> migrate ( ) ; $ c -> debug ( ' ' . get_class ( $ model ) . '.. ' . $ result ) ; } $ c -> notice ( 'Done with migration' ) ; } ) ; }
Provided with array of models perform migration for each of them .
16,250
public function getExtensionConfiguration ( $ configurationName ) { $ result = null ; $ extensionConfiguration = $ this -> getFullExtensionConfiguration ( ) ; if ( null === $ configurationName ) { $ result = $ extensionConfiguration ; } elseif ( ArrayUtility :: isValidPath ( $ extensionConfiguration , $ configurationName , '.' ) ) { $ result = ArrayUtility :: getValueByPath ( $ extensionConfiguration , $ configurationName , '.' ) ; } return $ result ; }
Return the wanted extension configuration .
16,251
public function expireCookie ( ResponseInterface $ response , $ name ) { $ cookie = SetCookie :: createExpired ( $ name ) -> withMaxAge ( $ this -> configuration [ 'maxAge' ] ) -> withPath ( $ this -> configuration [ 'path' ] ) -> withDomain ( $ this -> configuration [ 'domain' ] ) -> withSecure ( $ this -> configuration [ 'secure' ] ) -> withHttpOnly ( $ this -> configuration [ 'httpOnly' ] ) ; return $ response -> withAddedHeader ( static :: RESPONSE_COOKIE_NAME , $ cookie ) ; }
Expire a cookie in the response .
16,252
protected function addError ( $ key , $ code , array $ arguments = [ ] , $ title = '' ) { $ message = $ this -> addMessage ( Error :: class , $ key , $ code , $ arguments , $ title ) ; $ this -> result -> addError ( $ message ) ; }
Creates a new validation error and adds it to the result .
16,253
protected function addWarning ( $ key , $ code , array $ arguments = [ ] , $ title = '' ) { $ message = $ this -> addMessage ( Warning :: class , $ key , $ code , $ arguments , $ title ) ; $ this -> result -> addWarning ( $ message ) ; }
Creates a new validation warning and adds it to the result .
16,254
protected function addNotice ( $ key , $ code , array $ arguments = [ ] , $ title = '' ) { $ message = $ this -> addMessage ( Notice :: class , $ key , $ code , $ arguments , $ title ) ; $ this -> result -> addNotice ( $ message ) ; }
Creates a new validation notice and adds it to the result .
16,255
public function addProperty ( $ name ) { if ( false === $ this -> hasProperty ( $ name ) ) { $ this -> properties [ ] = $ name ; $ this -> hashService -> resetHash ( ) ; } return $ this ; }
Registers a new property for this form .
16,256
protected function read ( $ length ) { if ( $ this -> length < $ length ) { throw new \ Exception ( 'Reading while at end of stream' ) ; } $ output = substr ( $ this -> data , 0 , $ length ) ; $ this -> data = substr ( $ this -> data , $ length ) ; $ this -> length -= $ length ; return $ output ; }
Read data from stream .
16,257
public function readInt ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ length = $ this -> readShort ( ) ; return unpack ( 'l' , strrev ( $ this -> read ( $ length ) ) ) [ 1 ] ; } return unpack ( 'l' , strrev ( $ this -> read ( 4 ) ) ) [ 1 ] ; }
Read unsigned int .
16,258
function readBigInt ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ length = $ this -> readShort ( ) ; } else { $ length = 8 ; } $ data = $ this -> read ( $ length ) ; $ arr = unpack ( 'N2' , $ data ) ; if ( PHP_INT_SIZE == 4 ) { $ hi = $ arr [ 1 ] ; $ lo = $ arr [ 2 ] ; $ isNeg = $ hi < 0 ; if ( $ isNeg ) { $ hi = ~ $ hi & ( int ) 0xffffffff ; $ lo = ~ $ lo & ( int ) 0xffffffff ; if ( $ lo == ( int ) 0xffffffff ) { $ hi ++ ; $ lo = 0 ; } else { $ lo ++ ; } } if ( $ hi & ( int ) 0x80000000 ) { $ hi &= ( int ) 0x7fffffff ; $ hi += 0x80000000 ; } if ( $ lo & ( int ) 0x80000000 ) { $ lo &= ( int ) 0x7fffffff ; $ lo += 0x80000000 ; } $ value = $ hi * 4294967296 + $ lo ; if ( $ isNeg ) { $ value = 0 - $ value ; } } else { if ( $ arr [ 2 ] & 0x80000000 ) { $ arr [ 2 ] = $ arr [ 2 ] & 0xffffffff ; } if ( $ arr [ 1 ] & 0x80000000 ) { $ arr [ 1 ] = $ arr [ 1 ] & 0xffffffff ; $ arr [ 1 ] = $ arr [ 1 ] ^ 0xffffffff ; $ arr [ 2 ] = $ arr [ 2 ] ^ 0xffffffff ; $ value = 0 - $ arr [ 1 ] * 4294967296 - $ arr [ 2 ] - 1 ; } else { $ value = $ arr [ 1 ] * 4294967296 + $ arr [ 2 ] ; } } return $ value ; }
Read unsigned big int ;
16,259
public function readBytes ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) $ this -> readShort ( ) ; $ length = $ this -> readInt ( ) ; if ( $ length == - 1 ) return null ; return $ this -> read ( $ length ) ; }
Read bytes .
16,260
public function readUuid ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) $ this -> readShort ( ) ; $ uuid = '' ; $ data = $ this -> read ( 16 ) ; for ( $ i = 0 ; $ i < 16 ; ++ $ i ) { if ( $ i == 4 || $ i == 6 || $ i == 8 || $ i == 10 ) { $ uuid .= '-' ; } $ uuid .= str_pad ( dechex ( ord ( $ data { $ i } ) ) , 2 , '0' , STR_PAD_LEFT ) ; } return $ uuid ; }
Read uuid .
16,261
public function readList ( $ valueType ) { $ list = array ( ) ; $ count = $ this -> readShort ( ) ; for ( $ i = 0 ; $ i < $ count ; ++ $ i ) { $ list [ ] = $ this -> readByType ( $ valueType , true ) ; } return $ list ; }
Read list .
16,262
public function readMap ( $ keyType , $ valueType ) { $ map = array ( ) ; $ count = $ this -> readShort ( ) ; for ( $ i = 0 ; $ i < $ count ; ++ $ i ) { $ map [ $ this -> readByType ( $ keyType , true ) ] = $ this -> readByType ( $ valueType , true ) ; } return $ map ; }
Read map .
16,263
public function readFloat ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ this -> readShort ( ) ; } return unpack ( 'f' , strrev ( $ this -> read ( 4 ) ) ) [ 1 ] ; }
Read float .
16,264
public function readDouble ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ this -> readShort ( ) ; } return unpack ( 'd' , strrev ( $ this -> read ( 8 ) ) ) [ 1 ] ; }
Read double .
16,265
public function readInet ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ data = $ this -> read ( $ this -> readShort ( ) ) ; } else { $ data = $ this -> data ; } return inet_ntop ( $ data ) ; }
Read inet .
16,266
public function readVarint ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ length = $ this -> readShort ( ) ; } else { $ length = strlen ( $ this -> data ) ; } $ hex = unpack ( 'H*' , $ this -> read ( $ length ) ) ; return $ this -> bchexdec ( $ hex [ 1 ] ) ; }
Read variable length integer .
16,267
public function readDecimal ( $ isCollectionElement = false ) { if ( $ isCollectionElement ) { $ this -> readShort ( ) ; } $ scale = $ this -> readInt ( ) ; $ value = $ this -> readVarint ( $ isCollectionElement ) ; $ len = strlen ( $ value ) ; return substr ( $ value , 0 , $ len - $ scale ) . '.' . substr ( $ value , $ len - $ scale ) ; }
Read variable length decimal .
16,268
public function setModel ( \ atk4 \ data \ Model $ m ) { $ this -> table ( $ m -> table ) ; foreach ( $ m -> elements as $ field ) { if ( ! $ field instanceof \ atk4 \ data \ Field ) { continue ; } if ( $ field -> never_persist ) { continue ; } if ( $ field instanceof \ atk4 \ data \ Field_SQL_Expression ) { continue ; } if ( $ field -> short_name == $ m -> id_field ) { $ this -> id ( $ field -> actual ? : $ field -> short_name ) ; continue ; } $ this -> field ( $ field -> actual ? : $ field -> short_name , [ 'type' => $ field -> type ] ) ; } return $ m ; }
Sets model .
16,269
public function mode ( $ mode ) { if ( ! isset ( $ this -> templates [ $ mode ] ) ) { throw new Exception ( [ 'Structure builder does not have this mode' , 'mode' => $ mode ] ) ; } $ this -> mode = $ mode ; $ this -> template = $ this -> templates [ $ mode ] ; return $ this ; }
Set SQL expression template .
16,270
public function _render_statements ( ) { $ result = [ ] ; if ( isset ( $ this -> args [ 'dropField' ] ) ) { foreach ( $ this -> args [ 'dropField' ] as $ field => $ junk ) { $ result [ ] = 'drop column ' . $ this -> _escape ( $ field ) ; } } if ( isset ( $ this -> args [ 'newField' ] ) ) { foreach ( $ this -> args [ 'newField' ] as $ field => $ option ) { $ result [ ] = 'add column ' . $ this -> _render_one_field ( $ field , $ option ) ; } } if ( isset ( $ this -> args [ 'alterField' ] ) ) { foreach ( $ this -> args [ 'alterField' ] as $ field => $ option ) { $ result [ ] = 'change column ' . $ this -> _escape ( $ field ) . ' ' . $ this -> _render_one_field ( $ field , $ option ) ; } } return implode ( ', ' , $ result ) ; }
Renders statement .
16,271
public function getModelFieldType ( $ type ) { $ type = preg_replace ( '/\(.*/' , '' , strtolower ( $ type ) ) ; if ( substr ( $ type , 0 , 7 ) == 'varchar' || substr ( $ type , 0 , 4 ) == 'char' || substr ( $ type , 0 , 4 ) == 'enum' ) { $ type = null ; } if ( $ type == 'tinyint' ) { $ type = 'boolean' ; } if ( $ type == 'int' ) { $ type = 'integer' ; } if ( $ type == 'decimal' ) { $ type = 'float' ; } if ( $ type == 'longtext' || $ type == 'longblob' ) { $ type = 'text' ; } return $ type ; }
Convert SQL field types to Agile Data field types .
16,272
public function getSQLFieldType ( $ type , $ options = [ ] ) { $ type = strtolower ( $ type ) ; $ len = null ; switch ( $ type ) { case 'boolean' : $ type = 'tinyint' ; $ len = 1 ; break ; case 'integer' : $ type = 'int' ; break ; case 'money' : $ type = 'decimal' ; $ len = '12,2' ; break ; case 'float' : $ type = 'decimal' ; $ len = '16,6' ; break ; case 'date' : case 'datetime' : $ type = 'date' ; break ; case 'time' : $ type = 'varchar' ; $ len = '8' ; break ; case 'text' : $ type = 'longtext' ; break ; case 'array' : case 'object' : $ type = 'longtext' ; break ; default : $ type = 'varchar' ; $ len = '255' ; break ; } $ len = $ options [ 'len' ] ?? $ len ; return $ len !== null ? $ type . '(' . $ len . ')' : $ type ; }
Convert Agile Data field types to SQL field types .
16,273
public function importTable ( $ table ) { $ this -> table ( $ table ) ; $ has_fields = false ; foreach ( $ this -> describeTable ( $ table ) as $ row ) { $ has_fields = true ; if ( $ row [ 'pk' ] ) { $ this -> id ( $ row [ 'name' ] ) ; continue ; } $ type = $ this -> getModelFieldType ( $ row [ 'type' ] ) ; $ this -> field ( $ row [ 'name' ] , [ 'type' => $ type ] ) ; } return $ has_fields ; }
Import fields from database into migration field config .
16,274
public function id ( $ name = null ) { if ( ! $ name ) { $ name = 'id' ; } $ val = $ this -> connection -> expr ( $ this -> primary_key_expr ) ; $ this -> args [ 'field' ] = [ $ name => $ val ] + ( isset ( $ this -> args [ 'field' ] ) ? $ this -> args [ 'field' ] : [ ] ) ; return $ this ; }
Add ID field in template .
16,275
protected function _render_one_field ( $ field , $ options ) { $ name = $ options [ 'name' ] ?? $ field ; $ type = $ this -> getSQLFieldType ( $ options [ 'type' ] ?? null , $ options ) ; return $ this -> _escape ( $ name ) . ' ' . $ type ; }
Renders one field .
16,276
protected function _set_args ( $ what , $ alias , $ value ) { if ( $ alias === null ) { $ this -> args [ $ what ] [ ] = $ value ; } else { if ( isset ( $ this -> args [ $ what ] [ $ alias ] ) ) { throw new Exception ( [ ucfirst ( $ what ) . ' alias should be unique' , 'alias' => $ alias , ] ) ; } $ this -> args [ $ what ] [ $ alias ] = $ value ; } }
Sets value in args array . Doesn t allow duplicate aliases .
16,277
protected function getFinder ( ) : PathFinderInterface { $ result = ClassFactory :: createFinder ( $ this -> configType , $ this -> options ) ; return $ result ; }
Get path finder instance
16,278
public function createSchema ( array $ config = [ ] ) : SchemaInterface { $ path = rtrim ( Configure :: read ( 'ModuleConfig.schemaPath' ) , '/' ) ; $ file = $ this -> configType . '.json' ; $ schemaPath = implode ( DIRECTORY_SEPARATOR , [ $ path , $ file ] ) ; return new Schema ( $ schemaPath , null , $ config ) ; }
Creates a new Schema instance for the current config type .
16,279
public function find ( bool $ validate = true ) { $ cache = $ finder = $ exception = $ cacheKey = $ result = null ; try { $ cache = new Cache ( __FUNCTION__ , $ this -> options ) ; $ cacheKey = $ cache -> getKey ( [ $ this -> module , $ this -> configType , $ this -> configFile , $ validate ] ) ; $ result = $ cache -> readFrom ( $ cacheKey ) ; if ( $ result !== false ) { return $ result ; } $ finder = $ this -> getFinder ( ) ; $ result = $ finder -> find ( $ this -> module , $ this -> configFile , $ validate ) ; } catch ( InvalidArgumentException $ exception ) { $ this -> mergeMessages ( $ exception , __FUNCTION__ ) ; } $ this -> mergeMessages ( $ finder , __FUNCTION__ ) ; $ this -> mergeMessages ( $ cache , __FUNCTION__ ) ; if ( $ exception ) { throw $ exception ; } if ( $ cache && $ cacheKey ) { $ cache -> writeTo ( $ cacheKey , $ result ) ; } return $ result ; }
Find module configuration file
16,280
public function parse ( ) { $ result = new stdClass ( ) ; $ cache = $ parser = $ exception = $ cacheKey = $ path = null ; try { $ path = $ this -> find ( false ) ; $ cache = new PathCache ( __FUNCTION__ , $ this -> options ) ; $ cacheKey = $ cache -> getKey ( [ $ path ] ) ; $ result = $ cache -> readFrom ( $ cacheKey ) ; if ( $ result !== false ) { return $ result ; } $ parser = $ this -> getParser ( ) ; $ result = $ parser -> parse ( $ path ) ; } catch ( InvalidArgumentException $ exception ) { $ this -> mergeMessages ( $ exception , __FUNCTION__ ) ; } $ this -> mergeMessages ( $ parser , __FUNCTION__ ) ; $ this -> mergeMessages ( $ cache , __FUNCTION__ ) ; if ( $ exception ) { throw $ exception ; } if ( $ cache && $ cacheKey ) { $ cache -> writeTo ( $ cacheKey , $ result , [ 'path' => $ path ] ) ; } return $ result ; }
Parse module configuration file
16,281
protected function mergeMessages ( $ source = null , string $ caller = 'ModuleConfig' ) : void { $ source = is_object ( $ source ) ? $ source : new stdClass ( ) ; if ( $ source instanceof InvalidArgumentException ) { $ this -> errors = array_merge ( $ this -> errors , $ this -> formatMessages ( $ source -> getMessage ( ) , $ caller ) ) ; return ; } if ( $ source instanceof ErrorAwareInterface ) { $ this -> errors = array_merge ( $ this -> errors , $ this -> formatMessages ( $ source -> getErrors ( ) , $ caller ) ) ; $ this -> warnings = array_merge ( $ this -> warnings , $ this -> formatMessages ( $ source -> getWarnings ( ) , $ caller ) ) ; return ; } $ this -> errors [ ] = "Cannot merge messages from [" . get_class ( $ source ) . "]" ; }
Merge warning and error messages
16,282
public static function exists ( string $ moduleName , array $ options = [ ] ) : bool { $ config = ( new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ moduleName , null , $ options ) ) -> parseToArray ( ) ; if ( empty ( $ config ) ) { return false ; } $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ moduleName , null , $ options ) ) -> parseToArray ( ) ; if ( empty ( $ config [ 'table' ] ) || empty ( $ config [ 'table' ] [ 'type' ] ) ) { return false ; } return true ; }
Checks if the provided module name exists
16,283
public static function hasMigrationFields ( string $ moduleName , array $ fields , array $ options = [ ] ) : bool { $ config = ( new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ moduleName , null , $ options ) ) -> parseToArray ( ) ; $ fieldKeys = array_flip ( $ fields ) ; $ diff = array_diff_key ( $ fieldKeys , $ config ) ; return empty ( $ diff ) ; }
Checks whether the provided fields exists in migration configuration
16,284
public function readEvent ( ) { $ rawRequestBody = $ this -> httpClient -> getRawRequest ( ) ; $ webhookEvent = ! empty ( $ rawRequestBody [ 'webhook_event' ] ) ? json_decode ( $ rawRequestBody [ 'webhook_event' ] , true ) : false ; return $ webhookEvent ? $ this -> dataFactory -> create ( $ webhookEvent ) : false ; }
Read webhook event from request
16,285
public function includeGeneratedCss ( ) { $ filePath = $ this -> assetHandlerConnectorManager -> getFormzGeneratedFilePath ( ) . '.css' ; $ this -> assetHandlerConnectorManager -> createFileInTemporaryDirectory ( $ filePath , function ( ) { $ errorContainerDisplayCssAssetHandler = $ this -> assetHandlerConnectorManager -> getAssetHandlerFactory ( ) -> getAssetHandler ( MessageContainerDisplayCssAssetHandler :: class ) ; $ fieldsActivationCssAssetHandler = $ this -> assetHandlerConnectorManager -> getAssetHandlerFactory ( ) -> getAssetHandler ( FieldsActivationCssAssetHandler :: class ) ; $ css = $ errorContainerDisplayCssAssetHandler -> getErrorContainerDisplayCss ( ) . LF ; $ css .= $ fieldsActivationCssAssetHandler -> getFieldsActivationCss ( ) ; return $ css ; } ) ; $ this -> assetHandlerConnectorManager -> getPageRenderer ( ) -> addCssFile ( StringService :: get ( ) -> getResourceRelativePath ( $ filePath ) ) ; return $ this ; }
Will take care of generating the CSS with the AssetHandlerFactory . The code will be put in a . css file in the typo3temp directory .
16,286
public function includeDefaultAssets ( ) { if ( false === $ this -> assetHandlerConnectorStates -> defaultAssetsWereIncluded ( ) ) { $ this -> assetHandlerConnectorStates -> markDefaultAssetsAsIncluded ( ) ; $ this -> getJavaScriptAssetHandlerConnector ( ) -> includeDefaultJavaScriptFiles ( ) ; $ this -> getCssAssetHandlerConnector ( ) -> includeDefaultCssFiles ( ) ; } return $ this ; }
Will take care of including internal FormZ JavaScript and CSS files . They will be included only once even if the view helper is used several times in the same page .
16,287
public function getFormzGeneratedFilePath ( $ prefix = '' ) { $ formObject = $ this -> assetHandlerFactory -> getFormObject ( ) ; $ formIdentifier = CacheService :: get ( ) -> getFormCacheIdentifier ( $ formObject -> getClassName ( ) , $ formObject -> getName ( ) ) ; $ prefix = ( false === empty ( $ prefix ) ) ? $ prefix . '-' : '' ; $ identifier = substr ( 'fz-' . $ prefix . $ formIdentifier , 0 , 22 ) ; $ identifier .= '-' . md5 ( $ formObject -> getHash ( ) . $ formObject -> getName ( ) ) ; return CacheService :: GENERATED_FILES_PATH . $ identifier ; }
Returns a file name based on the form object class name .
16,288
public function createFileInTemporaryDirectory ( $ relativePath , callable $ callback ) { $ result = false ; $ absolutePath = GeneralUtility :: getFileAbsFileName ( $ relativePath ) ; if ( false === $ this -> fileExists ( $ absolutePath ) ) { $ content = call_user_func ( $ callback ) ; $ result = $ this -> writeTemporaryFile ( $ absolutePath , $ content ) ; if ( null !== $ result ) { throw FileCreationFailedException :: fileCreationFailed ( $ absolutePath , $ result ) ; } } return $ result ; }
This function will check if the file at the given path exists . If it does not the callback is called to get the content of the file which is put in the created file .
16,289
public function getContextHash ( ) { return ( $ this -> environmentService -> isEnvironmentInFrontendMode ( ) ) ? 'fe-' . Core :: get ( ) -> getPageController ( ) -> id : 'be-' . StringService :: get ( ) -> sanitizeString ( GeneralUtility :: _GET ( 'M' ) ) ; }
Returns a unique hash for the context of the current request depending on whether the request comes from frontend or backend .
16,290
public function getLanguageKey ( ) { $ languageKey = 'unknown' ; if ( $ this -> environmentService -> isEnvironmentInFrontendMode ( ) ) { $ pageController = Core :: get ( ) -> getPageController ( ) ; if ( isset ( $ pageController -> config [ 'config' ] [ 'language' ] ) ) { $ languageKey = $ pageController -> config [ 'config' ] [ 'language' ] ; } } else { $ backendUser = Core :: get ( ) -> getBackendUser ( ) ; if ( strlen ( $ backendUser -> uc [ 'lang' ] ) > 0 ) { $ languageKey = $ backendUser -> uc [ 'lang' ] ; } } return $ languageKey ; }
Returns the current language key .
16,291
public function addOptions ( array $ options ) { $ existingOptions = $ this -> getOptions ( ) ; $ newOptions = empty ( $ existingOptions ) ? $ options : array_merge ( ( array ) $ existingOptions , $ options ) ; $ this -> setOptions ( $ newOptions ) ; return $ this ; }
Allows to add multiple options at once when providing just one array .
16,292
protected function getDataFromPath ( string $ path ) : string { $ isPathRequired = $ this -> getConfig ( 'pathRequired' ) ; try { Utility :: validatePath ( $ path ) ; } catch ( InvalidArgumentException $ e ) { if ( $ isPathRequired ) { throw $ e ; } $ this -> warnings [ ] = $ e -> getMessage ( ) ; return ( string ) json_encode ( $ this -> getEmptyResult ( ) ) ; } return ( string ) file_get_contents ( $ path ) ; }
Read raw data from path .
16,293
protected function validate ( stdClass $ data ) : void { $ config = $ this -> getConfig ( ) ; $ schema = $ this -> readSchema ( ) ; $ dataArray = Convert :: objectToArray ( $ data ) ; if ( empty ( $ dataArray ) ) { if ( $ config [ 'allowEmptyData' ] === false ) { throw new JsonValidationException ( 'Empty data is not allowed.' ) ; } $ this -> warnings [ ] = "Skipping validation of empty data" ; return ; } $ schemaArray = Convert :: objectToArray ( $ schema ) ; if ( empty ( $ schemaArray ) ) { if ( $ config [ 'allowEmptySchema' ] === false ) { throw new JsonValidationException ( 'Empty schema is not allowed.' ) ; } $ this -> warnings [ ] = "Skipping validation with empty schema" ; return ; } $ this -> runValidator ( $ data , $ schema ) ; }
Validate the JSON object against the schema .
16,294
protected function readSchema ( ) : \ stdClass { $ schema = $ this -> getEmptyResult ( ) ; try { $ schema = $ this -> getSchema ( ) -> read ( ) ; } catch ( InvalidArgumentException $ e ) { $ this -> errors [ ] = $ e -> getMessage ( ) ; throw new JsonValidationException ( "Schema file `{$this->schema->getSchemaPath()}` cannot be read" , 0 , $ e ) ; } return $ schema ; }
Reads the schema .
16,295
protected function runValidator ( stdClass $ data , stdClass $ schema ) : void { $ config = $ this -> getConfig ( ) ; $ validator = new Validator ; $ validator -> validate ( $ data , $ schema , $ config [ 'validationMode' ] ) ; if ( ! $ validator -> isValid ( ) ) { foreach ( $ validator -> getErrors ( ) as $ error ) { $ this -> errors [ ] = sprintf ( '[%s]: %s' , $ error [ 'pointer' ] , $ error [ 'message' ] ) ; } throw new JsonValidationException ( 'Failed to validate json data against the schema.' ) ; } }
Runs the json validation .
16,296
final protected function renderForm ( array $ arguments ) { $ this -> formService -> activateFormContext ( ) ; $ this -> formService -> applyBehavioursOnSubmittedForm ( $ this -> controllerContext ) ; $ this -> addDefaultClass ( ) ; $ this -> handleDataAttributes ( ) ; $ this -> handleAssets ( ) ; $ this -> timeTracker -> logTime ( 'pre-render' ) ; $ result = $ this -> getParentRenderResult ( $ arguments ) ; $ this -> getAssetHandlerConnectorManager ( ) -> getJavaScriptAssetHandlerConnector ( ) -> includeLanguageJavaScriptFiles ( ) ; return $ result ; }
Will render the whole form and return the HTML result .
16,297
protected function addDefaultClass ( ) { $ formDefaultClass = $ this -> formObject -> getConfiguration ( ) -> getSettings ( ) -> getDefaultClass ( ) ; $ class = $ this -> tag -> getAttribute ( 'class' ) ; if ( false === empty ( $ formDefaultClass ) ) { $ class = ( ! empty ( $ class ) ? $ class . ' ' : '' ) . $ formDefaultClass ; $ this -> tag -> addAttribute ( 'class' , $ class ) ; } }
Will add a default class to the form element .
16,298
protected function handleDataAttributes ( ) { $ dataAttributes = [ ] ; $ dataAttributesAssetHandler = $ this -> getDataAttributesAssetHandler ( ) ; if ( $ this -> formObject -> hasForm ( ) ) { if ( false === $ this -> formObject -> hasFormResult ( ) ) { $ form = $ this -> formObject -> getForm ( ) ; $ formValidator = $ this -> getFormValidator ( $ this -> getFormObjectName ( ) ) ; $ formResult = $ formValidator -> validateGhost ( $ form ) ; } else { $ formResult = $ this -> formObject -> getFormResult ( ) ; } $ dataAttributes += $ dataAttributesAssetHandler -> getFieldsValuesDataAttributes ( $ formResult ) ; } if ( true === $ this -> formObject -> formWasSubmitted ( ) ) { $ dataAttributes += [ DataAttributesAssetHandler :: getFieldSubmissionDone ( ) => '1' ] ; $ dataAttributes += $ dataAttributesAssetHandler -> getFieldsValidDataAttributes ( ) ; $ dataAttributes += $ dataAttributesAssetHandler -> getFieldsMessagesDataAttributes ( ) ; } $ this -> tag -> addAttributes ( $ dataAttributes ) ; }
Adds custom data attributes to the form element based on the submitted form values and results .
16,299
protected function handleAssets ( ) { $ assetHandlerConnectorManager = $ this -> getAssetHandlerConnectorManager ( ) ; $ assetHandlerConnectorManager -> includeDefaultAssets ( ) ; $ assetHandlerConnectorManager -> getJavaScriptAssetHandlerConnector ( ) -> generateAndIncludeFormzConfigurationJavaScript ( ) -> generateAndIncludeJavaScript ( ) -> generateAndIncludeInlineJavaScript ( ) -> includeJavaScriptValidationAndConditionFiles ( ) ; $ assetHandlerConnectorManager -> getCssAssetHandlerConnector ( ) -> includeGeneratedCss ( ) ; }
Will include all JavaScript and CSS assets needed for this form .