idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
30,100
public function actionCheck ( ) { if ( ! $ this -> _modelConfigSync -> getFlagTreeSubordinateEnable ( ) ) { throw new InternalErrorException ( __d ( 'cake_ldap' , 'The database does not contain information on the tree view' ) ) ; } set_time_limit ( CHECK_TREE_EMPLOYEE_TIME_LIMIT ) ; $ treeState = $ this -> _modelSubordinate -> verify ( ) ; $ pageHeader = __d ( 'cake_ldap' , 'Checking state tree of employees' ) ; $ headerMenuActions = [ ] ; if ( $ treeState !== true ) { $ headerMenuActions [ ] = [ 'fas fa-redo-alt' , __d ( 'cake_ldap' , 'Recovery state of tree' ) , [ 'controller' => 'employees' , 'action' => 'recover' , 'prefix' => false ] , [ 'title' => __d ( 'cake_ldap' , 'Recovery state of tree' ) , 'data-toggle' => 'request-only' , ] ] ; } $ breadCrumbs = $ this -> _modelEmployee -> getBreadcrumbInfo ( ) ; $ breadCrumbs [ ] = __d ( 'cake_ldap' , 'Checking tree' ) ; $ this -> _controller -> set ( compact ( 'treeState' , 'pageHeader' , 'headerMenuActions' , 'breadCrumbs' ) ) ; }
Action check . Used to check state tree of subordinate employees .
30,101
public static function background ( string $ executable ) : self { $ self = new self ( $ executable ) ; $ self -> background = true ; return $ self ; }
Will run the command in the background and will survive even if the current process ends
30,102
public function transform ( Address $ address ) { return [ 'address' => $ address -> address , 'addressableId' => $ address -> addressable_id , 'addressableType' => $ address -> addressable_type , 'country' => $ address -> country , 'id' => $ address -> id , 'label' => $ address -> label , 'municipality' => $ address -> municipality , 'postcode' => $ address -> postcode , 'stateProvince' => $ address -> state_province , ] ; }
Transformer to generate JSON response with Address
30,103
protected function throwNumberFormatterException ( IntlNumberFormatter $ intlFormatter , $ number ) : void { $ error_code = $ intlFormatter -> getErrorCode ( ) ; if ( is_scalar ( $ number ) ) { $ val = ( string ) $ number ; } else { $ val = 'type: ' . gettype ( $ number ) ; } throw new Exception \ RuntimeException ( __METHOD__ . " Cannot format value '$val', Intl/NumberFormatter error code: $error_code." ) ; }
Throws an Exception when number cannot be formatted .
30,104
public function has ( string $ name ) : bool { if ( Arr :: keyExists ( $ this -> registry , $ name ) ) { return true ; } else { return false ; } }
Checks if an object with this name is in the registry .
30,105
public function set ( string $ name , $ value = null ) : void { Arr :: set ( $ this -> registry , $ name , $ value ) ; }
Registers a given value under a given name .
30,106
public function get ( string $ name , $ default = null ) { if ( ! $ this -> has ( $ name ) ) { throw new \ RuntimeException ( 'No item "' . $ name . '" exists in the registry.' ) ; } return Arr :: get ( $ this -> registry , $ name , $ default ) ; }
Get item from the registry .
30,107
private function getIndexForObject ( $ object ) { $ reflClass = new ReflectionClass ( $ object ) ; $ annotation = $ this -> reader -> getClassAnnotation ( $ reflClass , '\Keratine\Lucene\Mapping\Annotation\Indexable' ) ; if ( ! $ annotation ) { return ; } if ( empty ( $ annotation -> index ) ) { AnnotationException :: requiredError ( 'index' , '\Keratine\Lucene\Mapping\Annotation\Indexable' , $ object , 'string' ) ; } if ( false === isset ( $ this -> indices [ $ annotation -> index ] ) ) { throw new \ Exception ( sprintf ( 'Unknown index "%s".' , $ annotation -> index ) ) ; } if ( false === $ this -> indices [ $ annotation -> index ] instanceof SearchIndexInterface ) { throw new \ Exception ( sprintf ( 'Index "%s" must be an instance of "ZendSearch\Lucene\SearchIndexInterface". "%s" given.' , $ annotation -> index , is_object ( $ this -> indices [ $ annotation -> index ] ) ? get_class ( $ this -> indices [ $ annotation -> index ] ) : $ this -> indices [ $ annotation -> index ] ) ) ; } return $ this -> indices [ $ annotation -> index ] ; }
Gets the Lucene index to the related object
30,108
public function index ( $ object ) { $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; foreach ( $ this -> index -> find ( 'id:' . $ accessor -> getValue ( $ object , 'id' ) ) as $ hit ) { $ this -> index -> delete ( $ hit -> id ) ; } $ doc = new Document ( ) ; $ doc -> addField ( Field :: keyword ( 'id' , $ accessor -> getValue ( $ object , 'id' ) ) ) ; $ doc -> addField ( Field :: unIndexed ( 'entityClass' , get_class ( $ object ) ) ) ; $ reflClass = new ReflectionClass ( $ object ) ; foreach ( $ reflClass -> getProperties ( ) as $ property ) { $ reflProperty = new \ ReflectionProperty ( $ object , $ property -> name ) ; $ annotation = $ this -> reader -> getPropertyAnnotation ( $ reflProperty , '\Keratine\Lucene\Mapping\Annotation\DocumentField' ) ; if ( $ annotation ) { $ value = $ accessor -> getValue ( $ object , $ property -> name ) ; $ value = $ this -> ensureString ( $ value ) ; switch ( $ annotation -> type ) { case 'keyword' : $ doc -> addField ( Field :: keyword ( $ property -> name , $ value , 'UTF-8' ) ) ; break ; case 'unIndexed' : $ doc -> addField ( Field :: unIndexed ( $ property -> name , $ value , 'UTF-8' ) ) ; break ; case 'binary' : $ doc -> addField ( Field :: binary ( $ property -> name , $ value ) ) ; break ; case 'text' : $ doc -> addField ( Field :: text ( $ property -> name , $ value , 'UTF-8' ) ) ; break ; case 'unStored' : default : $ doc -> addField ( Field :: unStored ( $ property -> name , $ value , 'UTF-8' ) ) ; break ; } } } $ this -> index -> addDocument ( $ doc ) ; $ this -> index -> commit ( ) ; }
Create or update an indexed document
30,109
public function validateOrFail ( ) { $ passed = $ this -> validate ( ) ; if ( ! $ passed ) { throw new ValidationException ( $ this -> validator , $ this -> getErrorCodes ( ) ) ; } return true ; }
Validate data and throw an exception on failure .
30,110
public function withModel ( IlluminateModel $ model ) { $ this -> model = $ model ; $ this -> setValidationVariables ( $ model -> toArray ( ) ) ; return $ this ; }
Set model to validate .
30,111
public function getRules ( ) { $ group = $ this -> group ; if ( empty ( $ group ) ) { throw new GroupRulesNotFoundException ( 'No group has been provided' ) ; } if ( ! array_key_exists ( $ group , $ this -> rules ) ) { throw new GroupRulesNotFoundException ( sprintf ( 'Group [%s] not found in rules array' , $ group ) ) ; } return $ this -> prepareRules ( $ this -> rules [ $ group ] ) ; }
Retrieve validation rules .
30,112
protected function setValidationVariables ( array $ data , $ nestedKey = null ) { foreach ( $ data as $ key => $ value ) { $ key = ! empty ( $ nestedKey ) ? $ nestedKey . '.' . $ key : $ key ; if ( is_array ( $ value ) ) { $ this -> setValidationVariables ( $ value , $ key ) ; } else { $ this -> variables [ '{:' . $ key . '}' ] = $ value ; } } return $ this ; }
Set validation variables .
30,113
protected function prepareRules ( array $ rules ) { $ preparedRules = [ ] ; foreach ( $ rules as $ key => $ tests ) { $ tests = ! is_array ( $ tests ) ? explode ( '|' , $ tests ) : $ tests ; $ preparedTests = [ ] ; foreach ( $ tests as $ test ) { $ test = str_replace ( array_keys ( $ this -> variables ) , array_values ( $ this -> variables ) , $ test ) ; $ test = preg_replace ( '|{:.*}|is' , 'null' , $ test ) ; $ preparedTests [ ] = $ test ; } $ preparedRules [ $ key ] = $ preparedTests ; } return $ preparedRules ; }
Prepare rules and each rule s tests .
30,114
public function getHtmlErrorCode ( $ pos , $ before = 30 , $ after = 40 ) { return substr ( $ this -> _html , $ pos - $ before , $ before + $ after ) ; }
return a part of the HTML code for error message
30,115
public static function _dir ( string $ folder ) : bool { if ( is_dir ( $ folder ) ) { return true ; } mkdir ( $ folder , 0777 , true ) ; return false ; }
Create folder it doesn t exist .
30,116
public static function boot ( ) : object { ModulusCLI :: $ appdir = config ( 'app.dir' ) ; ModulusCLI :: $ approot = config ( 'app.root' ) ; $ app = new Application ( 'Modulus Craftsman' , ( new ModulusCLI ) -> getVersion ( ) ) ; $ app -> load ( ModulusCLI :: config ( ) ) ; Self :: autoload_plugins ( true , $ app ) ; return $ app ; }
Boot the modulusPHP CLI
30,117
public function getVersion ( ) { $ composerJson = config ( 'app.dir' ) . 'composer.json' ; if ( file_exists ( $ composerJson ) ) { $ composer = json_decode ( file_get_contents ( $ composerJson , true ) ) ; $ version = isset ( $ composer -> version ) ? $ composer -> version : '1' ; $ require = isset ( $ composer -> require ) ? ( array ) $ composer -> require : false ; if ( ! is_array ( $ require ) ) return "{$version} (1)" ; if ( isset ( $ require [ 'modulusphp/framework' ] ) ) { return $ version . " ({$require['modulusphp/framework']})" ; } else { return "{$version} (1)" ; } } return '1' ; }
Get application version from composer file
30,118
public function getNamespaces ( ) { $ result = [ ] ; foreach ( $ this -> registry [ NamespaceExtension :: class ] as $ extension ) { foreach ( $ extension -> getNamespaces ( ) as $ prefix => $ namespace ) { $ result [ $ prefix ] = $ namespace ; } } return $ result ; }
Return additional XML namespaces .
30,119
public function findByProduct ( $ product , array $ options = array ( ) ) { if ( ! $ product instanceof Product ) { $ product = $ this -> api ( 'subbly.product' ) -> find ( $ product ) ; } $ query = $ this -> newCollectionQuery ( $ options ) ; $ query -> with ( array ( 'product' => function ( $ query ) use ( $ product ) { $ query -> where ( 'uid' , '=' , $ product -> uid ) ; } ) ) ; return new Collection ( $ query ) ; }
Find a ProductCategory by Product .
30,120
public function create ( $ productCategory , $ product ) { if ( ! $ product instanceof Product ) { $ product = $ this -> api ( 'subbly.product' ) -> find ( $ product ) ; } if ( $ product instanceof Product ) { if ( $ this -> fireEvent ( 'creating' , array ( $ productCategory , $ product ) ) === false ) { return false ; } $ product -> categories ( ) -> sync ( $ productCategory ) ; $ this -> fireEvent ( 'created' , array ( $ productCategory , $ product ) ) ; return true ; } throw new Exception ( sprintf ( Exception :: CANT_CREATE_MODEL , $ this -> modelClass , $ this -> name ( ) ) ) ; }
Create a new ProductCategory .
30,121
public function update ( ) { $ args = func_get_args ( ) ; $ productCategory = null ; if ( count ( $ args ) == 1 && $ args [ 0 ] instanceof ProductCategory ) { $ productCategory = $ args [ 0 ] ; } elseif ( count ( $ args ) == 2 && ! empty ( $ args [ 0 ] ) && is_array ( $ args [ 1 ] ) ) { $ productCategory = $ this -> find ( $ args [ 0 ] ) ; $ productCategory -> fill ( $ args [ 1 ] ) ; } if ( $ productCategory instanceof ProductCategory ) { if ( $ this -> fireEvent ( 'updating' , array ( $ productCategory ) ) === false ) { return false ; } $ productCategory -> setCaller ( $ this ) ; $ productCategory -> save ( ) ; $ this -> fireEvent ( 'updated' , array ( $ productCategory ) ) ; return $ productCategory ; } throw new Exception ( sprintf ( Exception :: CANT_UPDATE_MODEL , 'Subbly\\Model\\ProductCategory' , $ this -> name ( ) ) ) ; }
Update a ProductCategory .
30,122
public function delete ( $ productCategory ) { if ( ! is_object ( $ productCategory ) ) { $ productCategory = $ this -> find ( $ productCategory ) ; } if ( $ productCategory instanceof ProductCategory ) { if ( $ this -> fireEvent ( 'deleting' , array ( $ productCategory ) ) === false ) { return false ; } $ productCategory -> delete ( $ this ) ; $ this -> fireEvent ( 'deleted' , array ( $ productCategory ) ) ; } }
Delete a ProductCategory .
30,123
public function set ( $ key , $ definition = [ ] ) { $ this -> _definitions [ $ key ] = $ this -> formatDefinition ( $ key , $ definition ) ; unset ( $ this -> _singletons [ $ key ] ) ; return $ this ; }
set a key - callback with this container .
30,124
public function setShared ( $ key , $ definition = [ ] ) { $ this -> _definitions [ $ key ] = $ this -> formatDefinition ( $ key , $ definition ) ; $ this -> _singletons [ $ key ] = null ; return $ this ; }
set singleton callback or object
30,125
public function remove ( $ key ) { unset ( $ this -> _definitions [ $ key ] , $ this -> _singletons [ $ key ] ) ; foreach ( $ this -> _aliases as $ alias => $ akey ) { if ( $ akey === $ key ) { unset ( $ this -> _aliases [ $ alias ] ) ; break ; } } }
Removes by key
30,126
protected function formatDefinition ( $ class , $ definition ) { if ( empty ( $ definition ) ) { return [ 'class' => $ class ] ; } elseif ( is_callable ( $ definition , false ) || is_object ( $ definition ) ) { return $ definition ; } elseif ( is_string ( $ definition ) ) { if ( strpos ( $ definition , ':' ) !== false ) { return $ definition ; } return [ 'class' => $ definition ] ; } elseif ( is_array ( $ definition ) ) { if ( ! isset ( $ definition [ 'class' ] ) ) { if ( strpos ( $ class , '\\' ) !== false ) { $ definition [ 'class' ] = $ class ; } elseif ( isset ( $ definition [ 0 ] ) && is_string ( $ definition [ 0 ] ) && strpos ( $ definition [ 0 ] , '\\' ) !== false ) { $ definition [ 'class' ] = $ definition [ 0 ] ; unset ( $ definition [ 0 ] ) ; } else { throw new InvalidConfigException ( "A class definition requires a \"class\" member." ) ; } } return $ definition ; } else { throw new InvalidConfigException ( "Unsupported definition type for \"$class\": " . gettype ( $ definition ) ) ; } }
format the class definition .
30,127
protected function build ( $ class , $ config ) { list ( $ reflection , $ dependencies ) = $ this -> getDependencies ( $ class ) ; $ dependencies = $ this -> resolveDependencies ( $ dependencies , $ reflection ) ; if ( empty ( $ config ) ) { return $ reflection -> newInstanceArgs ( $ dependencies ) ; } if ( ! empty ( $ dependencies ) && $ reflection -> implementsInterface ( 'Wslim\Common\ConfigurableInterface' ) ) { $ dependencies [ count ( $ dependencies ) - 1 ] = $ config ; return $ reflection -> newInstanceArgs ( $ dependencies ) ; } else { $ object = $ reflection -> newInstanceArgs ( $ dependencies ) ; foreach ( $ config as $ name => $ value ) { $ method = 'set' . ucfirst ( $ name ) ; if ( method_exists ( $ object , $ method ) ) { $ object -> $ method ( $ value ) ; } else { $ object -> $ name = $ value ; } } return $ object ; } }
Creates an instance of the specified class . This method will resolve dependencies of the specified class instantiate them and inject them into the new instance of the specified class .
30,128
public function render ( $ force = false ) { $ template = $ this -> getTemplate ( ) ; $ tag = $ this -> getTag ( ) ; $ variables = [ ] ; $ children = $ this -> getChildren ( ) ; $ attributes = $ this -> getAttributes ( ) ; $ innerHtml = $ this -> getInnerHtml ( ) ; $ renderer = $ this -> getRenderer ( ) ; $ result = $ renderer -> render ( $ force , $ template , $ tag , $ variables , $ children , $ attributes , $ innerHtml ) ; return $ result ; }
Hook on default renderer for some slighty required modifications on input .
30,129
public function addChild ( Doozr_Form_Service_Component_Interface_Html $ child , $ id = null ) { $ id = ( $ id === null ) ? count ( $ this -> children ) : $ id ; $ this -> children [ $ id ] = $ child ; $ this -> notify ( ) ; return $ id ; }
Adds a child to the component .
30,130
public function removeChild ( $ index ) { if ( ! isset ( $ this -> children [ $ index ] ) ) { $ result = null ; } else { $ result = ( array_splice ( $ this -> children , $ index , 1 ) !== null ) ; } $ this -> notify ( ) ; return $ result ; }
Removes a child from the component .
30,131
public function getChild ( $ id ) { return isset ( $ this -> children [ $ id ] ) ? $ this -> children [ $ id ] : null ; }
Returns a child by passed Id .
30,132
public function getRegistry ( $ key = null , $ default = null ) { $ result = $ this -> registry ; if ( $ key !== null ) { $ result = ( isset ( $ result [ $ key ] ) ) ? $ result [ $ key ] : $ default ; } return $ result ; }
Getter for registry .
30,133
static public function getAvailableAdapters ( ) { $ pdoAdapters = ( class_exists ( 'Pdo' , false ) ) ? \ PDO :: getAvailableDrivers ( ) : array ( ) ; return array ( 'mysql' => ( class_exists ( 'mysqli' , false ) ) , 'oracle' => ( function_exists ( 'oci_connect' ) ) , 'pdo' => array ( 'mysql' => ( in_array ( 'mysql' , $ pdoAdapters ) ) , 'pgsql' => ( in_array ( 'pgsql' , $ pdoAdapters ) ) , 'sqlite' => ( in_array ( 'sqlite' , $ pdoAdapters ) ) , 'sqlsrv' => ( in_array ( 'sqlsrv' , $ pdoAdapters ) ) ) , 'pgsql' => ( function_exists ( 'pg_connect' ) ) , 'sqlite' => ( class_exists ( 'Sqlite3' , false ) ) , 'sqlsrv' => ( function_exists ( 'sqlsrv_connect' ) ) ) ; }
Get the available database adapters
30,134
static public function isAvailableAdapter ( $ adapter ) { $ adapter = strtolower ( $ adapter ) ; $ result = false ; $ type = null ; $ pdoAdapters = ( class_exists ( 'Pdo' , false ) ) ? \ PDO :: getAvailableDrivers ( ) : array ( ) ; if ( strpos ( $ adapter , 'pdo_' ) !== false ) { $ type = substr ( $ adapter , 4 ) ; $ adapter = 'pdo' ; } switch ( $ adapter ) { case 'mysql' : case 'mysqli' : $ result = ( class_exists ( 'mysqli' , false ) ) ; break ; case 'oci' : case 'oracle' : $ result = ( function_exists ( 'oci_connect' ) ) ; break ; case 'pdo' : $ result = ( in_array ( $ type , $ pdoAdapters ) ) ; break ; case 'pgsql' : $ result = ( function_exists ( 'pg_connect' ) ) ; break ; case 'sqlite' : $ result = ( class_exists ( 'Sqlite3' , false ) ) ; break ; case 'sqlsrv' : $ result = ( function_exists ( 'sqlsrv_connect' ) ) ; break ; } return $ result ; }
Get the available image library adapters
30,135
public function validEmail ( $ data ) { $ data = array_shift ( $ data ) ; if ( empty ( $ data ) ) { return false ; } if ( is_array ( $ data ) ) { return false ; } $ result = true ; $ emails = explode ( CAKE_SETTINGS_APP_SMTP_EMAIL_DELIM , ( string ) $ data ) ; foreach ( $ emails as $ email ) { $ email = trim ( $ email ) ; if ( ! filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { $ result = false ; } } return $ result ; }
Validation email addresses
30,136
public function validHost ( ) { $ hostalias = 'EmailSmtphost' ; $ portalias = 'EmailSmtpport' ; $ port = CAKE_SETTINGS_APP_SMTP_DEFAULT_PORT ; $ timeLimit = CAKE_SETTINGS_APP_SMTP_TIME_LIMIT ; if ( ! isset ( $ this -> data [ $ this -> alias ] [ $ hostalias ] ) || empty ( $ this -> data [ $ this -> alias ] [ $ hostalias ] ) ) { return true ; } $ result = false ; if ( isset ( $ this -> data [ $ this -> alias ] [ $ portalias ] ) && ctype_digit ( $ this -> data [ $ this -> alias ] [ $ portalias ] ) ) { $ port = $ this -> data [ $ this -> alias ] [ $ portalias ] ; } $ fp = @ fsockopen ( $ this -> data [ $ this -> alias ] [ $ hostalias ] , $ port , $ errno , $ errstr , $ timeLimit ) ; if ( $ fp ) { $ result = true ; fclose ( $ fp ) ; } return $ result ; }
Checking connection with the host through the specified port .
30,137
protected function _getDefaultSchemaData ( ) { $ configAcLimit = $ this -> _modelConfigSettingsApp -> getFlagConfigAcLimit ( ) ; $ configADsearch = $ this -> _modelConfigSettingsApp -> getFlagConfigADsearch ( ) ; $ configSMTP = $ this -> _modelConfigSettingsApp -> getFlagConfigSmtp ( ) ; $ configExtAuth = $ this -> _modelConfigSettingsApp -> getFlagConfigExtAuth ( ) ; $ defaultSchema = $ this -> _schemaData ; $ excludeFields = [ ] ; if ( ! $ configAcLimit ) { $ excludeFields [ ] = 'AutocompleteLimit' ; } if ( ! $ configADsearch ) { $ excludeFields [ ] = 'Company' ; $ excludeFields [ ] = 'SearchBase' ; } if ( ! $ configSMTP ) { $ excludeFields [ ] = 'EmailSmtphost' ; $ excludeFields [ ] = 'EmailSmtpport' ; $ excludeFields [ ] = 'EmailSmtpuser' ; $ excludeFields [ ] = 'EmailSmtppassword' ; $ excludeFields [ ] = 'EmailNotifyUser' ; } if ( ! $ configExtAuth ) { $ excludeFields [ ] = 'ExternalAuth' ; } $ result = array_diff_key ( $ defaultSchema , array_flip ( $ excludeFields ) ) ; return $ result ; }
Returns an array of default settings fields metadata
30,138
public function getFullSchema ( ) { $ authGroups = $ this -> getAuthGroupsList ( ) ; $ authSchema = [ ] ; $ defaultSchema = $ this -> _getDefaultSchemaData ( ) ; $ extendSchema = $ this -> _modelConfigSettingsApp -> getExtendSchemaData ( ) ; if ( ! empty ( $ authGroups ) ) { foreach ( $ authGroups as $ authGroupField ) { $ authSchema [ $ authGroupField ] = [ 'type' => 'string' , 'default' => '' ] ; } } $ result = $ defaultSchema + $ authSchema + $ extendSchema ; return $ result ; }
Returns an array of settings fields metadata
30,139
public function getDefaultConfig ( ) { $ configs = [ ] ; $ schema = $ this -> getFullSchema ( ) ; foreach ( $ schema as $ field => $ metadata ) { $ configs [ $ this -> alias ] [ $ field ] = Hash :: get ( $ metadata , 'default' ) ; } return $ configs ; }
Returns an array of values default settings
30,140
protected function _getAuthFieldsList ( $ field = null ) { $ authGroups = $ this -> _modelConfigSettingsApp -> getAuthGroups ( ) ; $ result = [ ] ; if ( empty ( $ field ) ) { return $ result ; } foreach ( $ authGroups as $ userRole => $ authInfo ) { if ( ! isset ( $ authInfo [ $ field ] ) || empty ( $ authInfo [ $ field ] ) ) { continue ; } $ result [ $ userRole ] = $ authInfo [ $ field ] ; } return $ result ; }
Returns an array of authentication group information
30,141
public function getAuthRoleName ( $ role = null ) { $ role = ( int ) $ role ; $ result = '' ; if ( $ role === 0 ) { return $ result ; } $ roleNames = $ this -> _getAuthFieldsList ( 'name' ) ; if ( empty ( $ roleNames ) ) { return $ result ; } if ( ! krsort ( $ roleNames ) ) { return $ result ; } foreach ( $ roleNames as $ roleMask => $ roleName ) { if ( ( $ role & $ roleMask ) === $ roleMask ) { $ result = $ roleName ; break ; } } return $ result ; }
Get name for user role
30,142
public function getUiLangsList ( ) { $ result = [ ] ; $ UIlangs = $ this -> _modelConfigSettingsApp -> getUiLangs ( ) ; if ( empty ( $ UIlangs ) ) { return $ result ; } $ language = new Language ( ) ; foreach ( $ UIlangs as $ country => $ UIlang ) { $ langName = $ language -> convertLangCode ( $ UIlang , 'native' ) ; if ( empty ( $ langName ) ) { continue ; } $ result [ $ country ] = mb_ucfirst ( $ langName ) ; } return $ result ; }
Get list of UI languages
30,143
protected function _getUlangInfo ( $ key = null , $ reverse = false ) { $ result = '' ; if ( empty ( $ key ) ) { return $ result ; } $ UIlangs = $ this -> _modelConfigSettingsApp -> getUiLangs ( ) ; if ( empty ( $ UIlangs ) ) { return $ result ; } if ( $ reverse ) { $ UIlangs = array_flip ( $ UIlangs ) ; } if ( isset ( $ UIlangs [ $ key ] ) ) { $ result = $ UIlangs [ $ key ] ; } return $ result ; }
Return information about language of UI
30,144
public function isAuthGroupConfigured ( ) { $ markerFile = $ this -> getPathMarkerFile ( ) ; if ( $ this -> _checkMarkerFile ( $ markerFile ) ) { return true ; } $ authGroupsList = $ this -> getAuthGroupsList ( ) ; if ( empty ( $ authGroupsList ) ) { return false ; } foreach ( $ authGroupsList as $ fieldName ) { if ( ! $ this -> getConfig ( $ fieldName ) ) { return false ; } } return $ this -> _createMarkerFile ( $ markerFile ) ; }
Check application is correctly configured
30,145
protected function _createMarkerFile ( $ path = null ) { if ( empty ( $ path ) ) { return false ; } $ oFile = new File ( $ path , true ) ; $ now = time ( ) ; $ data = 'Configuration date: ' . CakeTime :: i18nFormat ( $ now , '%x %X' ) ; if ( ! $ oFile -> write ( $ data , 'w' , true ) ) { return false ; } return $ oFile -> close ( ) ; }
Create marker file
30,146
private function render ( ) { add_action ( 'admin_notices' , function ( ) { if ( is_array ( $ this -> message ) && ! empty ( $ this -> message ) ) { echo '<div class="error notice">' ; echo '<ul>' ; foreach ( $ this -> message as $ message ) { echo '<li>' . $ message . '</li>' ; } echo '</ul>' ; echo '</div>' ; $ this -> message = array ( ) ; } } ) ; }
Render active error messages
30,147
protected function thawArray ( array & $ array , array $ frozenObject , array & $ objects ) { foreach ( $ array as & $ value ) { if ( is_array ( $ value ) ) { $ this -> thawArray ( $ value , $ frozenObject , $ objects ) ; } elseif ( is_string ( $ value ) && strpos ( $ value , '__php_object_freezer' ) === 0 ) { $ aggregatedObjectId = str_replace ( '__php_object_freezer_' , '' , $ value ) ; if ( isset ( $ frozenObject [ 'objects' ] [ $ aggregatedObjectId ] ) ) { $ value = $ this -> thaw ( $ frozenObject , $ aggregatedObjectId , $ objects ) ; } } } }
Thaws an array .
30,148
private function getSelectQuery ( ) { $ result = $ this -> getSelectClause ( ) ; if ( $ join = $ this -> getJoinClause ( ) ) { $ result .= ' ' . $ join ; } if ( $ where = $ this -> getWhereClause ( ) ) { $ result .= ' ' . $ where ; } if ( $ groupBy = $ this -> getGroupByClause ( ) ) { $ result .= ' ' . $ groupBy ; } if ( $ orderBy = $ this -> getOrderByClause ( ) ) { $ result .= ' ' . $ orderBy ; } if ( $ limit = $ this -> getLimitClause ( ) ) { $ result .= ' ' . $ limit ; } if ( $ offset = $ this -> getOffsetClause ( ) ) { $ result .= ' ' . $ offset ; } return $ result ; }
Returns the select query .
30,149
private function getInsertClause ( ) { $ columns = [ ] ; $ values = [ ] ; foreach ( $ this -> values as $ key => $ value ) { $ columns [ ] = $ key ; $ values [ ] = sprintf ( '%s' , $ value ) ; } return sprintf ( 'INSERT INTO %s (%s) VALUES (%s)' , $ this -> table , implode ( ', ' , $ columns ) , implode ( ', ' , $ values ) ) ; }
Returns the insert clause .
30,150
private function getUpdateClause ( ) { $ placeholders = [ ] ; foreach ( $ this -> values as $ key => $ value ) { $ placeholders [ ] = sprintf ( '%s = %s' , $ key , $ value ) ; } return sprintf ( 'UPDATE %s SET %s' , $ this -> table , implode ( ', ' , $ placeholders ) ) ; }
Returns the update clause .
30,151
private function getUpdateQuery ( ) { $ result = $ this -> getUpdateClause ( ) ; if ( $ where = $ this -> getWhereClause ( ) ) { $ result .= ' ' . $ where ; } if ( $ limit = $ this -> getLimitClause ( ) ) { $ result .= ' ' . $ limit ; } return $ result ; }
Returns the update query .
30,152
private function getDeleteQuery ( ) { $ result = $ this -> getDeleteClause ( ) ; if ( $ where = $ this -> getWhereClause ( ) ) { $ result .= ' ' . $ where ; } if ( $ limit = $ this -> getLimitClause ( ) ) { $ result .= ' ' . $ limit ; } return $ result ; }
Returns the delete query .
30,153
private function getWhereClause ( ) { if ( empty ( $ this -> where ) ) { return '' ; } $ result = [ ] ; foreach ( $ this -> where as $ key => $ value ) { $ result [ ] = $ this -> getWhereCondition ( $ value [ 0 ] , $ value [ 1 ] , $ value [ 2 ] ) ; } return sprintf ( 'WHERE %s' , implode ( ' AND ' , $ result ) ) ; }
Returns the where clause .
30,154
private function getWhereCondition ( $ column , $ operator , $ value ) { if ( $ operator == 'IN' ) { return sprintf ( '%s IN (%s)' , $ column , is_array ( $ value ) ? implode ( ', ' , $ value ) : $ value ) ; } else { return sprintf ( '%s %s %s' , $ column , $ operator , $ value ) ; } }
Returns the where condition .
30,155
public function index ( ) { $ memberTags = MemberTag :: onTeam ( ) -> orderBy ( 'name' , 'asc' ) -> paginate ( config ( 'app.pagination_default' ) ) ; return fractal ( $ memberTags , new MemberTagTransformer ( ) ) -> withResourceName ( 'memberTag' ) -> respond ( ) ; }
List MemberTags for the Team currently selected in the User s context
30,156
public function store ( Request $ request ) { $ request -> validate ( [ 'description' => 'max:256' , 'name' => 'required|max:32' , ] ) ; $ memberTag = new MemberTag ( ) ; $ this -> authorize ( 'store' , $ memberTag ) ; $ memberTag -> team_id = $ this -> userContext ( ) -> team_id ; if ( $ request -> has ( 'description' ) ) { $ memberTag -> description = $ request -> description ; } $ memberTag -> name = $ request -> name ; $ memberTag -> save ( ) ; return fractal ( $ memberTag , new MemberTagTransformer ( ) ) -> withResourceName ( 'memberTag' ) -> respond ( ) ; }
Store a new MemberTag
30,157
public function update ( Request $ request , $ id ) { $ request -> validate ( [ 'description' => 'max:256' , 'name' => 'required|max:32' , ] ) ; $ memberTag = MemberTag :: findOrFail ( $ id ) ; $ this -> authorize ( 'update' , $ memberTag ) ; if ( $ request -> has ( 'description' ) ) { $ memberTag -> description = $ request -> description ; } $ memberTag -> name = $ request -> name ; $ memberTag -> save ( ) ; return fractal ( $ memberTag , new MemberTagTransformer ( ) ) -> withResourceName ( 'memberTag' ) -> respond ( ) ; }
Store an updated MemberTag
30,158
protected function createFromUrl ( $ file ) { $ ch = curl_init ( $ file ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 0 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; $ rawFile = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; $ ori_name = pathinfo ( $ file ) ; $ name = $ ori_name [ 'basename' ] ; $ filePath = sys_get_temp_dir ( ) . "/$name" ; file_put_contents ( $ filePath , $ rawFile ) ; return new File ( $ filePath ) ; }
Fetch a remote file using a string URL and convert it into an instance of Expstudio \ LaraClip \ File \ File .
30,159
public function process ( PricingSetInterface $ pricingSet , $ context = null ) { $ rp = new \ ReflectionProperty ( $ pricingSet , 'valueElement' ) ; $ rp -> setAccessible ( true ) ; if ( null == $ rp -> getValue ( $ pricingSet ) ) { $ rp -> setValue ( $ pricingSet , new TotalDoughValueElement ( ) ) ; } $ rp -> setAccessible ( false ) ; $ newPricingSet = $ pricingSet -> process ( $ context ) ; return $ newPricingSet ; }
Process an existing pricing set
30,160
public function run ( ) { try { return $ this -> preRun ( ) -> check ( ) ; } catch ( Exception $ e ) { return $ this -> setMessage ( $ e -> getMessage ( ) ) -> setCode ( $ e -> getCode ( ) ) ; } }
Performs the Icinga check .
30,161
protected function prepareArguments ( array $ recipe , array $ arguments ) { if ( true === isset ( $ recipe [ 'arguments' ] ) ) { $ recipe [ 'arguments' ] = array_merge ( $ recipe [ 'arguments' ] , $ arguments ) ; } else { $ recipe [ 'arguments' ] = $ arguments ; } return $ recipe ; }
Prepares the arguments in recipe either by creating them or merging runtime arguments in .
30,162
protected function instantiate ( $ recipe , array $ arguments = [ ] ) { $ recipe = $ this -> prepareArguments ( $ recipe , $ arguments ) ; $ injections = $ this -> initInjectionMapSkeleton ( ) ; if ( true === isset ( $ recipe [ 'dependencies' ] ) && null !== $ recipe [ 'dependencies' ] ) { foreach ( $ recipe [ 'dependencies' ] as $ dependency ) { if ( null === $ dependency -> getInstance ( ) ) { if ( true === $ dependency -> hasLink ( ) ) { if ( null === $ instance = $ this -> getRegistry ( ) -> get ( $ dependency -> getLink ( ) ) ) { $ instance = $ this -> getRegistry ( ) -> getContainer ( ) -> build ( $ dependency -> getLink ( ) ) ; } if ( null === $ instance ) { throw new Doozr_Di_Exception ( sprintf ( 'Link to "%s" could not be resolved/satisfied by registry instance of type "%s".' , $ dependency -> getLink ( ) , get_class ( $ this -> getRegistry ( ) ) ) ) ; } $ dependency -> setInstance ( $ instance ) ; } else { if ( null === $ className = $ dependency -> getClassName ( ) ) { throw new Doozr_Di_Exception ( sprintf ( 'Property "className" not set! If you are not using "link" then you need to ' . 'define the class to inject via "className".' ) ) ; } if ( null === $ constructor = $ dependency -> getConstructor ( ) ) { $ constructor = self :: parseConstructor ( new \ ReflectionClass ( $ className ) ) ; $ dependency -> setConstructor ( $ constructor ) ; } $ instance = $ this -> instantiate ( [ 'className' => $ className , 'constructor' => $ constructor , 'arguments' => $ dependency -> getArguments ( ) , ] ) ; $ dependency -> setInstance ( $ instance ) ; } } if ( null === $ dependency -> getPosition ( ) ) { $ position = ( isset ( $ injections [ $ dependency -> getType ( ) ] ) ) ? count ( $ injections [ $ dependency -> getType ( ) ] ) + 1 : 1 ; $ dependency -> setPosition ( $ position ) ; } $ injections [ $ dependency -> getType ( ) ] [ ] = [ 'instance' => $ dependency -> getInstance ( ) , 'position' => $ dependency -> getPosition ( ) , 'target' => $ dependency -> getTarget ( ) , ] ; } } return $ this -> createInstance ( $ recipe [ 'className' ] , $ recipe [ 'constructor' ] , $ arguments , $ injections ) ; }
Instantiates a class including it dependencies .
30,163
protected function createInstance ( $ className , $ constructor = null , array $ arguments = [ ] , array $ injections = [ ] ) { if ( count ( $ injections [ Doozr_Di_Constants :: INJECTION_TYPE_CONSTRUCTOR ] ) > 0 ) { $ constructorInjections = $ this -> parseInjections ( Doozr_Di_Constants :: INJECTION_TYPE_CONSTRUCTOR , $ injections ) ; if ( null !== $ constructorInjections ) { $ arguments = $ this -> mergeArguments ( $ constructorInjections , $ arguments ) ; } } $ instance = $ this -> constructorInjection ( $ className , $ arguments , $ constructor ) ; if ( count ( $ injections [ Doozr_Di_Constants :: INJECTION_TYPE_METHOD ] ) > 0 ) { $ methodInjections = $ this -> parseInjections ( Doozr_Di_Constants :: INJECTION_TYPE_METHOD , $ injections ) ; if ( null !== $ methodInjections ) { $ this -> methodInjection ( $ instance , $ methodInjections ) ; } } if ( count ( $ injections [ Doozr_Di_Constants :: INJECTION_TYPE_PROPERTY ] ) > 0 ) { $ propertyInjections = $ this -> parseInjections ( Doozr_Di_Constants :: INJECTION_TYPE_PROPERTY , $ injections ) ; if ( null !== $ propertyInjections ) { $ this -> propertyInjection ( $ instance , $ propertyInjections ) ; } } return $ instance ; }
Creates an instance of a class and returns it .
30,164
protected function constructorInjection ( $ className , array $ arguments = [ ] , $ constructor = null ) { if ( null === $ constructor ) { $ constructor = self :: parseConstructor ( $ this -> getReflection ( ) ) ; } if ( Doozr_Di_Constants :: CONSTRUCTOR_METHOD !== $ constructor ) { $ className = [ $ className , $ constructor ] ; } return $ this -> construct ( $ className , $ arguments ) ; }
Returns an instance with injected dependencies .
30,165
protected static function parseConstructor ( \ ReflectionClass $ reflectionClass ) { if ( true === $ reflectionClass -> isInstantiable ( ) ) { $ constructor = Doozr_Di_Constants :: CONSTRUCTOR_METHOD ; } else { $ constructorCandidates = $ reflectionClass -> getMethods ( ReflectionMethod :: IS_STATIC ) ; $ constructor = Doozr_Di_Constants :: CONSTRUCTOR_METHOD_SINGLETON ; $ lastProcessedFileName = null ; foreach ( $ constructorCandidates as $ constructorCandidate ) { $ fileName = $ constructorCandidate -> getFileName ( ) ; if ( $ lastProcessedFileName !== $ fileName ) { $ sourcecode = file ( $ fileName ) ; $ lastProcessedFileName = $ fileName ; } $ start = $ constructorCandidate -> getStartLine ( ) + 1 ; $ end = $ constructorCandidate -> getEndLine ( ) - 1 ; $ methodSourcecode = '' ; for ( $ i = $ start ; $ i < $ end ; ++ $ i ) { $ methodSourcecode .= $ sourcecode [ $ i ] ; } if ( strpos ( $ methodSourcecode , 'n' . 'e' . 'w' . ' self(' ) || strpos ( $ methodSourcecode , 'new ' . $ reflectionClass -> getName ( ) . '(' ) ) { $ constructor = $ constructorCandidate -> name ; break ; } } } return $ constructor ; }
Returns constructor of a class by ReflectionClass instance . No matter if singleton or default class .
30,166
protected function parseInjections ( $ type , array $ injections ) { $ result = null ; if ( ! empty ( $ injections [ $ type ] ) ) { $ result = [ ] ; switch ( $ type ) { case Doozr_Di_Constants :: INJECTION_TYPE_PROPERTY : case Doozr_Di_Constants :: INJECTION_TYPE_METHOD : foreach ( $ injections [ $ type ] as $ recipe ) { $ result [ ] = [ 'signature' => $ recipe [ 'target' ] , 'argument' => $ recipe [ 'instance' ] , ] ; } break ; default : case Doozr_Di_Constants :: INJECTION_TYPE_CONSTRUCTOR : return $ injections [ $ type ] ; break ; } } return $ result ; }
Parses out the requested type of injection from list of injections .
30,167
protected function mergeArguments ( array $ injections , array $ arguments ) { $ numberOfArguments = count ( $ injections ) + count ( $ arguments ) ; $ result = array_fill ( 0 , $ numberOfArguments , null ) ; $ countInjections = count ( $ injections ) ; for ( $ i = 0 ; $ i < $ countInjections ; ++ $ i ) { if ( null !== $ injections [ $ i ] [ 'position' ] ) { $ position = $ injections [ $ i ] [ 'position' ] - 1 ; } else { $ position = $ i ; } $ result [ $ position ] = $ injections [ $ i ] [ 'instance' ] ; } foreach ( $ result as $ key => $ value ) { if ( $ result [ $ key ] === null ) { $ result [ $ key ] = array_shift ( $ arguments ) ; } } return $ result ; }
Merges given constructor injections and arguments for constructor .
30,168
public function validate ( array $ values , array $ rules ) { $ result = true ; if ( true !== $ valid = $ this -> validateByRules ( $ rules , $ values ) ) { foreach ( $ valid as $ componentName => $ error ) { $ this -> setError ( $ error , $ componentName ) ; } $ this -> setError ( [ 'error' => 'general' , 'info' => [ ] , ] , Doozr_Form_Service_Constant :: ERROR_IDENTIFIER_FORM ) ; $ result = false ; } return $ result ; }
Validates values by validation rules .
30,169
public function getError ( $ componentName = null , $ default = null ) { $ result = $ default ; if ( null === $ componentName ) { $ result = $ this -> error ; } else { if ( $ this -> hasError ( $ componentName ) ) { $ result = $ this -> error [ $ componentName ] ; } } return $ result ; }
Returns the error of a component .
30,170
public function setAssets ( MvcEvent $ e ) { $ assetsService = $ e -> getApplication ( ) -> getServiceManager ( ) -> get ( 'AcAssets\Service\AssetsService' ) ; $ assetsService -> initHeadLink ( ) -> initHeadScript ( ) -> initInlineScript ( ) ; }
Reads assets from configuration and injects them into view by using view helpers
30,171
protected function registerFlysystems ( Container $ app ) { $ app [ 'flysystem.filesystems' ] = [ ] ; $ app [ 'flysystem.plugins' ] = [ new EmptyDir ( ) , new GetWithMetadata ( ) , new ListFiles ( ) , new ListPaths ( ) , new ListWith ( ) , ] ; $ app [ 'flysystems' ] = function ( Container $ app ) { $ flysystems = new Container ( ) ; foreach ( $ app [ 'flysystem.filesystems' ] as $ alias => $ parameters ) { $ flysystems [ $ alias ] = $ this -> buildFilesystem ( $ app , $ parameters ) ; } return $ flysystems ; } ; $ app [ 'flysystem.mount_manager' ] = function ( Container $ app ) { $ mountManager = new MountManager ( ) ; foreach ( $ app [ 'flysystem.filesystems' ] as $ alias => $ parameters ) { $ mountManager -> mountFilesystem ( $ alias , $ app [ 'flysystems' ] [ $ alias ] ) ; } return $ mountManager ; } ; }
Register this service provider with the Application .
30,172
protected function buildFilesystem ( Container $ app , array $ parameters ) { $ adapter = new \ ReflectionClass ( $ parameters [ 'adapter' ] ) ; $ filesystem = new Filesystem ( $ adapter -> newInstanceArgs ( $ parameters [ 'args' ] ) , $ this -> getConfig ( $ parameters ) ) ; foreach ( $ app [ 'flysystem.plugins' ] as $ plugin ) { $ plugin -> setFilesystem ( $ filesystem ) ; $ filesystem -> addPlugin ( $ plugin ) ; } return $ filesystem ; }
Instantiate an adapter and wrap it in a filesystem .
30,173
static public function uuid ( $ separator = true ) { if ( function_exists ( 'com_create_guid' ) ) { return com_create_guid ( ) ; } else { mt_srand ( ( double ) microtime ( ) * 10000 ) ; $ charid = strtoupper ( md5 ( uniqid ( mt_rand ( ) , true ) ) ) ; $ hyphen = $ separator ? chr ( 45 ) : '' ; $ uuid = substr ( $ charid , 0 , 8 ) . $ hyphen . substr ( $ charid , 8 , 4 ) . $ hyphen . substr ( $ charid , 12 , 4 ) . $ hyphen . substr ( $ charid , 16 , 4 ) . $ hyphen . substr ( $ charid , 20 , 12 ) ; return $ uuid ; } }
get uuid 315B817C - 11F5 - 718F - F7BD - 95E0E95519D0
30,174
public function resolveReader ( ResourceUri $ resource ) { if ( ! array_key_exists ( $ resource -> getProtocol ( ) , $ this -> protocolFactoryIndexes ) ) { throw new \ RuntimeException ( 'Unsupported protocol: ' . $ resource -> getProtocol ( ) . '( ' . $ resource . ')' ) ; } $ factoryIndex = $ this -> protocolFactoryIndexes [ $ resource -> getProtocol ( ) ] ; $ factory = $ this -> factories [ $ factoryIndex ] ; return $ factory -> createReaderFor ( $ resource ) ; }
Resolves a reader for the given resource URI .
30,175
public function delete ( $ table ) { if ( in_array ( $ table , $ this -> tablesToDelete ) === false ) { $ this -> tablesToDelete [ ] = $ table ; } return $ this ; }
Used when selecting multiple tables like joins
30,176
private function getResponseContentType ( ResponseInterface $ response ) : ? string { $ contentType = null ; foreach ( $ this -> listResponseHeaders ( $ response ) as $ header => $ value ) { if ( $ header == 'Content-Type' ) { $ contentType = explode ( ';' , $ value ) [ 0 ] ; } } return $ contentType ; }
Returns the response s content type . If multiple content types are present in the response headers the method retruns the last one .
30,177
public static function isJsonError ( $ response ) { if ( is_wp_error ( $ response ) ) { return true ; } if ( $ decoded = json_decode ( $ response ) ) { $ response = ( array ) $ decoded ; } if ( isset ( $ response [ 'error' ] ) ) { return true ; } return false ; }
Check if the response from the server may be a error response
30,178
public function getForm ( $ id ) { return ( isset ( $ this -> forms [ $ id ] ) ) ? $ this -> forms [ $ id ] : null ; }
Getter for form .
30,179
protected function parseConfigurations ( array $ forms ) { $ countForms = count ( $ forms [ 0 ] ) ; for ( $ i = 0 ; $ i < $ countForms ; ++ $ i ) { $ properties = $ this -> parsePropertiesFromHtml ( $ forms [ 1 ] [ $ i ] ) ; $ configuration = $ this -> prepareStructureAndData ( $ properties ) ; $ id = $ this -> getId ( $ configuration [ 'properties' ] ) ; $ configuration [ 'properties' ] [ 'id' ] = $ id ; $ templateIdentifier = $ this -> buildTemplateIdentifier ( $ id ) ; $ this -> template = str_replace ( $ forms [ 1 ] [ $ i ] , $ templateIdentifier , $ this -> template ) ; $ setup = [ 'form' => [ [ 'tag' => 'form' , 'properties' => $ configuration [ 'properties' ] ] ] , 'elements' => [ ] , ] ; $ elements = $ this -> parseFormTagsFromHtml ( $ forms [ 2 ] [ $ i ] ) ; $ setup [ 'elements' ] = $ this -> parseElements ( $ elements ) ; $ result [ ] = $ setup ; } return $ result ; }
Parses configuration - sets out of passed form - HTML .
30,180
protected function buildTemplateIdentifier ( $ id , $ type = self :: TEMPLATE_IDENTIFIER_FORM ) { $ type = strtoupper ( $ type ) ; return self :: TEMPLATE_BRACKETS_OPEN . self :: TEMPLATE_PREFIX . $ type . '-' . $ id . self :: TEMPLATE_BRACKETS_CLOSE ; }
Builds template identifier by passed id and type .
30,181
protected function parseElements ( array $ elements ) { $ result = [ ] ; $ countElements = count ( $ elements [ 1 ] ) ; pred ( $ elements ) ; for ( $ j = 0 ; $ j < $ countElements ; ++ $ j ) { $ element = $ this -> parsePropertiesFromHtml ( $ elements [ 1 ] [ $ j ] ) ; $ element = $ this -> prepareStructureAndData ( $ element ) ; $ fieldName = ( isset ( $ element [ 'properties' ] [ 'name' ] ) ) ? substr ( $ element [ 'properties' ] [ 'name' ] , 0 , strlen ( Doozr_Form_Service_Constant :: PREFIX ) ) : '' ; if ( $ fieldName !== Doozr_Form_Service_Constant :: PREFIX ) { $ id = $ this -> getId ( $ element [ 'properties' ] ) ; $ element [ 'properties' ] [ 'id' ] = $ id ; $ templateIdentifier = $ this -> buildTemplateIdentifier ( $ id , isset ( $ element [ 'properties' ] [ 'type' ] ) ? $ element [ 'properties' ] [ 'type' ] : $ element [ 'tag' ] ) ; $ this -> template = str_replace ( $ elements [ 1 ] [ $ j ] , $ templateIdentifier , $ this -> template ) ; $ result [ ] = $ element ; } } return $ result ; }
Parses elements from passed array of elements - HTML .
30,182
protected function getId ( array $ data ) { $ result = null ; if ( isset ( $ data [ 'id' ] ) ) { $ result = $ data [ 'id' ] ; } elseif ( isset ( $ data [ 'name' ] ) ) { $ result = $ data [ 'name' ] ; } else { $ result = sha1 ( serialize ( $ data ) ) ; } return $ result ; }
Returns either existing Id from passed data or calculates a new one based on input .
30,183
protected function prepareStructureAndData ( array $ data ) { if ( ! isset ( $ data [ 1 ] ) || ! isset ( $ data [ 2 ] ) || ! isset ( $ data [ 3 ] ) ) { throw new Exception ( 'Array passed to ' . __METHOD__ . ' could not be processed!' ) ; } $ tag = ( $ data [ 1 ] [ 0 ] !== '' ) ? $ data [ 1 ] [ 0 ] : null ; if ( $ tag !== null ) { $ keys = array_slice ( $ data [ 2 ] , 1 ) ; $ values = array_slice ( $ data [ 3 ] , 1 ) ; } else { $ keys = $ data [ 2 ] ; $ values = $ data [ 3 ] ; } $ properties = array_change_key_case ( array_combine ( $ keys , $ values ) , CASE_LOWER ) ; $ result = [ 'tag' => $ tag , 'properties' => $ properties , ] ; return $ result ; }
Takes an array of extracted properties and prepare it s structure and data for further use .
30,184
protected function prefixKeys ( $ prefix , array $ data ) { $ result = [ ] ; foreach ( $ data as $ k => $ v ) { $ result [ $ prefix . $ k ] = $ v ; } return $ result ; }
Apply a string prefix to all ay and return the resulting array .
30,185
protected function buildParamList ( array $ values , $ namePrefix = '' ) { return array_map ( function ( $ key ) use ( $ namePrefix ) { return ':' . $ namePrefix . $ key ; } , array_keys ( $ values ) ) ; }
Build a list of parameter placeholders named using keys from the given array .
30,186
protected function determineLastInsertId ( callable $ callback , $ sequenceName ) { try { switch ( $ this -> driverName ) { case DB :: DRIVER_MYSQL : case DB :: DRIVER_SQLITE : return ( int ) $ callback ( ) ; case DB :: DRIVER_POSTGRESQL : if ( is_array ( $ sequenceName ) ) { $ stmt = $ this -> prepare ( "SELECT currval(pg_get_serial_sequence(:table, :col))" ) ; $ stmt -> bindValue ( 'table' , $ this -> prepareSql ( $ sequenceName [ 0 ] ) ) ; $ stmt -> bindValue ( 'col' , $ sequenceName [ 1 ] ) ; $ stmt -> execute ( ) ; return ( int ) $ stmt -> fetchNextColumn ( 0 ) ; } return $ callback ( $ this -> prepareSql ( $ sequenceName ) ) ; case DB :: DRIVER_MYSQL : $ stmt = $ this -> prepare ( "SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int)" ) ; $ stmt -> execute ( ) ; return ( int ) $ stmt -> fetchNextColumn ( 0 ) ; } return ( int ) $ callback ( $ this -> prepareSql ( $ sequenceName ) ) ; } catch ( \ Exception $ e ) { throw $ this -> convertException ( $ e ) ; } }
Determine the last inserted ID value .
30,187
public function setHipchatParameters ( $ room , $ name , $ host , $ scheme ) { $ this -> room = $ room ; $ this -> name = $ name ; $ this -> httpHost = $ host ; $ this -> httpScheme = $ scheme ; }
Setting parameters for working with HipChat
30,188
protected function write ( array $ record ) { if ( $ record [ 'level' ] < Logger :: ERROR ) { return false ; } if ( isset ( $ record [ 'context' ] [ 'exception' ] ) && ( $ record [ 'context' ] [ 'exception' ] instanceof NotFoundHttpException || $ record [ 'context' ] [ 'exception' ] instanceof AccessDeniedHttpException || $ record [ 'context' ] [ 'exception' ] instanceof ResourceNotFoundException ) ) { return false ; } $ msg = '' ; if ( $ this -> server -> get ( 'HTTP_HOST' ) && $ this -> server -> get ( 'REQUEST_URI' ) ) { $ scheme = $ this -> httpScheme ? $ this -> httpScheme : $ this -> server -> get ( 'REQUEST_SCHEME' ) ; if ( is_null ( $ scheme ) ) { $ https = $ this -> server -> get ( 'HTTPS' ) ; $ scheme = ( empty ( $ https ) || 'off' === $ https ) ? 'http' : 'https' ; } $ host = $ this -> httpHost ? $ this -> httpHost : $ this -> server -> get ( 'HTTP_HOST' ) ; if ( false !== idn_to_utf8 ( $ host ) ) { $ host = idn_to_utf8 ( $ host ) ; } $ msg = sprintf ( 'Request url: %s://%s%s<br/>' , $ scheme , $ host , $ this -> server -> get ( 'REQUEST_URI' ) ) ; } if ( $ this -> post -> count ( ) > 0 || $ this -> get -> count ( ) > 0 ) { $ data = array_merge ( $ this -> post -> all ( ) , $ this -> get -> all ( ) ) ; $ msg .= "Request data: " . json_encode ( $ data ) . "<br>" ; } if ( isset ( $ record [ 'message' ] ) ) { $ msg .= $ record [ 'message' ] ; $ this -> hipchat -> message_room ( $ this -> room , $ this -> name , $ msg , true ) ; return true ; } return false ; }
Send message to HipChat room
30,189
public function defineOptions ( array $ defaults , array $ userOptions = null , $ recursive = false ) { $ this -> options = $ defaults ; if ( $ userOptions ) $ this -> mergeOptions ( $ userOptions , $ recursive ) ; }
Sets the options initially providing default - and optional user options .
30,190
public function mergeOptions ( array $ options , $ recursive = false , $ reverse = false ) { $ merge = 'array_replace' ; if ( $ recursive ) $ merge .= '_recursive' ; $ this -> options = $ reverse ? $ merge ( $ options , $ this -> options ) : $ merge ( $ this -> options , $ options ) ; return $ this ; }
Merges the current options with another option array .
30,191
public function getOption ( $ name , $ defaultValue = null ) { if ( strstr ( $ name , '.' ) ) return Config :: get ( $ name , $ this -> options , $ defaultValue ) ; return isset ( $ this -> options [ $ name ] ) ? $ this -> options [ $ name ] : $ defaultValue ; }
Returns a single option by its name .
30,192
public function forwardOption ( $ name , $ target , $ targetName = null ) { $ targetName = $ targetName ? $ targetName : $ name ; if ( isset ( $ this -> options [ $ name ] ) ) $ this -> options [ $ target ] [ $ targetName ] = $ this -> options [ $ name ] ; }
Forwards an option to an option array .
30,193
protected function calculateCurrentURL ( ) { $ url = "http" ; if ( $ this -> isSecureConnection ( ) ) { $ url .= 's://' . $ _SERVER [ 'SERVER_NAME' ] . ( '443' != $ _SERVER [ 'SERVER_PORT' ] ? ':' . $ _SERVER [ 'SERVER_PORT' ] : '' ) ; } else { $ url .= '://' . $ _SERVER [ 'SERVER_NAME' ] . ( '80' != $ _SERVER [ 'SERVER_PORT' ] ? ':' . $ _SERVER [ 'SERVER_PORT' ] : '' ) ; } $ this -> host = $ _SERVER [ 'SERVER_NAME' ] ; $ this -> currentDomain = $ url . '/' ; $ this -> currentURL = $ url . $ _SERVER [ 'REQUEST_URI' ] ; if ( $ _SERVER [ 'DOCUMENT_ROOT' ] [ strlen ( $ _SERVER [ 'DOCUMENT_ROOT' ] ) - 1 ] == '/' ) { $ docRoot = substr ( $ _SERVER [ 'DOCUMENT_ROOT' ] , 0 , strlen ( $ _SERVER [ 'DOCUMENT_ROOT' ] ) - 1 ) ; } else { $ docRoot = $ _SERVER [ 'DOCUMENT_ROOT' ] ; } $ secondPart = str_replace ( $ docRoot , '' , dirname ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ) . '/' ; $ this -> baseURL = $ url . ( ( '/' == $ secondPart [ 0 ] ) ? $ secondPart : '/' . $ secondPart ) ; }
Calculates current URL and returns it .
30,194
protected function applyModuleConfig ( $ config ) { if ( isset ( $ config [ 'mpf\\web\\request\\HTML' ] ) ) { foreach ( $ config [ 'mpf\\web\\request\\HTML' ] as $ k => $ v ) { $ this -> $ k = $ v ; } } if ( isset ( $ config [ 'mpf\\WebApp' ] ) ) { foreach ( $ config [ 'mpf\\WebApp' ] as $ k => $ v ) { WebApp :: get ( ) -> $ k = $ v ; } } foreach ( $ config as $ class => $ options ) { if ( in_array ( $ class , [ 'namespace' , 'path' ] ) ) continue ; Config :: get ( ) -> set ( $ class , $ options ) ; } return $ this ; }
Updates Config class with values from Module config .
30,195
protected function calculateModulePath ( ) { if ( ! $ this -> module || '/' == $ this -> module ) { $ this -> modulePath = APP_ROOT ; } else { if ( isset ( $ this -> modules [ $ this -> module ] ) && isset ( $ this -> modules [ $ this -> module ] [ 'path' ] ) ) { $ this -> modulePath = $ this -> modules [ $ this -> module ] [ 'path' ] ; } else { $ this -> modulePath = APP_ROOT . 'modules' . DIRECTORY_SEPARATOR . $ this -> module . DIRECTORY_SEPARATOR ; } } }
Calculates module path to be later used for viewers .
30,196
protected function isSecurityException ( ) { if ( ! count ( $ this -> csrfExceptions ) ) return false ; foreach ( $ this -> csrfExceptions as $ route ) { list ( $ module , $ controller , $ action ) = explode ( '/' , $ route ) ; if ( $ module != $ this -> module ) { continue ; } if ( '*' == $ controller ) return true ; if ( $ controller != $ this -> controller ) continue ; if ( '*' == $ action ) return true ; return ( $ action == $ this -> action ) ; } return false ; }
Check if current url is exception for csrf check
30,197
public function getLanguage ( ) { if ( $ this -> language ) return $ this -> language ; if ( $ this -> defaultLanguage ) return $ this -> defaultLanguage ; $ prefered = $ this -> getPreferredLanguage ( ) ; if ( in_array ( $ prefered , $ this -> availableLanguages ) ) return $ prefered ; return $ this -> availableLanguages [ 0 ] ; }
Get current language
30,198
public static function get ( $ options = array ( ) ) { if ( ! isset ( self :: $ _instances [ md5 ( serialize ( $ options ) ) ] ) ) { return new HTML ( $ options ) ; } return self :: $ _instances [ md5 ( serialize ( $ options ) ) ] ; }
Return an instantiated class of HTML
30,199
public function createURL ( $ controller , $ action = null , $ params = array ( ) , $ module = null , $ language = null ) { if ( null == $ controller ) $ controller = $ this -> getController ( ) ; if ( ! $ this -> SEO ) { $ params [ 'controller' ] = $ controller ; $ mod = ( null !== $ module ) ? $ module : $ this -> getModule ( ) ; if ( $ mod != $ this -> defaultModule ) { $ params [ 'module' ] = $ mod ; } if ( $ action ) $ params [ 'action' ] = $ action ; return '?' . http_build_query ( $ params ) ; } $ url = $ this -> getLinkRoot ( ) ; $ language = $ language ? : $ this -> language ; if ( $ language != $ this -> defaultLanguage && ( trim ( $ language ) ) ) { $ url = $ this -> getLinkRoot ( false ) ; $ url .= $ language . '/' ; if ( ! is_null ( $ module ) && ( $ module != $ this -> defaultModule ) ) { $ url .= $ module . '/' ; } } if ( ( ! is_null ( $ module ) ) && $ module != $ this -> module ) { if ( $ this -> module != $ this -> defaultModule ) { if ( $ module == $ this -> defaultModule ) { $ url = str_replace ( '/' . $ this -> module . '/' , '/' , $ url ) ; } else { $ url = str_replace ( '/' . $ this -> module . '/' , '/' . $ module . '/' , $ url ) ; $ params [ 'module' ] = $ this -> module ; } } elseif ( $ module != $ this -> defaultModule ) { $ url .= $ module . '/' ; $ params [ 'module' ] = $ module ; } } elseif ( $ this -> module ) { $ params [ 'module' ] = $ this -> module ; } return $ this -> _createURL ( $ url , $ controller , $ action , $ this -> _prepareParams ( $ params ) ) ; }
Get url to the selected page ;