idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
19,500
protected function loadArguments ( \ ReflectionFunctionAbstract $ ref , EventParamResolverInterface $ resolver ) { $ args = [ ] ; if ( $ ref -> getNumberOfParameters ( ) > 1 ) { foreach ( array_slice ( $ ref -> getParameters ( ) , 1 ) as $ param ) { $ args [ ] = $ resolver -> resolve ( $ param -> getClass ( ) , $ param -> isDefaultValueAvailable ( ) ? $ param -> getDefaultValue ( ) : false ) ; } } return $ args ; }
Populates arguments assembled from the event and the given target function .
19,501
public static function dropConnection ( $ name = null ) { if ( isset ( self :: $ connections [ $ name ] ) ) unset ( self :: $ connections [ $ name ] ) ; }
Drops the connection from the connection manager . Does not actually close it since there is no close method in PDO .
19,502
protected function merge ( $ target , $ source ) { if ( $ source === null ) { return $ target ; } return call_user_func ( $ this -> merge , $ target , $ source ) ; }
Merge two configs .
19,503
public function validInternalServerErrorJsonResponse ( $ exception , $ message = 'Error' ) { return response ( ) -> json ( [ 'exception' => class_basename ( $ exception ) , 'file' => basename ( $ exception -> getFile ( ) ) , 'line' => $ exception -> getLine ( ) , 'message' => $ exception -> getMessage ( ) , 'trace' => $ exception -> getTrace ( ) , ] , 500 , [ ] , JSON_PRETTY_PRINT ) ; }
Return a valid 500 Internal Server Error json response .
19,504
public function validSuccessJsonResponse ( $ message = 'Success' , $ data = [ ] , $ redirect = null ) { return response ( ) -> json ( [ 'code' => '200' , 'message' => $ message , 'data' => $ data , 'errors' => [ ] , 'redirect' => $ redirect , ] , 200 , [ ] , JSON_PRETTY_PRINT ) ; }
Return a valid 200 Success json response .
19,505
public function validUnprocessableEntityJsonResponse ( MessageBag $ errors , $ message = 'Unprocessable Entity' , $ redirect = null ) { return response ( ) -> json ( [ 'code' => '422' , 'message' => $ message , 'errors' => $ errors , 'redirect' => $ redirect , ] , 422 , [ ] , JSON_PRETTY_PRINT ) ; }
Return a valid 422 Unprocessable entity json response .
19,506
public static function getStatusesArray ( ) : array { return [ self :: STATUS_BLOCKED => Yii :: t ( 'setrun/user' , 'Blocked' ) , self :: STATUS_ACTIVE => Yii :: t ( 'setrun/user' , 'Active' ) , self :: STATUS_WAIT => Yii :: t ( 'setrun/user' , 'Wait' ) ] ; }
Get all statuses .
19,507
public static function create ( string $ username , string $ email , string $ password ) : User { $ user = new User ( ) ; $ user -> username = $ username ; $ user -> email = $ email ; $ user -> status = self :: STATUS_ACTIVE ; $ user -> setPassword ( $ password ) ; $ user -> generateAuthKey ( ) ; return $ user ; }
Creating a user .
19,508
public function edit ( string $ username , string $ email ) : void { $ this -> username = $ username ; $ this -> email = $ email ; }
Editing a user .
19,509
public static function requestSignup ( string $ username , string $ email , string $ password ) : User { $ user = new User ( ) ; $ user -> username = $ username ; $ user -> email = $ email ; $ user -> status = self :: STATUS_WAIT ; $ user -> generateEmailConfirmToken ( ) ; $ user -> generateAuthKey ( ) ; $ user -> setPassword ( $ password ) ; return $ user ; }
Request to sing up a new user .
19,510
public function confirmSignup ( ) : void { if ( ! $ this -> isWait ( ) ) { throw new \ DomainException ( Yii :: t ( 'setrun/user' , 'User is already active' ) ) ; } $ this -> status = self :: STATUS_ACTIVE ; $ this -> removeEmailConfirmToken ( ) ; }
Confirm user sing up .
19,511
public function requestPasswordReset ( ) : void { if ( ! empty ( $ this -> password_reset_token ) && self :: isPasswordResetTokenValid ( $ this -> password_reset_token ) ) { throw new \ DomainException ( Yii :: t ( 'setrun/user' , 'Password resetting is already requested' ) ) ; } $ this -> generatePasswordResetToken ( ) ; }
Request to reset the user s password .
19,512
public function resetPassword ( string $ password ) : void { if ( empty ( $ this -> password_reset_token ) ) { throw new \ DomainException ( Yii :: t ( 'setrun/user' , 'Password resetting is not requested' ) ) ; } $ this -> setPassword ( $ password ) ; $ this -> removePasswordResetToken ( ) ; }
Reset user password .
19,513
public static function findByPasswordResetToken ( string $ token ) : ? self { if ( ! static :: isPasswordResetTokenValid ( $ token ) ) { return null ; } return static :: findOne ( [ 'password_reset_token' => $ token , 'status' => self :: STATUS_ACTIVE , ] ) ; }
Finds user by password reset token .
19,514
public function setPassword ( string $ password ) : void { $ this -> password_hash = Yii :: $ app -> security -> generatePasswordHash ( $ password ) ; }
Generates password hash from password and sets it to the model .
19,515
protected function realJoin ( $ joinType , $ secondTable , $ onClause = '' , $ rawMode = false ) { $ alias = 0 ; list ( $ secondTable , $ alias ) = $ this -> fixJoinTable ( $ secondTable ) ; if ( $ rawMode || '' === $ onClause || $ this -> isRaw ( $ onClause , false ) ) { $ rawMode = true ; } else { $ onClause = $ this -> fixOnClause ( $ onClause ) ; } $ clause = & $ this -> getClause ( 'JOIN' ) ; $ clause [ ] = [ $ rawMode , $ joinType , $ secondTable , $ alias , $ onClause ] ; return $ this ; }
The real join
19,516
protected function fixJoinTable ( $ table ) { if ( is_array ( $ table ) ) { return $ table ; } elseif ( is_object ( $ table ) && $ table instanceof StatementInterface ) { return [ $ table , uniqid ( ) ] ; } else { return [ $ table , 0 ] ; } }
Fix join table
19,517
protected function fixOnClause ( $ onClause ) { if ( is_string ( $ onClause ) ) { return [ $ onClause , '=' , $ onClause ] ; } elseif ( is_array ( $ onClause ) && ! isset ( $ onClause [ 2 ] ) ) { return [ $ onClause [ 0 ] , '=' , $ onClause [ 1 ] ] ; } else { return $ onClause ; } }
Fix ON clause
19,518
protected function buildJoinTable ( array $ cls , array $ settings ) { $ table = $ cls [ 2 ] ; $ alias = $ cls [ 3 ] ; return $ this -> quoteItem ( $ table , $ settings ) . $ this -> quoteAlias ( $ alias , $ settings ) ; }
Build TABLE part
19,519
protected function buildJoinOn ( array $ cls , array $ settings ) { $ res = [ 'ON' ] ; $ on = $ cls [ 4 ] ; if ( is_string ( $ on ) ) { $ res [ ] = $ on ; } elseif ( is_object ( $ on ) ) { $ res [ ] = $ this -> quoteItem ( $ on , $ settings ) ; } else { $ res [ ] = $ this -> quote ( $ this -> getFirstTableAlias ( $ on [ 0 ] ) . $ on [ 0 ] , $ settings ) ; $ res [ ] = $ on [ 1 ] ; $ res [ ] = $ this -> quote ( $ this -> getSecondTableAlias ( $ cls , $ on [ 2 ] ) . $ on [ 2 ] , $ settings ) ; } return join ( ' ' , $ res ) ; }
Build ON part
19,520
protected function getFirstTableAlias ( $ left ) { if ( false !== strpos ( $ left , '.' ) ) { return '' ; } else { $ tables = & $ this -> getClause ( 'TABLE' ) ; reset ( $ tables ) ; $ alias = key ( $ tables ) ; return ( is_int ( $ alias ) ? $ tables [ $ alias ] [ 0 ] : $ alias ) . '.' ; } }
Get first table alias
19,521
protected function getSecondTableAlias ( array $ cls , $ right ) { if ( false !== strpos ( $ right , '.' ) ) { return '' ; } else { $ alias = $ cls [ 3 ] ; if ( ! is_string ( $ alias ) ) { $ alias = $ cls [ 2 ] ; } return $ alias . '.' ; } }
Get second table alias
19,522
public function addRoleForUser ( UserEntity $ user , $ role ) { $ roles = $ user -> getRoles ( ) ; if ( ! in_array ( $ role , $ roles ) ) { $ this -> userRolePivotMapper -> addRoleForUser ( $ user -> getId ( ) , $ role ) ; array_push ( $ roles , $ role ) ; $ user -> setRoles ( $ roles ) ; } }
Add a role to a given user
19,523
public function _format ( $ format , $ placeholders = [ ] , $ default = '' ) { $ placeholders = ( array ) $ placeholders ; $ matches = [ ] ; if ( ! preg_match_all ( '/\{([^{}]*)\}+/u' , $ format , $ matches ) ) return sprintf ( $ format , ... array_values ( $ placeholders ) ) ; ksort ( $ placeholders , SORT_NATURAL ) ; $ placeholders [ '__default__' ] = $ default ; $ positions = array_flip ( array_keys ( $ placeholders ) ) ; $ type_specifiers = '/([sducoxXbgGeEfF])$/u' ; $ replacements = [ ] ; foreach ( $ matches [ 1 ] as $ match ) { list ( $ name , $ options ) = array_pad ( explode ( ':' , $ match , 2 ) , 2 , '' ) ; if ( ! preg_match ( $ type_specifiers , $ options ) ) $ options .= 's' ; $ position = array_key_exists ( $ name , $ positions ) ? $ positions [ $ name ] + 1 : $ positions [ '__default__' ] + 1 ; $ pattern = '%' . $ position . '$' . $ options ; $ replacements [ '{' . $ match . '}' ] = $ pattern ; } $ format = str_replace ( array_keys ( $ replacements ) , array_values ( $ replacements ) , $ format ) ; return sprintf ( $ format , ... array_values ( $ placeholders ) ) ; }
Return a formatted string .
19,524
public function is ( $ value , $ wildcards = true , $ caseSensitive = true ) { if ( $ this -> str == $ value ) return true ; return $ this -> regexPatternForIs ( $ wildcards , $ caseSensitive ) -> matches ( $ value ) ; }
Determine if the string is a pattern matching the given value .
19,525
public function isAll ( $ values , $ wildcards = true , $ caseSensitive = true ) { $ regex = $ this -> regexPatternForIs ( $ wildcards , $ caseSensitive ) ; return count ( $ regex -> filter ( Helpers :: toArray ( $ values ) , true ) ) === 0 ; }
Determine if the string is a pattern matching all the given values .
19,526
public function matches ( $ pattern , $ caseSensitive = true ) { $ regex = $ this -> toRegex ( $ pattern , ( $ caseSensitive ? "" : Modifiers :: CASELESS ) ) ; return $ regex -> matches ( $ this ) ; }
Determine if the string matches the given regex pattern .
19,527
public function replace ( $ search , $ replacement , & $ count = 0 ) { return $ this -> getNew ( str_replace ( $ search , $ replacement , $ this -> str , $ count ) ) ; }
Replaces occurrences of search in string by replacement .
19,528
protected function regexPatternForStrip ( $ substring , $ limit ) { $ pattern = $ substring ? Regex :: quote ( $ substring ) : '\s' ; return '(?:' . '(?:' . $ pattern . ')' . ( $ limit > 0 ? '{1,' . $ limit . '}' : '+' ) . ')' ; }
Get the appropriate regex pattern for stripping a string
19,529
public function confirmEmailAction ( ) { $ code = $ this -> dispatcher -> getParam ( 'code' ) ; $ confirmation = EmailConfirmations :: findFirstByCode ( $ code ) ; if ( ! $ confirmation ) { return $ this -> dispatcher -> forward ( [ 'controller' => 'index' , 'action' => 'index' ] ) ; } if ( $ confirmation -> confirmed != 'N' ) { return $ this -> dispatcher -> forward ( [ 'controller' => 'session' , 'action' => 'login' ] ) ; } $ confirmation -> confirmed = 'Y' ; $ confirmation -> user -> active = 'Y' ; if ( ! $ confirmation -> save ( ) ) { foreach ( $ confirmation -> getMessages ( ) as $ message ) { $ this -> flash -> error ( $ message ) ; } return $ this -> dispatcher -> forward ( [ 'controller' => 'index' , 'action' => 'index' ] ) ; } $ this -> auth -> authUserById ( $ confirmation -> user -> id ) ; if ( $ confirmation -> user -> mustChangePassword == 'Y' ) { $ this -> flash -> success ( 'The email was successfully confirmed. Now you must change your password' ) ; return $ this -> dispatcher -> forward ( [ 'controller' => 'users' , 'action' => 'changePassword' ] ) ; } $ this -> flash -> success ( 'The email was successfully confirmed' ) ; return $ this -> dispatcher -> forward ( [ 'controller' => 'users' , 'action' => 'index' ] ) ; }
Confirms an e - mail if the user must change thier password then changes it
19,530
public function getContainersAction ( ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ containers = $ em -> getRepository ( 'InterneSeanceBundle:Container' ) -> findAll ( ) ; $ view = $ this -> view ( $ containers , Response :: HTTP_OK ) ; return $ this -> handleView ( $ view ) ; }
Gets the list of all Containers .
19,531
public static function discoverListeners ( $ object , $ listeners = null , $ pattern = self :: LISTENER_DISCOVERY_PATTERN ) { $ _listeners = $ listeners ? : static :: _discoverObjectListeners ( $ object , $ pattern ) ; if ( empty ( $ _listeners ) || ! is_array ( $ _listeners ) ) { return ; } foreach ( $ _listeners as $ _eventName => $ _callables ) { foreach ( $ _callables as $ _listener ) { static :: on ( $ _eventName , $ _listener ) ; } } }
Wires up any event handlers automatically
19,532
public static function _discoverObjectListeners ( $ object , $ pattern = self :: LISTENER_DISCOVERY_PATTERN , $ rediscover = false ) { static $ _discovered = array ( ) ; $ _listeners = array ( ) ; $ _objectId = spl_object_hash ( is_string ( $ object ) ? '_class.' . $ object : $ object ) ; if ( false === $ rediscover && isset ( $ _discovered [ $ _objectId ] ) ) { return true ; } try { $ _mirror = new \ ReflectionClass ( $ object ) ; $ _methods = $ _mirror -> getMethods ( \ ReflectionMethod :: IS_PUBLIC | \ ReflectionMethod :: IS_PROTECTED ) ; foreach ( $ _methods as $ _method ) { if ( 0 == preg_match ( $ pattern , $ _method -> name , $ _matches ) || empty ( $ _matches [ 1 ] ) ) { continue ; } $ _eventName = Inflector :: neutralize ( $ _matches [ 1 ] ) ; if ( ! isset ( $ _listeners [ $ _eventName ] ) ) { $ _listeners [ $ _eventName ] = array ( ) ; } $ _listeners [ $ _eventName ] [ ] = array ( $ object , $ _method -> name ) ; unset ( $ _matches , $ _method ) ; } unset ( $ _methods , $ _mirror ) ; $ _discovered [ $ _objectId ] = true ; } catch ( \ Exception $ _ex ) { return false ; } return $ _listeners ; }
Builds a hash of events and handlers that are present in this object based on the event handler signature . This merely builds the hash nothing is done with it .
19,533
public function render ( $ paths , $ navAttrs = array ( ) , $ listAttrs = array ( ) ) { if ( false !== $ navAttrs ) { $ navAttrs = array_merge ( array ( 'tag' => 'nav' ) , $ navAttrs ) ; $ navTag = $ navAttrs [ 'tag' ] ; unset ( $ navAttrs [ 'tag' ] ) ; } $ listAttrs = array_merge ( array ( 'tag' => 'ul' ) , $ listAttrs ) ; $ this -> _tag = $ listAttrs [ 'tag' ] ; unset ( $ listAttrs [ 'tag' ] ) ; if ( is_string ( $ paths ) ) { $ paths = array ( array ( 'path' => $ paths ) ) ; } $ out = '' ; foreach ( $ paths as $ k => $ path ) { if ( is_string ( $ path ) ) { $ paths [ $ k ] = compact ( 'path' ) ; } else if ( is_string ( $ k ) ) { $ attrs = ( array ) $ path ; $ path = $ k ; if ( ! array_key_exists ( 'navAttrs' , $ attrs ) && ! array_key_exists ( 'listAttrs' , $ attrs ) ) { $ attrs = array ( 'navAttrs' => $ attrs , 'listAttrs' => array ( ) ) ; } $ out .= $ this -> render ( $ path , $ attrs [ 'navAttrs' ] , $ attrs [ 'listAttrs' ] ) ; continue ; } $ paths [ $ k ] = Hash :: merge ( array ( 'attrs' => $ listAttrs ) , $ paths [ $ k ] ) ; $ out .= $ this -> _render ( $ paths [ $ k ] ) ; } if ( empty ( $ out ) ) { return ; } if ( false === $ navAttrs ) { return $ out ; } return $ this -> Html -> useTag ( 'tag' , $ navTag , $ navAttrs , $ out , $ navTag ) ; }
Render navigation .
19,534
public function load ( $ environment , $ namespace ) { $ file = $ this -> directory ; $ file .= ! empty ( $ environment ) ? $ environment . DS : DS ; $ file .= $ namespace ; $ file .= $ this -> extension ; if ( ! array_key_exists ( $ this -> extension , $ this -> handlers ) ) { throw new \ Exception ( "config file handler for {$this->extension} does not exists" ) ; } $ handler = $ this -> handlers [ $ this -> extension ] ; $ params = $ handler -> readParams ( $ file ) ; return $ params ; }
Loads config from a specific namespace
19,535
public function init ( ) { $ asset = Yii :: app ( ) -> assetManager -> publish ( YiiBase :: getPathOfAlias ( 'cii.assets.dist' ) , true , - 1 , YII_DEBUG ) ; Yii :: app ( ) -> clientScript -> registerScriptFile ( $ asset . ( YII_DEBUG ? '/ciimscomments.js' : '/ciimscomments.min.js' ) , CClientScript :: POS_END ) ; Yii :: app ( ) -> clientScript -> registerCssFile ( $ asset . ( YII_DEBUG ? '/ciimscomments.css' : '/ciimscomments.min.css' ) ) ; if ( $ this -> content != false ) $ this -> renderCommentBox ( ) ; else $ this -> renderCommentCount ( ) ; }
Init function to start the rendering process
19,536
private function renderCommentBox ( ) { $ link = CHtml :: link ( '0' , Yii :: app ( ) -> createAbsoluteUrl ( $ this -> content [ 'slug' ] ) . '#comment' , array ( 'data-ciimscomments-identifier' => $ this -> content [ 'id' ] ) ) ; $ id = $ this -> content [ 'id' ] ; Yii :: app ( ) -> clientScript -> registerScript ( 'CiiMSComments' , " $(document).ready(function() { // Load the Endpoint var endpoint = $('#endpoint').attr('data-attr-endpoint') + '/'; // Update the comments div $('.comment-count').attr('data-attr-id', '$id').addClass('registered').append('$link'); // Load the comments Comments.load(); Comments.commentCount(); }); " ) ; }
Renders the Disqus Comment Box on the page
19,537
public function handleForm ( Request $ request , Form $ form ) { $ data = $ request -> request -> all ( ) ; $ children = $ form -> all ( ) ; $ data = array_intersect_key ( $ data , $ children ) ; $ form -> submit ( $ data ) ; return $ form ; }
Se hace un submit de los campos de un request que esten definidos en un formulario
19,538
public function getFormErrors ( Form $ form , $ deep = false , $ flatten = true ) { $ errors = array ( ) ; foreach ( $ form -> getErrors ( $ deep , $ flatten ) as $ key => $ error ) { if ( $ form -> isRoot ( ) ) { $ errors [ 'form' ] [ ] = $ error -> getMessage ( ) ; } else { $ errors [ ] = $ error -> getMessage ( ) ; } } $ childs = $ form -> getIterator ( ) ; foreach ( $ childs as $ child ) { $ fieldErrors = $ child -> getErrors ( ) ; while ( $ fieldErrors -> current ( ) != null ) { $ errors [ $ child -> getName ( ) ] [ ] = $ fieldErrors -> current ( ) -> getMessage ( ) ; $ fieldErrors -> next ( ) ; } } return $ errors ; }
Dado un formulario se devuelven sus errores parseados
19,539
public function register ( ) { $ this -> registerMiddleware ( ) ; $ this -> app -> before ( $ this -> createBeforeFilter ( ) ) ; $ this -> app -> after ( $ this -> createAfterFilter ( ) ) ; }
Register all configured middleware classes with the appropriate App - level events .
19,540
protected function registerMiddleware ( ) { $ middleware = $ this -> app [ 'config' ] [ 'app.middleware' ] ; foreach ( $ middleware as $ class_name ) { $ filter = app ( $ class_name ) ; if ( $ filter instanceof BeforeInterface ) { array_push ( $ this -> before , $ filter ) ; } if ( $ filter instanceof AfterInterface ) { array_push ( $ this -> after , $ filter ) ; } } }
Create middleware instances from the array of class names in the app . middleware config key .
19,541
protected function createBeforeFilter ( ) { $ before = $ this -> before ; return function ( $ request ) use ( $ before ) { foreach ( $ before as $ filter ) { $ response = $ filter -> onBefore ( $ request ) ; if ( ! is_null ( $ response ) ) { return $ response ; } } return null ; } ; }
Generate a callback function that iterates over all BeforeInterface middleware .
19,542
protected function createAfterFilter ( ) { $ after = $ this -> after ; return function ( $ request , $ response ) use ( $ after ) { foreach ( $ after as $ filter ) { $ filter -> onAfter ( $ request , $ response ) ; } } ; }
Generate a callback function that iterates over all AfterInterface middleware .
19,543
public function getConfig ( $ key = null ) { if ( isLaravel5 ( ) ) { $ configNameSpace = 'vendor.' . $ this -> packageVendor . '.' . $ this -> packageName . '.' ; $ key = $ configNameSpace . ( $ key ? '.' . $ key : '' ) ; return $ this -> app [ 'config' ] -> get ( $ key ) ; } }
Get a configuration value
19,544
public function persistAndFlush ( $ entity , $ persistAll = false , $ entityManager = null ) { $ entityManager = $ this -> getEntityManager ( $ entityManager ) ; $ entityManager -> persist ( $ entity ) ; $ entityManager -> flush ( $ persistAll ? null : $ entity ) ; }
Persist and flush a given entity
19,545
public function deleteAndFlush ( $ entity , $ entityManager = null ) { $ entityManager = $ this -> getEntityManager ( $ entityManager ) ; $ entityManager -> remove ( $ entity ) ; $ entityManager -> flush ( $ entity ) ; }
Remove and flush a given entity
19,546
public static function isUnix ( ) : bool { if ( null !== static :: $ type ) { return static :: $ type === self :: TYPE_UNIX ; } return static :: getType ( ) === self :: TYPE_UNIX ; }
Checks whether PHP is running on a Unix platform
19,547
public static function isWindows ( ) : bool { if ( null !== static :: $ type ) { return static :: $ type === self :: TYPE_WINDOWS ; } return static :: getType ( ) === self :: TYPE_WINDOWS ; }
Checks whether PHP is running on a Windows platform
19,548
public static function isBsd ( ) : bool { if ( null !== static :: $ type ) { return static :: $ type === self :: TYPE_BSD ; } return static :: getType ( ) === self :: TYPE_BSD ; }
Checks whether PHP is running on a BSD platform
19,549
public static function isDarwin ( ) : bool { if ( null !== static :: $ type ) { return static :: $ type === self :: TYPE_DARWIN ; } return static :: getType ( ) === self :: TYPE_DARWIN ; }
Checks whether PHP is running on a Darwin platform
19,550
public static function isCygwin ( ) : bool { if ( null !== static :: $ type ) { return static :: $ type === self :: TYPE_CYGWIN ; } return static :: getType ( ) === self :: TYPE_CYGWIN ; }
Checks whether PHP is running on a Cygwin platform
19,551
public static function hasStty ( ) : bool { if ( static :: $ hasStty !== null ) { return static :: $ hasStty ; } if ( static :: isWindows ( ) ) { return static :: $ hasStty = false ; } exec ( '/usr/bin/env stty' , $ output , $ exitCode ) ; return static :: $ hasStty = $ exitCode === 0 ; }
Checks whether this platform has the stty binary .
19,552
public static function post ( $ route ) { $ content = self :: traitPost ( $ route ) ; self :: addRoute ( $ content ) ; return true ; }
function to generate Post Route .
19,553
public static function target ( $ route , $ controller , $ method ) { $ content = self :: traitTarget ( $ route , $ controller , $ method ) ; self :: addRoute ( $ content ) ; return true ; }
function to generate target Route .
19,554
protected static function traitPost ( $ route ) { $ content = '' ; $ content .= "\n\n" . self :: funcPost ( $ route ) . ' ' ; $ content .= '{' . "\n" ; $ content .= "\t" . '// TODO : ' . "\n" ; $ content .= '});' ; return $ content ; }
generate Post Route script .
19,555
protected static function addRoute ( $ content ) { $ Root = Process :: root ; $ RouterFile = $ Root . 'app/http/Routes.php' ; file_put_contents ( $ RouterFile , $ content , FILE_APPEND | LOCK_EX ) ; }
Add callable to the route file .
19,556
protected static function formatParams ( $ params ) { $ reslt = '' ; for ( $ i = 0 ; $ i < count ( $ params ) ; $ i ++ ) { $ reslt .= '$' . $ params [ $ i ] ; if ( $ i < count ( $ params ) - 1 ) { $ reslt .= ',' ; } } return $ reslt ; }
Concat the paramters .
19,557
protected static function dynamic ( $ route ) { $ parms = [ ] ; $ param = '' ; $ open = false ; for ( $ i = 0 ; $ i < Strings :: length ( $ route ) ; $ i ++ ) { if ( $ open && $ route [ $ i ] != '}' ) { $ param .= $ route [ $ i ] ; } if ( $ route [ $ i ] == '{' && ! $ open ) { $ open = true ; } elseif ( $ route [ $ i ] == '}' && $ open ) { $ open = ! true ; $ parms [ ] = $ param ; $ param = '' ; } } return $ parms ; }
Get the dynamic paramteres from route string .
19,558
protected function replaceRefs ( $ key , & $ scope ) { if ( is_array ( $ scope ) ) { foreach ( array_keys ( $ scope ) as $ subkey ) { $ this -> replaceRefs ( implode ( $ this -> delimiter , [ $ key , $ subkey ] ) , $ scope [ $ subkey ] ) ; } } else { $ this -> getByRef ( $ key , $ scope ) ; } }
Replaces references recursively .
19,559
protected function setScope ( & $ key , $ create = false ) { $ this -> scope = & $ this -> fullScope ; if ( false === strpos ( $ key , $ this -> delimiter ) ) { return ; } $ this -> key = $ key ; $ keys = explode ( $ this -> delimiter , $ key ) ; $ lastKey = array_pop ( $ keys ) ; $ lastIndex = sizeof ( $ keys ) - 1 ; foreach ( $ keys as $ index => $ key ) { if ( ! isset ( $ this -> scope [ $ key ] ) || ! is_array ( $ this -> scope [ $ key ] ) ) { if ( $ create ) { $ this -> scope [ $ key ] = [ ] ; } else if ( ! isset ( $ this -> scope [ $ key ] ) && $ index == $ lastIndex ) { return ; } } if ( $ this -> checkRefs && $ this -> isRef ( $ this -> scope [ $ key ] , false ) ) { $ key = $ this -> scope [ $ key ] ; $ this -> isRef ( $ key ) ; $ this -> setScope ( $ key , $ create ) ; } $ this -> scope = & $ this -> scope [ $ key ] ; } $ key = $ lastKey ; }
Shifts scope according to complex key .
19,560
public function getAttributeFromArray ( $ key , $ default = null ) { return isset ( $ this -> attributes [ $ key ] ) ? $ this -> attributes [ $ key ] : $ default ; }
Get an attribute from the array in model .
19,561
public function setAttributeToArray ( $ key , $ value ) { $ this -> changed [ $ key ] = true ; $ this -> attributes [ $ key ] = $ value ; return $ this ; }
Set an attribute to the array in model .
19,562
public function mergeRawAttributes ( array $ attributes , $ sync = false , $ force = false ) { foreach ( $ attributes as $ key => $ value ) { if ( $ force || ( ( ! $ force ) && ( ! $ this -> hasAttribute ( $ key ) ) ) ) { $ this -> setAttribute ( $ key , $ value ) ; } } if ( $ sync ) { $ this -> syncOriginal ( ) ; } return $ this ; }
Set the array of model attributes .
19,563
public function hasChanged ( $ attribute = false ) { $ changes = $ this -> getChanged ( ) ; if ( $ attribute !== false ) { $ attribute = ( array ) $ attribute ; foreach ( $ attribute as $ attr ) { if ( array_key_exists ( $ attr , $ changes ) ) { return true ; } } return false ; } return count ( $ changes ) > 0 ; }
Verifica e retorna se ha alguma alteracao para ser salva .
19,564
public function getBasecampAccounts ( AccessToken $ token ) { $ response = $ this -> fetchUserDetails ( $ token ) ; $ details = json_decode ( $ response ) ; return $ details -> accounts ; }
Get basecamp accounts
19,565
public static function compressFile ( $ filepathSrc , $ filepathDst = null , $ level = 9 ) { if ( ! isset ( $ filepathDst ) ) { $ filepathDst = $ filepathSrc . '.gz' ; } $ return = $ filepathDst ; $ mode = 'wb' . $ level ; if ( $ fpOut = gzopen ( $ filepathDst , $ mode ) ) { if ( $ fpIn = fopen ( $ filepathSrc , 'rb' ) ) { while ( ! feof ( $ fpIn ) ) { gzwrite ( $ fpOut , fread ( $ fpIn , 1024 * 512 ) ) ; } fclose ( $ fpIn ) ; } else { $ return = false ; } gzclose ( $ fpOut ) ; } else { $ return = false ; } return $ return ; }
Compress a file Removes original
19,566
public static function uncompressFile ( $ filepathSrc , $ filepathDst = null ) { if ( ! isset ( $ filepathDst ) ) { $ regex = '#^(.+).gz$#' ; $ filepathDst = preg_replace ( $ regex , '$1' , $ filepathSrc ) ; } elseif ( is_dir ( $ filepathDst ) ) { $ pathInfo = pathinfo ( $ filepathSrc ) ; $ filename = preg_replace ( $ filename , '$1' , $ pathInfo [ 'filename' ] ) ; $ filepathDst = $ pathInfo [ 'dirname' ] . '/' . $ filename ; } $ return = $ filepathDst ; if ( $ filepathDst == $ filepathSrc ) { $ return = false ; } elseif ( $ fpIn = gzopen ( $ filepathSrc , 'rb' ) ) { if ( $ fpOut = fopen ( $ filepathDst , 'wb' ) ) { while ( ! gzeof ( $ fpIn ) ) { fwrite ( $ fpOut , gzread ( $ fpIn , 1024 * 512 ) ) ; } } else { $ return = false ; } } else { $ return = false ; } return $ return ; }
Uncompress gziped file
19,567
public function processDomainGSheetObjects ( array $ inventories ) { $ dom = new DomDocument ( "1.0" , "UTF-8" ) ; $ products = $ dom -> createElement ( 'Products' ) ; foreach ( $ inventories as $ inventory ) { $ product = $ dom -> createElement ( 'Product' ) ; $ inventoryXmlElement = $ this -> buildInventoryElement ( $ dom , $ inventory ) ; $ product -> appendChild ( $ inventoryXmlElement ) ; $ products -> appendChild ( $ product ) ; } $ dom -> appendChild ( $ products ) ; return $ this -> outputFormattedXml ( $ dom ) ; }
Satisfies interface method . Invoked in XmlSquad \ Library \ Application \ Service \ GoogleDriveProcessService
19,568
public function actionCreate ( ) { $ model = new Categories ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { if ( Yii :: $ app -> request -> isAjax ) { header ( 'Content-type: application/json' ) ; echo Json :: encode ( [ 'status' => 'DONE' , 'model' => $ model ] ) ; exit ( ) ; } else { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Categories model . If creation is successful the browser will be redirected to the view page .
19,569
public function actionJsoncategories ( ) { header ( 'Content-type: application/json' ) ; $ out = [ ] ; if ( isset ( $ _POST [ 'depdrop_parents' ] ) ) { $ parents = $ _POST [ 'depdrop_parents' ] ; if ( $ parents != null ) { $ mod_table = $ parents [ 0 ] ; $ out = Categories :: jsCategories ( $ mod_table ) ; echo Json :: encode ( [ 'output' => $ out , 'selected' => '' ] ) ; return ; } } echo Json :: encode ( [ 'output' => '' , 'selected' => '' ] ) ; exit ; }
this produces an json array with the available categories for the passed over module .
19,570
public function actionIndex ( $ page = 1 , $ id = 0 ) { $ searchModel = new NewsSearch ( ) ; $ params = Yii :: $ app -> request -> queryParams ; if ( ! Yii :: $ app -> user -> can ( 'roleNewsModerator' ) && Yii :: $ app -> user -> can ( 'roleNewsAuthor' ) ) { $ params [ $ searchModel -> formName ( ) ] [ 'owner_id' ] = Yii :: $ app -> user -> id ; } $ dataProvider = $ searchModel -> search ( $ params ) ; $ pager = $ dataProvider -> getPagination ( ) ; $ pager -> pageSize = $ this -> module -> params [ 'pageSizeAdmin' ] ; $ pager -> totalCount = $ dataProvider -> getTotalCount ( ) ; $ maxPage = ceil ( $ pager -> totalCount / $ pager -> pageSize ) ; if ( $ page > $ maxPage ) { $ pager -> page = $ maxPage - 1 ; } else { $ pager -> page = $ page - 1 ; } return $ this -> render ( 'index' , [ 'searchModel' => $ searchModel , 'dataProvider' => $ dataProvider , 'currentId' => $ id , ] ) ; }
Lists all News models .
19,571
public function actionView ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ modelsI18n = $ model :: prepareI18nModels ( $ model ) ; if ( $ model -> pageSize > 0 ) { $ model -> orderBy = $ model -> defaultOrderBy ; $ model -> page = $ model -> calcPage ( ) ; } return $ this -> render ( 'view' , [ 'model' => $ model , 'modelsI18n' => $ modelsI18n , ] ) ; }
Displays a single News model .
19,572
public function actionCreate ( ) { $ model = $ this -> module -> model ( 'News' ) ; $ model = $ model -> loadDefaultValues ( ) ; $ modelsI18n = $ model :: prepareI18nModels ( $ model ) ; $ activeTab = $ this -> langCodeMain ; $ created = $ this -> savePost ( $ model , $ modelsI18n ) ; if ( ! $ created ) { return $ this -> render ( 'create' , [ 'model' => $ model , 'modelsI18n' => $ modelsI18n , 'activeTab' => $ activeTab , ] ) ; } else if ( $ activeTab = $ this -> modelsHaveErrors ( $ model , $ modelsI18n ) ) { Yii :: $ app -> session -> setFlash ( 'warning' , Yii :: t ( $ this -> tcModule , 'Record create but partially' ) ) ; if ( $ activeTab === true ) $ activeTab = $ this -> langCodeMain ; $ errors = $ model -> errors ; foreach ( $ modelsI18n as $ langCode => $ modelI18n ) { if ( $ modelI18n -> hasErrors ( ) ) { $ errors += $ modelI18n -> errors ; $ activeTab = $ langCode ; break ; } } $ error = array_shift ( $ errors ) ; if ( isset ( $ error [ 0 ] ) ) { Yii :: $ app -> session -> setFlash ( 'error' , $ error [ 0 ] ) ; } return $ this -> redirect ( [ 'update' , 'id' => $ model -> id , 'activeTab' => $ activeTab , ] ) ; } else { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , 'Record create success' ) ) ; if ( $ model -> aftersave == $ model :: AFTERSAVE_VIEW ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { return $ this -> redirect ( [ 'index' , 'page' => $ model -> page , 'id' => $ model -> id , 'sort' => $ model -> orderBy , ] ) ; } } }
Creates a new News model . If creation is successful the browser will be redirected to the view page .
19,573
public function actionUpdate ( $ id , $ activeTab = null ) { $ model = $ this -> findModel ( $ id ) ; if ( ! Yii :: $ app -> user -> can ( 'roleNewsModerator' ) && Yii :: $ app -> user -> can ( 'roleNewsAuthor' ) && ! Yii :: $ app -> user -> can ( 'updateOwnNews' , [ 'news' => $ model , 'canEditVisible' => $ this -> canAuthorEditOwnVisibleArticle , ] ) ) { if ( $ this -> canAuthorEditOwnVisibleArticle ) { throw new ForbiddenHttpException ( Yii :: t ( $ this -> tc , 'You can update only your own post' ) ) ; } else { throw new ForbiddenHttpException ( Yii :: t ( $ this -> tc , 'You can update only your own post still unvisible' ) ) ; } } $ modelsI18n = $ this -> module -> model ( 'News' ) -> prepareI18nModels ( $ model ) ; if ( empty ( $ activeTab ) ) $ activeTab = $ this -> langCodeMain ; $ created = $ this -> savePost ( $ model , $ modelsI18n ) ; if ( ! $ created || ( $ activeTab = $ this -> modelsHaveErrors ( $ model , $ modelsI18n ) ) ) { return $ this -> render ( 'update' , [ 'model' => $ model , 'modelsI18n' => $ modelsI18n , 'activeTab' => $ activeTab , ] ) ; } else { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , 'Record save success' ) ) ; if ( $ model -> aftersave == $ model :: AFTERSAVE_VIEW ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { return $ this -> redirect ( [ 'index' , 'page' => $ model -> page , 'id' => $ model -> id , 'sort' => $ model -> orderBy , ] ) ; } } }
Updates an existing News model . If update is successful the browser will be redirected to the view page .
19,574
protected function timeCorrection ( $ model , $ attribute ) { $ resultFormat = 'Y-m-d H:i' ; $ dateFormats = [ 'Y-m-d H:i' , 'Y-m-d G:i' , 'Y-m-j H:i' , 'Y-m-j G:i' , 'Y-n-d H:i' , 'Y-n-d G:i' , 'Y-n-j H:i' , 'Y-n-j G:i' , ] ; $ needCorrection = true ; if ( ':' == substr ( $ model -> $ attribute , - 1 ) ) { $ model -> $ attribute = rtrim ( $ model -> $ attribute , ':' ) ; $ model -> $ attribute .= '00:00' ; $ needCorrection = false ; } foreach ( $ dateFormats as $ dateFormat ) { $ datetime = \ DateTime :: createFromFormat ( $ dateFormat , $ model -> $ attribute ) ; if ( ! empty ( $ datetime ) ) break ; } if ( $ needCorrection && ! empty ( $ datetime ) && ! empty ( $ model -> timezoneshift ) ) { $ unixDatetime = $ datetime -> getTimestamp ( ) ; $ unixDatetime += 60 * intval ( $ model -> timezoneshift ) ; $ datetime -> setTimestamp ( $ unixDatetime ) ; $ model -> $ attribute = $ datetime -> format ( $ resultFormat ) ; } }
Correct datetime field according to timezone
19,575
protected function saveImage ( $ model ) { $ subdir = $ this -> module -> model ( 'News' ) -> getImageSubdir ( $ model -> id ) ; FileHelper :: createDirectory ( $ this -> uploadsNewsDir . '/' . $ subdir ) ; $ baseMainImageName = $ model -> id . '-' . $ this -> baseMainImageName ; $ path = $ subdir . '/' . $ baseMainImageName . '.' . $ model -> imagefile -> extension ; $ newImagePath = $ this -> uploadsNewsDir . '/' . $ path ; $ oldImagePath = $ this -> uploadsNewsDir . '/' . $ model -> image ; if ( $ newImagePath !== $ oldImagePath && is_file ( $ newImagePath ) ) { rename ( $ newImagePath , $ newImagePath . '-' . uniqid ( ) ) ; } if ( is_file ( $ oldImagePath ) ) { @ unlink ( $ oldImagePath ) ; } try { $ model -> imagefile -> saveAs ( $ newImagePath ) ; } catch ( ErrorException $ e ) { $ model -> addError ( 'imagefile' , $ error = $ e -> getMessage ( ) ) ; $ path = false ; } return $ path ; }
Save image file . Replace if exists .
19,576
public function actionDelete ( $ id , $ page = 1 ) { $ model = $ this -> findModel ( $ id ) ; $ model -> delete ( ) ; Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , 'Record with ID={id} delete success' , [ 'id' => $ id ] ) ) ; $ searchFormName = basename ( NewsSearch :: className ( ) ) ; $ paramSort = Yii :: $ app -> request -> get ( $ searchFormName , [ ] ) ; foreach ( $ paramSort as $ key => $ val ) { if ( empty ( $ val ) ) unset ( $ paramSort [ $ key ] ) ; } return $ this -> redirect ( [ 'index' , 'page' => $ page , $ searchFormName => $ paramSort , 'sort' => $ model -> orderBy , ] ) ; }
Deletes an existing News model . If deletion is successful the browser will be redirected to the index page .
19,577
protected function findModel ( $ id ) { $ model = $ this -> module -> model ( 'News' ) -> findOne ( $ id ) ; if ( $ model !== null ) { return $ model ; } else { throw new NotFoundHttpException ( Yii :: t ( $ this -> tc , 'The requested news does not exist' ) ) ; } }
Finds the News model based on its primary key value . If the model is not found a 404 HTTP exception will be thrown .
19,578
public function addCommand ( string $ name , string $ description , array $ operands = null , array $ options = null , array $ parameters = null ) : ShellBuilder { $ definition = new Definition ( ) ; foreach ( $ operands ?? [ ] as $ operand ) { $ definition -> addOperand ( new Operand ( $ operand [ 'name' ] ) ) ; } foreach ( $ options ?? [ ] as $ option ) { $ definition -> addOption ( new Option ( $ option [ 'name' ] , $ option [ 'description' ] , $ option [ 'short' ] ?? null , $ option [ 'long' ] ?? null , $ option [ 'flag' ] ?? null , $ option [ 'multiple' ] ?? null ) ) ; } $ this -> commands [ ] = new Command ( $ name , $ description , $ definition , $ parameters ) ; return $ this ; }
Add command to shell .
19,579
protected function reset ( ) : ShellBuilder { $ this -> name = $ this -> program = $ this -> version = $ this -> descriptor = $ this -> suggester = $ this -> parser = null ; $ this -> commands = [ ] ; return $ this ; }
Reset builder after build .
19,580
public function sendSuccessfulLoginEmailMessage ( UserInterface $ user ) { $ siteName = $ this -> settingsManager -> getParameter ( 'general.site_name' ) ; $ userName = sprintf ( '%s %s' , $ user -> getFirstName ( ) , $ user -> getLastName ( ) ) ; $ rendered = $ this -> templating -> render ( 'EkynaUserBundle:Security:login_success_email.html.twig' , [ 'username' => $ userName , 'sitename' => $ siteName , 'date' => new \ DateTime ( ) ] ) ; $ subject = $ this -> translator -> trans ( 'ekyna_user.email.login_success.subject' , [ '%sitename%' => $ siteName ] ) ; $ this -> sendEmail ( $ rendered , $ user -> getEmail ( ) , $ userName , $ subject ) ; }
Sends an email to the user to warn about successful login .
19,581
public function sendCreationEmailMessage ( UserInterface $ user , $ password ) { $ siteName = $ this -> settingsManager -> getParameter ( 'general.site_name' ) ; $ userName = sprintf ( '%s %s' , $ user -> getFirstName ( ) , $ user -> getLastName ( ) ) ; $ login = $ user -> getUsername ( ) ; if ( 0 === strlen ( $ password ) ) { return 0 ; } if ( null === $ loginUrl = $ this -> getLoginUrl ( $ user ) ) { return 0 ; } $ rendered = $ this -> templating -> render ( 'EkynaUserBundle:Admin/User:creation_email.html.twig' , [ 'username' => $ userName , 'sitename' => $ siteName , 'login_url' => $ loginUrl , 'login' => $ login , 'password' => $ password , ] ) ; $ subject = $ this -> translator -> trans ( 'ekyna_user.email.creation.subject' , [ '%sitename%' => $ siteName ] ) ; return $ this -> sendEmail ( $ rendered , $ user -> getEmail ( ) , $ userName , $ subject ) ; }
Sends an email to the user to warn about account creation .
19,582
protected function getLoginUrl ( UserInterface $ user ) { $ token = new UsernamePasswordToken ( $ user , 'none' , 'none' , $ user -> getRoles ( ) ) ; if ( $ this -> accessDecisionManager -> decide ( $ token , [ 'ROLE_ADMIN' ] ) ) { return $ this -> router -> generate ( 'ekyna_admin_security_login' , [ ] , UrlGeneratorInterface :: ABSOLUTE_URL ) ; } else if ( $ this -> config [ 'account' ] [ 'enable' ] ) { return $ this -> router -> generate ( 'fos_user_security_login' , [ ] , UrlGeneratorInterface :: ABSOLUTE_URL ) ; } return null ; }
Returns the login url .
19,583
public function destroySession ( SsoServer $ ssoServer , $ sessionId ) { $ signedRequest = $ this -> buildDestroySessionRequest ( $ ssoServer , $ sessionId ) ; $ response = $ this -> requestEngine -> sendRequest ( $ signedRequest ) ; if ( $ response -> getStatusCode ( ) === 404 && $ response -> getHeader ( 'Content-Type' ) === 'application/json' ) { $ data = json_decode ( $ response -> getContent ( ) , TRUE ) ; if ( is_array ( $ data ) && isset ( $ data [ 'error' ] ) && $ data [ 'error' ] === 'SessionNotFound' ) { return ; } } if ( $ response -> getStatusCode ( ) !== 200 ) { throw new Exception ( 'Unexpected status code for destroy session when calling "' . ( string ) $ signedRequest -> getUri ( ) . '": "' . $ response -> getStatus ( ) . '"' , 1354132939 ) ; } }
Destroy a client session with the given session id
19,584
public function buildDestroySessionRequest ( SsoServer $ ssoServer , $ sessionId ) { $ serviceUri = new Uri ( rtrim ( $ this -> serviceBaseUri , '/' ) . '/session/' . urlencode ( $ sessionId ) . '/destroy' ) ; $ serviceUri -> setQuery ( http_build_query ( array ( 'serverIdentifier' => $ ssoServer -> getServiceBaseUri ( ) ) ) ) ; $ request = \ TYPO3 \ Flow \ Http \ Request :: create ( $ serviceUri , 'DELETE' ) ; $ request -> setContent ( '' ) ; return $ this -> requestSigner -> signRequest ( $ request , $ ssoServer -> getKeyPairFingerprint ( ) , $ ssoServer -> getKeyPairFingerprint ( ) ) ; }
Builds a request for calling the destroy session webservice on this client
19,585
protected function getDiff ( $ model ) { $ dirty = $ model -> getDirty ( ) ; $ fresh = $ model -> fresh ( ) ? $ model -> fresh ( ) -> toArray ( ) : [ ] ; $ after = json_encode ( $ dirty ) ; $ before = json_encode ( array_intersect_key ( $ fresh , $ dirty ) ) ; return compact ( 'before' , 'after' ) ; }
Get diff between dirty and fresh model attributes .
19,586
protected function handleEventsLogging ( $ model ) { if ( config ( $ this -> package . '.log_events_to_file' ) === true ) { $ this -> logEventsToFile ( $ model ) ; } if ( config ( $ this -> package . '.log_events_to_db' ) === true ) { $ this -> logEventsToDB ( $ model ) ; } }
Handle events logging .
19,587
private function logEventsToDB ( $ model ) { $ user = auth ( ) -> user ( ) ; $ class = get_class ( $ model ) ; $ trace = debug_backtrace ( ) ; $ event = $ trace [ 2 ] ? $ trace [ 2 ] [ 'function' ] : "Unknown event" ; try { UserAction :: create ( array_merge ( $ this -> getDiff ( $ model ) , [ 'model' => $ class , 'action' => $ event , 'user_id' => $ user ? $ user -> id : null , 'model_id' => $ model -> id , ] ) ) ; } catch ( \ Exception $ e ) { $ message = $ e -> getMessage ( ) ; Log :: error ( "Could not record user action to db: '{$message}'" ) ; } }
Log Events to DB .
19,588
private function logEventsToFile ( $ model ) { $ user = auth ( ) -> user ( ) ; $ class = class_basename ( $ model ) ; $ trace = debug_backtrace ( ) ; $ event = $ trace [ 2 ] ? $ trace [ 2 ] [ 'function' ] : "Unknown event" ; if ( auth ( ) -> check ( ) ) { Log :: info ( "{$class} id {$model->id} {$event} by user id {$user->id} ({$user->email})." ) ; } else { Log :: info ( "{$class} id {$model->id} {$event} by unknown user." ) ; } }
Log Events to file .
19,589
public function getIndex ( ) { $ this -> di -> get ( "auth" ) -> isAdmin ( true ) ; $ user = new User ( ) ; $ user -> setDb ( $ this -> di -> get ( "db" ) ) ; $ title = "Min sida" ; $ view = $ this -> di -> get ( "view" ) ; $ pageRender = $ this -> di -> get ( "pageRender" ) ; $ data = [ "title" => $ title , "users" => $ user -> findAll ( ) , ] ; $ view -> add ( "admin/index" , $ data ) ; $ pageRender -> renderPage ( [ "title" => $ title ] ) ; }
Get the Admin indexpage .
19,590
public function getPostEditAdmin ( $ id ) { $ this -> di -> get ( "auth" ) -> isAdmin ( true ) ; $ title = "Admin - Redigera profil" ; $ card = "Redigera" ; $ view = $ this -> di -> get ( "view" ) ; $ pageRender = $ this -> di -> get ( "pageRender" ) ; $ form = new EditAdminForm ( $ this -> di , $ id ) ; $ form -> check ( ) ; $ data = [ "form" => $ form -> getHTML ( ) , "card" => $ card , "title" => $ title , ] ; $ view -> add ( "admin/edit" , $ data ) ; $ pageRender -> renderPage ( [ "title" => $ title ] ) ; }
Edit a user as admin .
19,591
private static function guessAbsoluteURL ( ) { $ scheme = 'http' ; $ host = 'localhost' ; if ( isset ( $ _SERVER [ 'REQUEST_SCHEME' ] ) ) { $ scheme = $ _SERVER [ 'REQUEST_SCHEME' ] ; } if ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ) { $ host = $ _SERVER [ 'HTTP_HOST' ] ; } return $ scheme . '://' . $ host . '/' ; }
Guest absolute url from server variables .
19,592
private function patternMatch ( $ url ) { $ url = explode ( '/' , $ url ) ; $ pattern = explode ( '/' , $ this -> pattern ) ; $ matches = true ; if ( count ( $ url ) > count ( $ pattern ) ) { return false ; } foreach ( $ pattern as $ pkey => $ pvalue ) { if ( ! isset ( $ url [ $ pkey ] ) ) { if ( substr ( $ pvalue , 0 , 2 ) === '{?' ) { continue ; } else { return false ; } } if ( $ pvalue != $ url [ $ pkey ] && substr ( $ pvalue , 0 , 1 ) != '{' ) { return false ; } } return $ matches ; }
Determines if this route matches a variable path
19,593
public function build ( string $ method , string $ url , $ handler ) : Route { return new BaseRoute ( $ method , $ url , $ handler ) ; }
Build instance of the route
19,594
public function newInstance ( ) { foreach ( $ this -> loaders as $ loader ) { if ( false === $ loader instanceof LoaderInterface ) { throw new \ InvalidArgumentException ( "Loaders must implement Affiniti\Config\Loader\LoaderInterface." ) ; } $ loader -> setLocator ( $ this -> fileLocator ) ; } return new DelegatingLoader ( new LoaderResolver ( $ this -> loaders ) ) ; }
Returns a new DelegatingLoader which allows multiple loaders to be managed .
19,595
public function addPath ( $ namespace , $ path , $ prepend = false ) { if ( $ namespace === null ) { $ namespace = '_' ; } if ( ! isset ( $ this -> paths [ $ namespace ] ) ) { $ this -> paths [ $ namespace ] = [ ] ; } if ( $ prepend ) { array_unshift ( $ this -> paths [ $ namespace ] , $ path ) ; } else { array_push ( $ this -> paths [ $ namespace ] , $ path ) ; } }
Register a namespaced path to search for asset files .
19,596
public function enable ( $ ver = null ) { if ( $ ver == null ) { $ ver = ( $ this -> getVersion ( ) ) ? $ this -> getVersion ( ) : $ this -> defVersion ; } if ( $ this -> isEnabled ( ) && $ this -> getVersion ( ) == $ ver ) { return $ this ; } $ ver = ( string ) $ ver ; $ this -> enabled = $ ver ; return $ this ; }
Enable jQ by minimum version required
19,597
protected function append ( array $ item ) { if ( ! $ this -> isEnabled ( ) ) { $ this -> enable ( ) ; } $ this -> getContainer ( ) -> append ( $ item ) ; }
Append data to container
19,598
protected function prepend ( array $ item ) { if ( ! $ this -> isEnabled ( ) ) { $ this -> enable ( ) ; } $ container = $ this -> getContainer ( ) ; $ currentArr = $ container -> getArrayCopy ( ) ; array_unshift ( $ currentArr , $ item ) ; $ container -> exchangeArray ( $ currentArr ) ; }
Prepend data to container
19,599
public function getDecorator ( ) { if ( ! $ this -> decorator ) { $ this -> decorator = new DefaultDecorator ( ) ; } $ this -> decorator -> no_conflict_mode = $ this -> isNoConflict ( ) ; $ this -> decorator -> base_library = $ this -> getLibSrc ( ) ; $ this -> decorator -> no_conflict_handler = $ this -> getNoConflictHandler ( ) ; return $ this -> decorator ; }
Get decorator for rendering data in container