idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
21,600
public function on ( $ name , $ callback ) { if ( ! is_a ( $ callback , '\Moxy\Event\ListenerInterface' ) ) { if ( ! is_callable ( $ callback ) ) { throw new \ Exception ( 'Event callback must be a callable' ) ; } $ callback = new \ Moxy \ Event \ Listener ( $ callback ) ; } if ( ! array_key_exists ( $ name , self :: $ _events ) ) { self :: $ _events [ $ name ] = new \ Moxy \ Event \ Dispatcher ( $ name ) ; } self :: $ _events [ $ name ] -> addListener ( $ callback ) ; }
Listen for an Event
21,601
public function findByCriteria ( Criteria $ criteria , $ order = null , $ limit = null , $ offset = 0 ) { $ qb = $ this -> createCriteriaQueryBuilder ( $ criteria , 'm' ) ; if ( $ order ) { foreach ( $ order as $ field => $ dir ) { $ qb -> orderBy ( "m.$field" , $ dir ) ; } } if ( $ limit ) { $ qb -> setMaxResults ( $ limit ) ; } if ( $ offset ) { $ qb -> setFirstResult ( $ offset ) ; } return $ qb -> getQuery ( ) -> getResult ( ) ; }
Find messages by criteria .
21,602
private function applyCriteriaToQueryBuilder ( Criteria $ criteria , QueryBuilder $ qb , $ prefix ) { if ( $ criteria -> getMode ( ) === Criteria :: MODE_OR ) { $ expr = $ qb -> expr ( ) -> orX ( ) ; } else { $ expr = $ qb -> expr ( ) -> andX ( ) ; } foreach ( $ criteria as $ criterium ) { if ( $ criterium instanceof Criteria ) { $ expr -> add ( $ this -> applyCriteriaToQueryBuilder ( $ criterium , $ qb , $ prefix ) ) ; } else { $ this -> applyCriteriumToQueryBuilder ( $ criterium , $ qb , $ expr , $ prefix ) ; } } return $ expr ; }
Apply criteria to select .
21,603
public static function removeDirectory ( $ dir = '' ) { if ( $ dir == '' || $ dir == NULL || $ dir == '/' ) return false ; $ files = array_diff ( scandir ( $ dir ) , array ( '.' , '..' ) ) ; foreach ( $ files as $ file ) ( is_dir ( "$dir/$file" ) ) ? CiiFileDeleter :: removeDirectory ( "$dir/$file" ) : unlink ( "$dir/$file" ) ; return rmdir ( $ dir ) ; }
Terrifying function that recursively deletes a directory
21,604
protected function format ( $ str , $ indent = true ) { $ spaces = str_repeat ( ' ' , ( ( int ) $ indent ) * $ this -> indent ) ; return $ spaces . trim ( str_replace ( "\n" , "\n" . $ spaces , ( php_sapi_name ( ) != 'cli' ? htmlspecialchars ( $ str ) : $ str ) ) ) . "\n" ; }
Format output .
21,605
public function ddump ( $ file , $ line , ... $ data ) { static $ last_key = '' ; if ( ( $ is_html = $ this -> isHtml ( ) ) ) { fputs ( $ this -> output , '<pre>' ) ; } $ key = $ file . ':' . $ line ; if ( $ last_key != $ key ) { fputs ( $ this -> output , $ this -> format ( sprintf ( "\n** DEBUG: %s(%d)**\n" , $ file , $ line ) , false ) ) ; $ last_key = $ key ; } if ( extension_loaded ( 'xdebug' ) ) { for ( $ i = 0 , $ cnt = count ( $ data ) ; $ i < $ cnt ; ++ $ i ) { var_dump ( $ data [ $ i ] ) ; } } else { for ( $ i = 0 , $ cnt = count ( $ data ) ; $ i < $ cnt ; ++ $ i ) { ob_start ( array ( $ this , 'format' ) ) ; var_dump ( $ data [ $ i ] ) ; ob_end_flush ( ) ; } } if ( $ is_html ) { fputs ( $ this -> output , '</pre>' ) ; } }
Dump contents of one or multiple variables . This method should not be called directly use global function ddump instead .
21,606
public function error ( $ context , $ context_line , array $ info , $ trace = null , \ Exception $ exception = null ) { if ( ( $ is_html = $ this -> isHtml ( ) ) ) { fputs ( $ this -> output , ' ) ; fputs ( $ this -> output , '<pre>' ) ; } fputs ( $ this -> output , $ this -> format ( sprintf ( "\n** ERROR: %s(%d)**\n" , $ context , $ context_line ) , false ) ) ; $ max = array_reduce ( array_keys ( $ info ) , function ( $ carry , $ key ) { return max ( $ carry , strlen ( $ key ) + 3 ) ; } , 0 ) ; foreach ( $ info as $ key => $ value ) { fputs ( $ this -> output , $ this -> format ( sprintf ( '%-' . $ max . "s %s\n" , $ key . ': ' , $ value ) ) ) ; } if ( is_null ( $ trace ) ) { ob_start ( ) ; debug_print_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS ) ; $ trace = ob_get_contents ( ) ; ob_end_clean ( ) ; } fputs ( $ this -> output , "\n" . $ this -> format ( $ trace ) . "\n" ) ; if ( ! is_null ( $ exception ) ) { throw $ exception ; } elseif ( $ is_html ) { fputs ( $ this -> output , '</pre>' ) ; } }
Output error message with stack trace .
21,607
protected function doComponentPass ( array $ components ) { foreach ( $ components as $ component ) { $ instance = $ this -> container -> injectConstructor ( $ component ) ; $ this -> components [ $ component ] = $ instance ; if ( $ instance instanceof ProviderInterface ) { $ instance -> provides ( $ this ) ; } } foreach ( $ this -> components as $ instance ) { $ instance -> init ( $ this -> providers ) ; DomainEvents :: dispatch ( new InitializedComponentEvent ( $ instance ) ) ; } }
Initialize a group of components .
21,608
public function addProvider ( $ providerName , $ consumer ) { if ( ! class_exists ( $ consumer ) && ! interface_exists ( $ consumer ) ) { throw new InvalidArgumentException ( 'Consumer "' . $ consumer . '" doesn\'t exist for provider "' . $ providerName . '"' ) ; } if ( isset ( $ this -> providers [ $ providerName ] ) ) { throw new DuplicateProviderException ( $ providerName ) ; } $ this -> providers [ $ providerName ] = [ 'consumer' => $ consumer , 'scope' => 'global' ] ; DomainEvents :: dispatch ( new AddedProviderEvent ( $ providerName , $ consumer ) ) ; }
Add global providers
21,609
protected function prettyJson ( $ json , $ istr = ' ' ) { $ result = '' ; for ( $ p = $ q = $ i = 0 ; isset ( $ json [ $ p ] ) ; $ p ++ ) { $ json [ $ p ] == '"' && ( $ p > 0 ? $ json [ $ p - 1 ] : '' ) != '\\' && $ q = ! $ q ; if ( ! $ q && strchr ( " \t\n" , $ json [ $ p ] ) ) { continue ; } if ( strchr ( '}]' , $ json [ $ p ] ) && ! $ q && $ i -- ) { strchr ( '{[' , $ json [ $ p - 1 ] ) || $ result .= "\n" . str_repeat ( $ istr , $ i ) ; } $ result .= $ json [ $ p ] ; if ( strchr ( ',{[' , $ json [ $ p ] ) && ! $ q ) { $ i += strchr ( '{[' , $ json [ $ p ] ) === FALSE ? 0 : 1 ; strchr ( '}]' , $ json [ $ p + 1 ] ) || $ result .= "\n" . str_repeat ( $ istr , $ i ) ; } } return $ result ; }
jsonpp - Pretty print JSON data
21,610
protected function one ( ) { $ query = $ this -> loadElements ( ) ; $ this -> source -> setQuery ( $ query ) ; $ result = $ this -> source -> one ( ) ; $ activeTransformations = $ this -> activeTransformations ; $ this -> reset ( ) ; if ( $ result && ! empty ( $ activeTransformations ) ) { foreach ( $ activeTransformations as $ transform ) { if ( isset ( $ this -> transforms [ $ transform ] ) ) { $ result = call_user_func ( $ this -> transforms [ $ transform ] , $ result ) ; } if ( isset ( $ this -> arraytransforms [ $ transform ] ) ) { $ temp = call_user_func ( $ this -> arraytransforms [ $ transform ] , [ $ result ] ) ; $ result = $ temp [ 0 ] ; } } } $ this -> reset ( ) ; return $ result ; }
call one of these last
21,611
protected function limit ( $ rows , $ offset = false ) { $ this -> query -> setLimit ( $ rows , $ offset ) ; return $ this ; }
Sets the LIMIT for the current query .
21,612
protected function orderBy ( $ columnname_or_columnarray , $ order = 'ASC' , $ useAliases = false ) { if ( ! is_array ( $ columnname_or_columnarray ) ) { $ columnname_or_columnarray = [ $ columnname_or_columnarray ] ; } $ this -> query -> setOrderBy ( $ columnname_or_columnarray , $ order , $ useAliases ) ; return $ this ; }
Sets the order for the query
21,613
protected function groupBy ( $ columnname_or_columnarray ) { if ( ! is_array ( $ columnname_or_columnarray ) ) { $ columnname_or_columnarray = [ $ columnname_or_columnarray ] ; } $ this -> query -> setGroupBy ( $ columnname_or_columnarray ) ; return $ this ; }
Sets the groupby clause
21,614
protected function join ( $ firsttable , $ secondtable , Array $ on , $ type = 'inner' ) { $ this -> query -> setJoin ( $ firsttable , $ secondtable , $ on , strtoupper ( $ type ) ) ; return $ this ; }
Adds a JOIN clause
21,615
protected function getCurrentSQL ( ) { $ cloneQuery = clone $ this -> query ; $ cloneQuery = $ this -> loadElements ( $ cloneQuery ) ; return $ cloneQuery -> compile ( ) ; }
Attempts to compile the current query including all Patterns and Filters Excludes Transformations
21,616
protected function getCurrentBindings ( ) { $ cloneQuery = clone $ this -> query ; $ cloneQuery = $ this -> loadElements ( $ cloneQuery ) ; if ( ! empty ( $ this -> set ) ) { $ cloneQuery -> setUpdates ( $ this -> set ) ; } if ( ! empty ( $ this -> insert_records ) ) { foreach ( $ this -> insert_records as $ record ) { $ cloneQuery -> addInsertRecord ( $ record ) ; } } return $ cloneQuery -> getBindings ( ) ; }
Attempts to compile the current query and returns the resulting bindings
21,617
protected function whitelistTable ( $ table ) { if ( is_array ( $ table ) ) { foreach ( $ table as $ t ) { $ this -> query -> addToTableWhitelist ( $ t ) ; } } else { $ this -> query -> addToTableWhitelist ( $ table ) ; } }
Add either a table or an array of tables to the current whitelist
21,618
protected function whitelistColumn ( $ column ) { if ( is_array ( $ column ) ) { foreach ( $ column as $ c ) { $ this -> query -> addToColumnWhitelist ( $ c ) ; } } else { $ this -> query -> addToColumnWhitelist ( $ column ) ; } }
Add either a column or an array of columns to the current whitelist
21,619
protected function reset ( ) { $ this -> activePattern = false ; $ this -> activeFilters = [ ] ; $ this -> activeTransformations = [ ] ; $ this -> insert_records = [ ] ; $ this -> set = [ ] ; $ queryclass = get_class ( $ this -> query ) ; $ this -> query = new $ queryclass ( ) ; }
Reset the query and source ; prep for another pass
21,620
final public function current ( ) { if ( ! $ this -> valid ( ) ) { return null ; } if ( $ this -> _lastPositionExecuted !== $ this -> _position ) { $ this -> runToNextYieldStatement ( ) ; } return $ this -> valid ( ) ? $ this -> getLastYieldedValue ( ) : null ; }
Get the yielded value .
21,621
final public function send ( $ value ) { $ this -> _lastValueSentIn = $ value ; $ this -> _sendInvokedAtLeastOnce = true ; if ( $ this -> _positionsExecutedCount > 0 ) { $ this -> _position ++ ; } return $ this -> current ( ) ; }
Send a value to the generator .
21,622
public function recordEnquiry ( string $ email , string $ name , string $ subject , string $ message , callable $ sendMailToAdminCallback ) : ContactEnquiry { $ enquiry = new ContactEnquiry ( $ this -> clock , new EmailAddress ( $ email ) , $ name , $ subject , $ message ) ; $ this -> repository -> save ( $ enquiry ) ; $ sendMailToAdminCallback ( $ enquiry ) ; return $ enquiry ; }
Records a contact enquiry .
21,623
protected function redirectHere ( $ action , $ parameters = [ ] ) { $ controller = get_class ( $ this ) ; return Redirect :: action ( $ controller . '@' . $ action , $ parameters ) ; }
Redirect to an action in the current controller .
21,624
protected function redirectBackWithSession ( ) { if ( $ redirect = Session :: get ( 'redirect' ) ) { Session :: forget ( 'redirect' ) ; return Redirect :: to ( $ redirect ) ; } return Redirect :: back ( ) ; }
Redirect back or to a saved URL if any .
21,625
public function group ( $ data , $ callback = null ) { if ( is_callable ( $ data ) ) { $ callback = $ data ; $ data = null ; } if ( $ data ) { $ this -> prefix [ ] = $ data ; } call_user_func ( $ callback , $ this ) ; if ( $ data ) { array_pop ( $ this -> prefix ) ; } }
Create group of routes
21,626
public function dispatch ( Request $ request ) { $ pathInfo = $ request -> getPathInfo ( ) ; $ method = $ request -> getMethod ( ) ; $ route = $ this -> collection -> find ( $ method , $ pathInfo ) ; if ( ! $ route ) { throw new \ Exception ( 'Route not found !' ) ; } return $ this -> dispatcher -> dispatch ( $ route ) ; }
For a specific method and uri dispatch the route .
21,627
private function methodNeedsDocBlock ( File $ sniffedFile , $ index ) { $ methodName = $ sniffedFile -> getDeclarationName ( $ index ) ; return ! in_array ( $ methodName , $ this -> methodNamesWithoutNecessaryDocBlock , true ) ; }
Checks if the method declaration is in need of a docblock .
21,628
private function isInWhitelist ( $ serviceName ) { foreach ( $ this -> whiteList as $ pattern ) { if ( ! preg_match ( $ pattern , $ serviceName ) ) { return false ; } } return true ; }
Returns true if one of the patterns is match
21,629
public static function byExtension ( $ extension , $ quality = 1.0 ) { $ extension = trim ( $ extension , '. ' ) ; if ( ! array_key_exists ( $ extension , self :: $ extensionMap ) ) { return false ; } else { return new Mime ( self :: $ extensionMap [ $ extension ] , $ quality ) ; } }
Find a Mime type by its extension
21,630
public static function byContentType ( $ contentType , $ quality = 1.0 ) { if ( ! array_key_exists ( $ contentType , self :: $ contentTypeMap ) ) { return false ; } else { return new Mime ( self :: $ contentTypeMap [ $ contentType ] , $ quality ) ; } }
Find a Mime type by a contentType
21,631
public function getExtensions ( ) { $ exts = array ( ) ; foreach ( self :: $ extensionMap as $ ext => $ type ) { if ( $ type == $ this -> type ) { $ exts [ ] = $ ext ; } } return $ exts ; }
Get possible extensions for this type
21,632
public function getContentType ( ) { foreach ( self :: $ contentTypeMap as $ ct => $ type ) { if ( $ type == $ this -> type ) { return $ ct ; } } return false ; }
Get the default content - type string for this Mime type
21,633
public function get ( $ name ) { if ( ! $ this -> has ( $ name ) ) { throw new Exception \ HelperNotFoundException ( "Helper '$name' not found" ) ; } if ( ! isset ( $ this -> helpers [ $ name ] ) ) { $ factory = $ this -> factories [ $ name ] ; $ this -> helpers [ $ name ] = $ factory ( ) ; } return $ this -> helpers [ $ name ] ; }
gets a helper
21,634
public function getIpV6 ( ) : ? string { if ( ! $ this -> hasIpV6 ( ) ) { $ this -> setIpV6 ( $ this -> getDefaultIpV6 ( ) ) ; } return $ this -> ipV6 ; }
Get ip v6
21,635
public function authorize ( $ user , CakeRequest $ request ) { if ( empty ( $ user [ 'id' ] ) ) { return false ; } if ( array_key_exists ( 'is_admin' , $ user ) && $ user [ 'is_admin' ] ) { return true ; } if ( $ request -> params [ 'plugin' ] == 'mt_sites' && $ request -> params [ 'controller' ] == 'sites' && $ request -> params [ 'action' ] == 'install' ) { return true ; } if ( $ request -> params [ 'plugin' ] == 'install' && $ request -> params [ 'controller' ] == 'configurations' && $ request -> params [ 'action' ] == 'first_configuration_wizard' ) { return true ; } if ( ! array_key_exists ( 'tenant' , $ request -> params ) && empty ( $ request -> params [ 'tenant' ] ) ) { if ( $ request -> params [ 'action' ] == 'display' ) { return true ; } } if ( ! array_key_exists ( 'Site' , $ user ) ) { return false ; } $ siteAlias = Hash :: extract ( $ user [ 'Site' ] , '{n}.alias' ) ; if ( array_key_exists ( 'tenant' , $ request -> params ) && in_array ( $ request -> params [ 'tenant' ] , $ siteAlias ) ) { return true ; } if ( ( strtolower ( $ request -> params [ 'controller' ] ) == "users" && strtolower ( $ request -> params [ 'action' ] ) == 'my_edit' ) or ( strtolower ( $ request -> params [ 'controller' ] ) == "users" && strtolower ( $ request -> params [ 'action' ] ) == 'change_password' ) ) { return true ; } return false ; }
Checks user authorization using a controller callback .
21,636
public function id ( $ prefix = '' ) { $ id = ++ self :: $ id ; if ( $ prefix ) { $ id = $ prefix . $ id ; } return $ id ; }
Generate and return a unique id .
21,637
public function readableSize ( $ size , $ decimals = 0 , $ binarySuffix = false ) { $ formatter = new FilesizeFormatter ( ) ; return $ formatter -> formatFilesize ( $ size , $ decimals , $ binarySuffix ) ; }
Return readable file size for given value .
21,638
public function age ( $ date1 , $ date2 = null ) { $ formatter = new AgeFormatter ( ) ; return $ formatter -> formatDate ( $ date1 , $ date2 ) ; }
Return age string for given date .
21,639
public function index ( ) { $ menus = $ this -> Filter -> filter ( $ this -> Menus -> find ( 'all' ) ) -> hydrate ( false ) ; $ this -> set ( 'menus' , $ menus ) ; }
index action GET
21,640
public function deleteItem ( $ id ) { $ this -> request -> allowMethod ( 'post' ) ; $ menuItem = $ this -> MenuItems -> get ( $ id ) ; if ( $ this -> MenuItems -> delete ( $ menuItem ) ) { $ this -> Flash -> success ( __d ( 'wasabi_core' , 'The menu item <strong>{0}</strong> has been deleted.' , $ menuItem -> get ( 'name' ) ) ) ; } else { $ this -> Flash -> error ( $ this -> dbErrorMessage ) ; } $ this -> redirect ( [ 'action' => 'edit' , $ menuItem -> get ( 'menu_id' ) ] ) ; return ; }
Delete a menu item . POST
21,641
public function reorderItems ( ) { if ( ! $ this -> request -> isAll ( [ 'ajax' , 'post' ] ) ) { throw new MethodNotAllowedException ( ) ; } if ( empty ( $ this -> request -> data ) ) { throw new BadRequestException ( ) ; } $ this -> request -> data = Hash :: map ( $ this -> request -> data , '{n}' , function ( $ item ) { if ( $ item [ 'parent_id' ] === 'null' ) { $ item [ 'parent_id' ] = null ; } return $ item ; } ) ; $ menuItems = $ this -> MenuItems -> patchEntities ( $ this -> MenuItems -> find ( 'threaded' ) , $ this -> request -> data ) ; $ this -> MenuItems -> connection ( ) -> begin ( ) ; foreach ( $ menuItems as $ menuItem ) { $ this -> MenuItems -> behaviors ( ) -> unload ( 'Tree' ) ; if ( ! $ this -> MenuItems -> save ( $ menuItem ) ) { $ this -> MenuItems -> connection ( ) -> rollback ( ) ; break ; } } if ( $ this -> MenuItems -> connection ( ) -> inTransaction ( ) ) { $ this -> MenuItems -> connection ( ) -> commit ( ) ; $ status = 'success' ; $ flashMessage = __d ( 'wasabi_core' , 'The menu item positions have been updated.' ) ; } else { $ status = 'error' ; $ flashMessage = $ this -> dbErrorMessage ; } $ this -> set ( [ 'status' => $ status , 'flashMessage' => $ flashMessage , '_serialize' => [ 'status' , 'flashMessage' ] ] ) ; }
reorderItems action AJAX POST
21,642
private function getPath ( ) { if ( strpos ( $ this -> i18nMessagePath , '/' ) === 0 || strpos ( $ this -> i18nMessagePath , ':/' ) === 1 ) { return $ this -> i18nMessagePath ; } return ROOT_PATH . $ this -> i18nMessagePath ; }
This function return the real path set in parameter .
21,643
private function getMessageFile ( $ language ) { if ( ! isset ( $ this -> messageFile [ $ language ] ) ) { $ this -> messageFile [ $ language ] = new MessageFileLanguage ( $ this -> getPath ( ) , $ language ) ; } return $ this -> messageFile [ $ language ] ; }
Return the instance of the MessageFileLanguage Each MessageFileLanguage is link to one language
21,644
public function getTranslationsForLanguage ( $ language ) { if ( ! isset ( $ this -> messages [ $ language ] ) ) { $ messageLanguage = $ this -> getMessageFile ( $ language ) ; $ this -> messages [ $ language ] = $ messageLanguage -> getAllMessages ( ) ; } return $ this -> messages [ $ language ] ; }
Return a list of all message for a language .
21,645
public function getTranslationsForKey ( $ key ) { $ this -> getAllTranslationByLanguage ( ) ; $ translations = [ ] ; foreach ( $ this -> messages as $ language => $ messages ) { foreach ( $ messages as $ messageKey => $ message ) { if ( $ key == $ messageKey ) { $ translations [ $ language ] = $ message ; } } } return $ translations ; }
Return a list of all message for a key by language .
21,646
public function deleteTranslation ( $ key , $ language = null ) { if ( $ language === null ) { $ languages = $ this -> getLanguageList ( ) ; } else { $ languages = array ( $ language ) ; } foreach ( $ languages as $ language ) { $ messageFile = $ this -> getMessageFile ( $ language ) ; $ messageFile -> deleteMessage ( $ key ) ; $ messageFile -> save ( ) ; unset ( $ this -> messages [ $ language ] [ $ key ] ) ; } }
Delete a translation for a language . If the language is not set or null this function deletes the translation for all language .
21,647
public function setTranslation ( $ key , $ value , $ language ) { $ messageFile = $ this -> getMessageFile ( $ language ) ; $ messageFile -> setMessage ( $ key , $ value ) ; $ messageFile -> save ( ) ; $ this -> messages [ $ language ] [ $ key ] = $ value ; }
Add or change a translation
21,648
public function getLanguageList ( ) { $ files = glob ( $ this -> getPath ( ) . 'messages_*.php' ) ; $ startAt = strlen ( 'messages_' ) ; $ languages = array ( ) ; foreach ( $ files as $ file ) { $ base = basename ( $ file ) ; $ languages [ ] = substr ( $ base , $ startAt , strrpos ( $ base , '.php' ) - $ startAt ) ; } return $ languages ; }
Liste of all language supported
21,649
public static function difference ( $ time , $ now = NULL , $ opt = array ( ) ) { if ( date ( 'Y-m-d H:i:s' , $ time ) == "0000-00-00 00:00:00" || empty ( $ time ) ) { return t ( 'Never' ) ; } $ defOptions = array ( 'to' => $ now , 'parts' => 1 , 'precision' => 'sec' , 'distance' => true , 'separator' => ', ' ) ; $ opt = array_merge ( $ defOptions , $ opt ) ; if ( ! $ opt [ 'to' ] ) $ opt [ 'to' ] = time ( ) ; $ str = '' ; $ diff = ( $ opt [ 'to' ] > $ time ) ? $ opt [ 'to' ] - $ time : $ time - $ opt [ 'to' ] ; $ periods = array ( 'decade' => 315569260 , 'year' => 31556926 , 'month' => 2629744 , 'week' => 604800 , 'day' => 86400 , 'hour' => 3600 , 'min' => 60 , 'sec' => 1 ) ; if ( $ opt [ 'precision' ] != 'sec' ) { $ diff = round ( ( $ diff / $ periods [ $ opt [ 'precision' ] ] ) ) * $ periods [ $ opt [ 'precision' ] ] ; } ( 0 == $ diff ) && ( $ str = 'less than 1 ' . $ opt [ 'precision' ] ) ; foreach ( $ periods as $ label => $ value ) { ( ( $ x = floor ( $ diff / $ value ) ) && $ opt [ 'parts' ] -- ) && $ str .= ( $ str ? $ opt [ 'separator' ] : '' ) . ( $ x . ' ' . $ label . ( $ x > 1 ? 's' : '' ) ) ; if ( $ opt [ 'parts' ] == 0 || $ label == $ opt [ 'precision' ] ) { break ; } $ diff -= $ x * $ value ; } $ opt [ 'distance' ] && $ str .= ( $ str && $ opt [ 'to' ] > $ time ) ? ' ago' : ' ago' ; return $ str ; }
Get time difference between 2 times
21,650
protected static function normalizeQuery ( ? string $ query ) : ? string { if ( null === $ query ) { return null ; } if ( '' === $ query ) { return '' ; } $ parts = [ ] ; $ order = [ ] ; foreach ( explode ( '&' , $ query ) as $ param ) { if ( '' === $ param || '=' === $ param [ 0 ] ) { continue ; } $ parts [ ] = $ param ; $ kvp = explode ( '=' , $ param , 2 ) ; $ order [ ] = $ kvp [ 0 ] ; } array_multisort ( $ order , SORT_ASC , $ parts ) ; return parent :: normalizeQuery ( implode ( '&' , $ parts ) ) ; }
Normalizes the query
21,651
public function mappingController ( $ uriapp = NULL , $ method = NULL ) { $ controllers = $ this -> app -> context -> getControllersDefinition ( ) ; $ maps = FALSE ; foreach ( $ controllers as $ url => $ controller_esp ) { $ controller_esp [ 'url' ] = strpos ( $ url , '@' ) ? substr ( $ url , 0 , strpos ( $ url , '@' ) ) : $ url ; $ mapController = $ this -> mapsController ( $ controller_esp , $ uriapp , $ method ) ; if ( $ mapController == NULL && isset ( $ controller_esp [ 'routes' ] ) ) { foreach ( $ controller_esp [ 'routes' ] as $ url => $ controller_esp_2 ) { $ controller_esp_2 [ 'url' ] = strpos ( $ url , '@' ) ? substr ( $ url , 0 , strpos ( $ url , '@' ) ) : $ url ; $ mapController = $ this -> mapsController ( $ controller_esp_2 , $ uriapp , $ method , $ controller_esp ) ; if ( $ mapController != NULL ) { break ; } } } if ( $ mapController != NULL ) { return $ mapController ; } } if ( ! $ maps ) { Error :: error_404 ( ) ; } }
Retorna la especificacion del controlador que mapea con la URI actual Levanta error 404 si ningun controlador mapea
21,652
private function mapsController ( $ controller , $ uriapp = NULL , $ method = NULL , $ parentController = NULL ) { $ httpMethod = isset ( $ controller [ 'httpMethod' ] ) ? $ controller [ 'httpMethod' ] : '*' ; if ( $ parentController != NULL ) { $ controller [ 'url' ] = rtrim ( $ parentController [ 'url' ] , '/' ) . '/' . ltrim ( $ controller [ 'url' ] , '/' ) ; } $ maps = UrlUri :: mapsActualUrl ( $ controller [ 'url' ] , $ uriapp ) && UrlUri :: mapsActualMethod ( $ httpMethod , $ method ) ; if ( $ maps ) { $ mapController = array ( 'url' => $ controller [ 'url' ] , 'httpMethod' => $ httpMethod , 'location' => isset ( $ controller [ 'location' ] ) ? $ controller [ 'location' ] : NULL , 'namespace' => isset ( $ controller [ 'namespace' ] ) ? $ controller [ 'namespace' ] : NULL , 'class' => isset ( $ controller [ 'class' ] ) ? $ controller [ 'class' ] : $ parentController [ 'class' ] , 'method' => isset ( $ controller [ 'method' ] ) ? $ controller [ 'method' ] : NULL , 'properties' => isset ( $ controller [ 'properties' ] ) ? $ controller [ 'properties' ] : array ( ) , 'middlewares' => isset ( $ controller [ 'middlewares' ] ) ? $ controller [ 'middlewares' ] : [ ] ) ; if ( $ parentController != NULL ) { if ( ! isset ( $ controller [ 'class' ] ) ) { $ mapController [ 'location' ] = isset ( $ parentController [ 'location' ] ) ? $ parentController [ 'location' ] : NULL ; $ mapController [ 'namespace' ] = isset ( $ parentController [ 'namespace' ] ) ? $ parentController [ 'namespace' ] : NULL ; } if ( isset ( $ parentController [ 'properties' ] ) ) { $ mapController [ 'properties' ] = array_merge ( $ parentController [ 'properties' ] , $ mapController [ 'properties' ] ) ; } if ( isset ( $ parentController [ 'middlewares' ] ) ) { $ mapController [ 'middlewares' ] = array_merge ( $ parentController [ 'middlewares' ] , $ mapController [ 'middlewares' ] ) ; } } return $ mapController ; } else { return NULL ; } }
Controla si el controlador pasado mapea con la url y el metodo actual . En caso de mapear arma la especificacion del controlador .
21,653
public function executeHttpRequest ( $ actualController = NULL , $ uriapp = NULL , $ filter = TRUE ) { if ( $ actualController == NULL ) { $ actualController = $ this -> mappingController ( $ uriapp ) ; } $ rtaFilters = true ; if ( $ filter ) { $ rtaFilters = $ this -> executeFilters ( $ this -> app -> context -> getFiltersBeforeDefinition ( ) ) ; } if ( $ rtaFilters !== false ) { $ this -> executeController ( $ actualController , $ uriapp ) ; if ( $ filter ) { $ this -> executeFilters ( $ this -> app -> context -> getFiltersAfterDefinition ( ) ) ; } } }
Ejecuta la especificacion de controlador pasada como parametro en base a una URI ejecutando o no filtros . En caso de que no se le pase el controlador lo consigue en base a la URI y en caso de que no se pase la URI especifica se usa la de la peticion actual .
21,654
protected function executeFilters ( $ filters , $ uriapp = NULL ) { foreach ( $ filters as $ filter_esp ) { $ filter = UrlUri :: mapsActualUrl ( $ filter_esp [ 'filtered' ] , $ uriapp ) ; if ( $ filter ) { $ dir = $ this -> buildDir ( $ filter_esp , 'filters' ) ; $ class = $ this -> buildClass ( $ filter_esp ) ; if ( ! class_exists ( $ class ) ) { if ( file_exists ( $ dir ) ) { require_once $ dir ; } else { Error :: general_error ( 'Filter Error' , 'The filter ' . $ filter_esp [ 'class' ] . ' dont exists' ) ; } } $ filterIns = new $ class ( ) ; if ( isset ( $ filter_esp [ 'properties' ] ) ) { $ this -> app -> dependenciesEngine -> injectProperties ( $ filterIns , $ filter_esp [ 'properties' ] ) ; } if ( method_exists ( $ filterIns , 'filter' ) ) { $ rta = $ filterIns -> filter ( $ this -> httpRequest , $ this -> httpResponse ) ; if ( $ rta === false ) { return false ; } } else { Error :: general_error ( 'Filter Error' , 'The filter ' . $ filter_esp [ 'class' ] . ' dont implement the method filter()' ) ; } } } }
Analiza los filtros que mapean con la URI pasada y ejecuta los que correspondan . En caso de no pasar URI se utiliza la de la peticion actual .
21,655
protected function executeMiddlewares ( $ middlewares ) { $ middlewaresDefinition = $ this -> app -> context -> getMiddlewaresDefinition ( ) ; foreach ( $ middlewares as $ middlewareName ) { if ( ! isset ( $ middlewaresDefinition [ $ middlewareName ] ) ) { Error :: general_error ( 'Middleware Error' , 'The middleware ' . $ middlewareName . ' dont exists' ) ; } $ middleware = $ middlewaresDefinition [ $ middlewareName ] ; $ dir = $ this -> buildDir ( $ middleware , 'middlewares' ) ; $ class = $ this -> buildClass ( $ middleware ) ; if ( ! class_exists ( $ class ) ) { if ( file_exists ( $ dir ) ) { require_once $ dir ; } else { Error :: general_error ( 'Middleware Error' , 'The middleware ' . $ middleware [ 'class' ] . ' dont exists' ) ; } } $ middlewareIns = new $ class ( ) ; if ( isset ( $ middleware [ 'properties' ] ) ) { $ this -> app -> dependenciesEngine -> injectProperties ( $ middlewareIns , $ middleware [ 'properties' ] ) ; } if ( method_exists ( $ middlewareIns , 'handle' ) ) { $ rta = $ middlewareIns -> handle ( $ this -> httpRequest , $ this -> httpResponse ) ; if ( $ rta === false ) { return false ; } } else { Error :: general_error ( 'Middleware Error' , 'The middleware ' . $ middleware [ 'class' ] . ' dont implement the method handle()' ) ; } } }
Se ejecutan los middlewares que se pasan como parametro
21,656
protected function executeController ( $ controller_esp , $ uriapp = NULL ) { if ( count ( $ controller_esp [ 'middlewares' ] ) > 0 ) { if ( $ this -> executeMiddlewares ( $ controller_esp [ 'middlewares' ] ) === false ) { return ; } } $ dir = $ this -> buildDir ( $ controller_esp ) ; $ class = $ this -> buildClass ( $ controller_esp ) ; if ( ! class_exists ( $ class ) ) { if ( file_exists ( $ dir ) ) { require_once $ dir ; } else { Error :: general_error ( 'Controller Error' , 'The controller ' . $ controller_esp [ 'class' ] . ' dont exists' ) ; } } $ controller = new $ class ( ) ; $ uri_params = UrlUri :: uriParams ( $ controller_esp [ 'url' ] , $ uriapp ) ; $ dinamic_method = $ uri_params [ 'dinamic' ] ; $ method = $ uri_params [ 'method' ] ; $ parameters = $ uri_params [ 'params' ] ? $ uri_params [ 'params' ] : array ( ) ; if ( isset ( $ controller_esp [ 'properties' ] ) ) { $ this -> app -> dependenciesEngine -> injectProperties ( $ controller , $ controller_esp [ 'properties' ] ) ; } $ methodHttp = filter_input ( INPUT_SERVER , 'REQUEST_METHOD' ) ; if ( $ dinamic_method ) { if ( $ method != 'index' && ! ( method_exists ( $ controller , $ methodHttp . '_' . $ method ) || method_exists ( $ controller , $ method ) ) ) { $ parameters = array_merge ( array ( '0' => $ method ) , $ parameters ) ; $ method = 'index' ; } if ( method_exists ( $ controller , $ methodHttp . '_' . $ method ) ) { $ method = $ methodHttp . '_' . $ method ; } } else if ( isset ( $ controller_esp [ 'method' ] ) ) { $ method = $ controller_esp [ 'method' ] ; } else { $ method = "do" . ucfirst ( strtolower ( $ methodHttp ) ) ; } $ controller -> setUriParams ( $ parameters ) ; if ( method_exists ( $ controller , $ method ) ) { $ controller -> $ method ( $ this -> httpRequest , $ this -> httpResponse ) ; } else { Error :: general_error ( 'HTTP Method Error' , "The HTTP method $method is not supported" ) ; } }
Ejecuta el controlador que mapeo anteriormente . Segun su definicion en la configuracion se ejecutara al estilo REST o mediante nombre de funciones
21,657
static public function get ( $ email = null , $ type ) { static $ cache ; if ( is_null ( $ email ) ) { $ email = Util :: getModuleId ( ) . "@" . Util :: getApplicationId ( ) ; } if ( is_null ( $ cache [ $ email ] ) ) { $ payload = [ "exp" => time ( ) + 3.154e+7 , "sub" => $ email ] ; $ cache [ $ email ] = \ Firebase \ JWT \ JWT :: encode ( $ payload , self :: getSecret ( $ type ) , self :: ALG ) ; } return $ cache [ $ email ] ; }
Returns a valid JWT token for this account
21,658
static public function getInternalToken ( ) { static $ token ; if ( is_null ( $ token ) ) { $ payload = [ "exp" => time ( ) + Moment :: ONEHOUR , "sub" => Util :: getModuleId ( ) . "@" . Util :: getApplicationId ( ) ] ; $ secret = self :: getSecret ( self :: CONF_INTERNAL_SECRET_NAME ) ; $ token = \ Firebase \ JWT \ JWT :: encode ( $ payload , $ secret , self :: ALG ) ; } return $ token ; }
Get Token used for service to service communication . Setting standard time to 5 seconds for internal service to service communication .
21,659
protected function _getFileName ( $ name ) { $ name = trim ( $ name ) ; $ name = iconv ( 'ISO-8859-1' , 'ASCII//TRANSLIT' , $ name ) ; $ name = preg_replace ( '/[^a-z0-9\-:]+/i' , '_' , $ name ) ; $ name = str_replace ( ':' , '.' , $ name ) ; if ( $ name == '' ) { throw new CacheException ( 'Cache-entry name cannot be empty' ) ; } return "{$name}.cache" ; }
Get a cache - entry filename based upon the string provided .
21,660
protected function _clearExpired ( $ time = null ) { if ( $ time === null ) $ time = time ( ) ; $ files = glob ( "{$this->_cache_path}*.cache" ) ; $ cleared = 0 ; if ( is_array ( $ files ) ) { foreach ( $ files as $ file ) { $ path = $ this -> _cache_path . basename ( $ file ) ; $ mtime = @ filemtime ( $ path ) ; if ( $ mtime !== false && $ time > $ mtime ) { @ unlink ( $ path ) ; ++ $ cleared ; } } } return $ cleared ; }
Clear expired cache - entries from the cache - path .
21,661
public function set ( $ name , $ value , $ ttl = 0 ) { if ( $ ttl <= 0 ) $ ttl = self :: TTL_FUTURE ; if ( is_resource ( $ value ) ) { throw new CacheException ( 'Cannot cache values of type "resource"' ) ; } if ( ! $ this -> validateValueSize ( $ value ) ) { ExceptionHandler :: notice ( "Value in $name is too big to be stored in file cache." ) ; } $ file = $ this -> _getFileName ( $ name ) ; $ fp = @ fopen ( $ this -> _cache_path . $ file , 'wb' ) ; if ( is_resource ( $ fp ) ) { $ result = @ fwrite ( $ fp , serialize ( $ value ) ) ; $ result = ( $ result && @ fclose ( $ fp ) ) ; $ result = ( $ result && @ touch ( $ this -> _cache_path . $ file , time ( ) + $ ttl ) ) ; if ( $ result && rand ( 1 , self :: CLEAR_INTERVAL ) == self :: CLEAR_INTERVAL ) { $ this -> _clearExpired ( ) ; } return $ result ; } else { return false ; } }
Add an entry to the FileCache .
21,662
public function get ( $ name , & $ error = false ) { if ( ! $ this -> _enabled ) { return null ; } try { $ file = $ this -> _getFileName ( $ name ) ; } catch ( CacheException $ e ) { $ error = true ; return null ; } if ( time ( ) > @ filemtime ( $ this -> _cache_path . $ file ) ) { return null ; } $ contents = @ file_get_contents ( $ this -> _cache_path . $ file ) ; if ( $ contents !== false ) { error_clear_last ( ) ; $ value = @ unserialize ( $ contents ) ; $ last_error = error_get_last ( ) ; if ( $ value === false && $ last_error !== null && $ last_error [ 'type' ] === E_WARNING ) { $ error = true ; return null ; } return $ value ; } return null ; }
Get an entry from the FileCache .
21,663
public function delete ( $ name ) { try { $ file = $ this -> _getFileName ( $ name ) ; } catch ( CacheException $ e ) { return false ; } return @ unlink ( $ this -> _cache_path . $ file ) ; }
Delete an entry from the FileCache .
21,664
protected function push ( callable $ newTopMiddleware ) { $ oldStack = $ this -> middlewareStack ; if ( $ oldStack === null ) { $ this -> middlewareStack = $ newTopMiddleware ; return $ this ; } $ this -> middlewareStack = function ( $ request , $ response , callable $ next ) use ( $ oldStack , $ newTopMiddleware ) { return $ newTopMiddleware ( $ request , $ response , function ( $ req , $ res ) use ( $ next , $ oldStack ) { return $ oldStack ( $ req , $ res , $ next ) ; } ) ; } ; return $ this ; }
Push a middleware onto the top of this stack .
21,665
public function listAction ( ) { $ groupManager = $ this -> get ( 'phlexible_user.group_manager' ) ; $ groups = [ ] ; foreach ( $ groupManager -> findAll ( ) as $ group ) { $ members = [ ] ; foreach ( $ group -> getUsers ( ) as $ user ) { $ members [ ] = $ user -> getDisplayName ( ) ; } sort ( $ members ) ; $ groups [ ] = [ 'gid' => $ group -> getId ( ) , 'name' => $ group -> getName ( ) , 'readonly' => false , 'memberCnt' => count ( $ members ) , 'members' => $ members , ] ; } return new JsonResponse ( $ groups ) ; }
List groups .
21,666
public function createAction ( Request $ request ) { $ name = $ request -> get ( 'name' ) ; $ groupManager = $ this -> get ( 'phlexible_user.group_manager' ) ; $ group = $ groupManager -> create ( ) -> setName ( $ name ) -> setCreateUserId ( $ this -> getUser ( ) -> getId ( ) ) -> setCreatedAt ( new \ DateTime ( ) ) -> setModifyUserId ( $ this -> getUser ( ) -> getId ( ) ) -> setModifiedAt ( new \ DateTime ( ) ) ; $ groupManager -> updateGroup ( $ group ) ; $ this -> get ( 'phlexible_message.message_poster' ) -> post ( UsersMessage :: create ( 'Group "' . $ group -> getName ( ) . '" created.' ) ) ; return new ResultResponse ( true , "Group $name created." ) ; }
Create new group .
21,667
public function renameAction ( Request $ request , $ groupId ) { $ name = $ request -> get ( 'name' ) ; $ groupManager = $ this -> get ( 'phlexible_user.group_manager' ) ; $ group = $ groupManager -> find ( $ groupId ) ; $ oldName = $ group -> getName ( ) ; $ group -> setName ( $ name ) -> setModifyUserId ( $ this -> getUser ( ) -> getId ( ) ) -> setModifiedAt ( new \ DateTime ( ) ) ; $ groupManager -> updateGroup ( $ group ) ; $ this -> get ( 'phlexible_message.message_poster' ) -> post ( UsersMessage :: create ( 'Group "' . $ group -> getName ( ) . '" updated.' ) ) ; return new ResultResponse ( true , "Group $oldName renamed to $name." ) ; }
Rename group .
21,668
public function deleteAction ( $ groupId ) { $ groupManager = $ this -> get ( 'phlexible_user.group_manager' ) ; $ group = $ groupManager -> find ( $ groupId ) ; $ name = $ group -> getName ( ) ; $ groupManager -> deleteGroup ( $ group ) ; $ this -> get ( 'phlexible_message.message_poster' ) -> post ( UsersMessage :: create ( 'Group "' . $ group -> getName ( ) . '" deleted.' ) ) ; return new ResultResponse ( true , "Group $name deleted." ) ; }
Delete group .
21,669
public function setField ( $ pField , $ pDistinct = false ) { Agl :: validateParams ( array ( 'String' => $ pField , 'Bool' => $ pDistinct ) ) ; $ this -> _field = array ( static :: FIELD_NAME => $ pField , static :: FIELD_DISTINCT => $ pDistinct ) ; return $ this ; }
Set the main field of the count query .
21,670
public function run ( RequestInterface $ request = null , ResponseInterface $ response = null ) { if ( is_null ( $ request ) ) { if ( ! $ this -> getContainer ( ) -> has ( 'request' ) ) { if ( $ this -> getContainer ( ) -> has ( 'Psr\Http\Message\ServerRequestInterface' ) ) { $ this -> getContainer ( ) -> add ( 'request' , 'Psr\Http\Message\ServerRequestInterface' ) ; } else if ( $ this -> getContainer ( ) -> has ( 'Psr\Http\Message\RequestInterface' ) ) { $ this -> getContainer ( ) -> add ( 'request' , 'Psr\Http\Message\RequestInterface' ) ; } } $ request = $ this -> getContainer ( ) -> get ( 'request' ) ; } if ( is_null ( $ response ) ) { if ( ! $ this -> getContainer ( ) -> has ( 'response' ) && $ this -> getContainer ( ) -> has ( 'Psr\Http\Message\ResponseInterface' ) ) { $ this -> getContainer ( ) -> add ( 'response' , 'Psr\Http\Message\ResponseInterface' ) ; } $ response = $ this -> getContainer ( ) -> get ( 'response' ) ; } $ this -> getContainer ( ) -> add ( 'request' , $ request ) ; $ this -> getContainer ( ) -> add ( 'response' , $ response ) ; $ this -> setErrorHandler ( ) ; $ this -> getKernel ( ) -> run ( $ request , $ response ) ; if ( $ this -> getLogger ( ) ) { if ( $ request instanceof ServerRequestInterface ) { $ this -> getLogger ( ) -> debug ( 'Script execution time: ' . number_format ( microtime ( true ) - $ request -> getServerParams ( ) [ 'REQUEST_TIME_FLOAT' ] , 3 ) . ' s' ) ; } $ this -> getLogger ( ) -> debug ( 'Memory usage: ' . number_format ( memory_get_usage ( ) / 1024 / 1024 , 3 ) . ' MB.' ) ; } }
Handles the request and delivers the response through the stack
21,671
public function getLogger ( ) { if ( is_null ( $ this -> logger ) ) { if ( $ this -> getContainer ( ) -> has ( 'logger' ) ) { return $ this -> getContainer ( ) -> get ( 'logger' ) ; } else if ( $ this -> getContainer ( ) -> has ( 'Psr\Log\LoggerInterface' ) ) { return $ this -> getContainer ( ) -> get ( 'Psr\Log\LoggerInterface' ) ; } else if ( class_exists ( 'Monolog\Logger' ) ) { $ this -> getContainer ( ) -> addServiceProvider ( new \ Laasti \ Log \ MonologProvider ) ; return $ this -> getContainer ( ) -> get ( 'logger' ) ; } } return $ this -> logger ; }
Returns application logger
21,672
public function getSynchronizedProperty ( \ JsonSerializable $ classInstance , array $ data ) { $ keys = array_keys ( $ classInstance -> jsonSerialize ( ) ) ; $ sync = array ( ) ; foreach ( $ keys as $ key ) { $ camelCaseKey = $ this -> toCamelCase ( $ key ) ; if ( array_key_exists ( $ key , $ data ) === false ) { throw new ValidationException ( sprintf ( 'Key "%s" does not exist in "%s"' , $ key , json_encode ( $ data ) ) ) ; } elseif ( property_exists ( $ classInstance , $ camelCaseKey ) === true ) { $ sync [ ] = $ camelCaseKey ; } } return $ sync ; }
Retrieve the synchorinized property with return data by jsonSerialize
21,673
public static function getParamFromLink ( $ url , $ paramName ) { if ( ! $ url ) { throw new \ InvalidArgumentException ( 'url' ) ; } if ( ! $ paramName ) { throw new \ InvalidArgumentException ( 'paramName' ) ; } $ parts = parse_url ( html_entity_decode ( $ url ) ) ; if ( isset ( $ parts ) ) { parse_str ( $ parts [ 'query' ] , $ query ) ; if ( array_key_exists ( $ paramName , $ query ) ) { return $ query [ $ paramName ] ; } } return null ; }
Get value of a passes param in a query .
21,674
public static function beginForm ( $ action = null , $ method = 'post' , $ name = null , $ options = [ ] ) { $ hiddenInputs = [ ] ; $ action = ( array ) $ action ; if ( ! isset ( $ url [ '@scheme' ] ) ) { $ action [ '@scheme' ] = Url :: ABS ; } $ action = Url :: modify ( $ action ) ; $ request = Instance :: ensure ( 'request' , '\rock\request\Request' , [ ] , false ) ; if ( $ request instanceof Request ) { if ( strcasecmp ( $ method , 'get' ) && strcasecmp ( $ method , 'post' ) ) { $ hiddenInputs [ ] = static :: hiddenInput ( isset ( $ name ) ? $ name . "[{$request->methodParam}]" : $ request -> methodParam , $ method , ArrayHelper :: getValue ( $ options , 'hiddenMethod' , [ ] ) ) ; $ method = 'post' ; } } $ csrf = static :: getCSRF ( ) ; if ( $ csrf instanceof CSRF && $ csrf -> enableCsrfValidation && ! strcasecmp ( $ method , 'post' ) ) { $ token = $ csrf -> get ( ) ; $ hiddenInputs [ ] = static :: hiddenInput ( isset ( $ name ) ? "{$name}[_csrf]" : '_csrf' , $ token , ArrayHelper :: getValue ( $ options , 'hiddenCsrf' , [ ] ) ) ; } if ( ! strcasecmp ( $ method , 'get' ) && ( $ pos = strpos ( $ action , '?' ) ) !== false ) { foreach ( explode ( '&' , substr ( $ action , $ pos + 1 ) ) as $ pair ) { if ( ( $ pos1 = strpos ( $ pair , '=' ) ) !== false ) { $ hiddenInputs [ ] = static :: hiddenInput ( urldecode ( substr ( $ pair , 0 , $ pos1 ) ) , urldecode ( substr ( $ pair , $ pos1 + 1 ) ) ) ; } else { $ hiddenInputs [ ] = static :: hiddenInput ( urldecode ( $ pair ) , '' ) ; } } $ action = substr ( $ action , 0 , $ pos ) ; } unset ( $ options [ 'hiddenMethod' ] , $ options [ 'hiddenCsrf' ] ) ; $ options [ 'action' ] = $ action ; $ options [ 'method' ] = $ method ; $ form = static :: beginTag ( 'form' , $ options ) ; if ( ! empty ( $ hiddenInputs ) ) { $ form .= "\n" . implode ( "\n" , $ hiddenInputs ) ; } return $ form ; }
Generates a form start tag .
21,675
public static function checkbox ( $ name , $ checked = false , $ options = [ ] ) { $ options [ 'checked' ] = ( boolean ) $ checked ; $ value = array_key_exists ( 'value' , $ options ) ? $ options [ 'value' ] : '1' ; if ( isset ( $ options [ 'uncheck' ] ) ) { $ hidden = static :: hiddenInput ( $ name , $ options [ 'uncheck' ] ) ; unset ( $ options [ 'uncheck' ] ) ; } else { $ hidden = '' ; } if ( isset ( $ options [ 'label' ] ) ) { $ label = $ options [ 'label' ] ; $ labelOptions = isset ( $ options [ 'labelOptions' ] ) ? $ options [ 'labelOptions' ] : [ ] ; unset ( $ options [ 'label' ] , $ options [ 'labelOptions' ] ) ; $ content = static :: label ( static :: input ( 'checkbox' , $ name , $ value , $ options ) . ' ' . $ label , null , $ labelOptions ) ; return $ hidden . $ content ; } else { return $ hidden . static :: input ( 'checkbox' , $ name , $ value , $ options ) ; } }
Generates a checkbox input .
21,676
public static function removeCssClass ( & $ options , $ class ) { if ( isset ( $ options [ 'class' ] ) ) { $ classes = array_unique ( preg_split ( '/\s+/' , $ options [ 'class' ] . ' ' . $ class , - 1 , PREG_SPLIT_NO_EMPTY ) ) ; if ( ( $ index = array_search ( $ class , $ classes ) ) !== false ) { unset ( $ classes [ $ index ] ) ; } if ( empty ( $ classes ) ) { unset ( $ options [ 'class' ] ) ; } else { $ options [ 'class' ] = implode ( ' ' , $ classes ) ; } } }
Removes a CSS class from the specified options .
21,677
public static function addCssStyle ( & $ options , $ style , $ overwrite = true ) { if ( ! empty ( $ options [ 'style' ] ) ) { $ oldStyle = static :: cssStyleToArray ( $ options [ 'style' ] ) ; $ newStyle = is_array ( $ style ) ? $ style : static :: cssStyleToArray ( $ style ) ; if ( ! $ overwrite ) { foreach ( $ newStyle as $ property => $ value ) { if ( isset ( $ oldStyle [ $ property ] ) ) { unset ( $ newStyle [ $ property ] ) ; } } } $ style = static :: cssStyleFromArray ( array_merge ( $ oldStyle , $ newStyle ) ) ; } $ options [ 'style' ] = $ style ; }
Adds the specified CSS style to the HTML options .
21,678
public static function removeCssStyle ( & $ options , $ properties ) { if ( ! empty ( $ options [ 'style' ] ) ) { $ style = static :: cssStyleToArray ( $ options [ 'style' ] ) ; foreach ( ( array ) $ properties as $ property ) { unset ( $ style [ $ property ] ) ; } $ options [ 'style' ] = static :: cssStyleFromArray ( $ style ) ; } }
Removes the specified CSS style from the HTML options .
21,679
public static function fromArray ( array $ data ) { $ result = '' ; foreach ( $ data as $ name => $ value ) { $ value = StringHelper :: toString ( $ value , "'" , Serialize :: SERIALIZE_JSON ) ; $ result .= "$name=$value; " ; } return $ result === '' ? null : rtrim ( $ result ) ; }
Converts a array into a string representation .
21,680
protected function boot ( ) { if ( $ this -> booted ) { return ; } $ this -> booted = true ; foreach ( $ this -> eventSubscribers as $ subscriber ) { $ this -> container [ 'eventDispatcher' ] -> addSubscriber ( $ subscriber ) ; } }
Boots the Application by calling boot on every provider added and then subscribe in order to add listeners .
21,681
public function run ( InputInterface $ input = null , OutputInterface $ output = null ) { $ this -> boot ( ) ; return $ this -> container [ 'console' ] -> run ( $ input , $ output ) ; }
Executes this application
21,682
public function service ( $ fonction , $ listArgument = array ( ) ) { try { return $ this -> client -> __soapCall ( $ fonction , $ listArgument ) ; } catch ( \ Exception $ e ) { throw new \ Exception ( 'Erreur lors de l\'appel de la méthode ' f onction du webservice : ' e - >g etMessage( ) ) ; return null ; } }
Permet d appeler une fonction du webservice
21,683
public function getChannel ( $ s_channelName ) { if ( ! array_key_exists ( $ s_channelName , $ this -> aI_channels ) ) { throw new \ UnexpectedValueException ( 'Channel ' . $ s_channelName . ' does not exist' ) ; } return $ this -> aI_channels [ $ s_channelName ] ; }
Gets a spcific channel
21,684
public function removeChannel ( $ s_channelName ) { if ( ! array_key_exists ( $ s_channelName , $ this -> aI_channels ) ) { throw new \ UnexpectedValueException ( 'Channel ' . $ s_channelName . ' does not exist. Cannot remove it' ) ; } unset ( $ this -> aI_channels [ $ s_channelName ] ) ; }
Removes a channel from list of registered ones
21,685
public function log ( $ s_message , $ s_level = 'notice' , array $ am_context = array ( ) ) { if ( ! $ this -> isValidSeverityLevel ( $ s_level ) ) { throw new \ OutOfRangeException ( 'Severity level ' . $ s_level . ' is invalid and can not be used' ) ; } foreach ( $ this -> aI_channels as $ s_channelName => $ I_channel ) { $ I_channel -> addRecord ( self :: $ as_monologLevels [ $ s_level ] , $ s_message , $ am_context ) ; } }
Logs with severity level to all registered channels
21,686
public function select ( Sql \ Query \ FQuery $ fQuery , $ useGlobalInstanceKeeper = false ) { $ statement = $ fQuery -> execute ( $ this -> config -> getPdo ( ) ) ; if ( $ useGlobalInstanceKeeper ) { $ instanceKeeper = $ this -> instancesKeeper ; } else { $ instanceKeeper = new InstancesKeeper ( ) ; } if ( ! $ statement -> rowCount ( ) ) { return new ResultSet ( $ fQuery -> getBaseFace ( ) , $ instanceKeeper ) ; } $ hydrator = new ArrayHydrator ( ) ; $ rs = $ hydrator -> hydrate ( $ fQuery , $ statement ) ; return $ rs ; }
Execute a select query parse the result and returns a resultSet
21,687
public function simpleInsert ( $ entity ) { $ simpleInsert = new SimpleInsert ( $ entity , $ this -> getConfig ( ) ) ; return $ this -> insert ( $ simpleInsert ) ; }
performs a SimpleInsert query for the given entity
21,688
public function simpleUpdate ( $ entity ) { $ simpleUpdate = new SimpleUpdate ( $ entity , $ this -> getConfig ( ) ) ; return $ this -> update ( $ simpleUpdate ) ; }
performs a SimpleUpdate query for the given entity
21,689
public function simpleDelete ( $ entity ) { $ simpleDelete = new SimpleDelete ( $ entity , $ this -> getConfig ( ) ) ; return $ this -> delete ( $ simpleDelete ) ; }
performs a SimpleDelete query for the given entity
21,690
public function getCommandLine ( ) { return is_array ( $ this -> commandline ) ? implode ( ' ' , array_map ( array ( $ this , 'escapeArgument' ) , $ this -> commandline ) ) : $ this -> commandline ; }
Gets the command line to be executed .
21,691
public function setOptions ( array $ options ) { @ trigger_error ( sprintf ( 'The %s() method is deprecated since version 3.3 and will be removed in 4.0.' , __METHOD__ ) , E_USER_DEPRECATED ) ; $ this -> options = $ options ; return $ this ; }
Sets the options for proc_open .
21,692
public function setEnhanceWindowsCompatibility ( $ enhance ) { @ trigger_error ( sprintf ( 'The %s() method is deprecated since version 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.' , __METHOD__ ) , E_USER_DEPRECATED ) ; $ this -> enhanceWindowsCompatibility = ( bool ) $ enhance ; return $ this ; }
Sets whether or not Windows compatibility is enabled .
21,693
public function setEnhanceSigchildCompatibility ( $ enhance ) { @ trigger_error ( sprintf ( 'The %s() method is deprecated since version 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.' , __METHOD__ ) , E_USER_DEPRECATED ) ; $ this -> enhanceSigchildCompatibility = ( bool ) $ enhance ; return $ this ; }
Activates sigchild compatibility mode .
21,694
public static function getHandlerByName ( $ name ) { return isset ( self :: $ namedRoutes [ $ name ] ) ? self :: $ namedRoutes [ $ name ] [ 1 ] : null ; }
Get handler by name
21,695
public static function getHandlerByPath ( $ path ) { $ result = null ; $ path = self :: prepareRoute ( '/' . trim ( $ path , " /" ) ) ; foreach ( static :: $ routes as $ key => $ handler ) { $ matches = [ ] ; if ( preg_match ( '#' . $ key . '$#i' , $ path , $ matches ) ) { foreach ( $ matches as $ key => $ val ) { if ( ! is_numeric ( $ key ) ) { $ _GET [ $ key ] = $ val ; } } $ result = $ handler [ 1 ] ; break ; } } return $ result ; }
Get handler by path
21,696
public static function parseRoute ( $ url ) { $ result = null ; $ parts = explode ( '/' , trim ( $ url , '/' ) ) ; if ( count ( $ parts ) === 1 ) { $ parts [ 0 ] = $ parts [ 0 ] === '' ? self :: DEFAULT_CONTROLLER : $ parts [ 0 ] ; $ parts [ 1 ] = self :: DEFAULT_ACTION ; } $ action = static :: preparePart ( array_pop ( $ parts ) , true ) ; $ parts [ count ( $ parts ) - 1 ] = static :: preparePart ( $ parts [ count ( $ parts ) - 1 ] ) . 'Controller' ; $ controller = '\\project\\controllers\\' . implode ( '\\' , $ parts ) ; if ( $ action != '' && $ controller != '' ) { $ result = $ controller . '::' . $ action ; } return $ result ; }
Parse url to callable
21,697
public static function preparePart ( $ part , $ firstLower = false ) { $ result = str_replace ( ' ' , '' , ucwords ( str_replace ( '-' , ' ' , $ part ) ) ) ; if ( $ firstLower && mb_strlen ( $ result ) > 0 ) { $ result [ 0 ] = mb_strtolower ( $ result [ 0 ] ) ; } return $ result ; }
Converts main - action to mainAction
21,698
private static function type ( string $ className , string $ constructor = self :: SAME_KEY , string $ key = null ) : DefinesTheType { return new Is ( $ className , $ constructor , [ ] , $ key ) ; }
Declare that the property is of the type .
21,699
private static function decoratedType ( string $ className , string $ constructor , array $ decorators , string $ key = null ) : DefinesTheType { return new Is ( $ className , $ constructor , $ decorators , $ key ) ; }
Declare that the property is of the decorated type .