idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
700 | private function start ( ) { new Session ( ) ; $ this -> setBaseURL ( ) ; $ this -> setRequestURI ( ) ; $ this -> fetchRouteRules ( ) ; $ this -> establishConnection ( ) ; $ this -> locateMethod ( ) ; $ this -> invokeMethod ( ) ; } | Starts system by first loading configuration then processing request . Locates module controller and method based request set and calls it . Connects to database before invoking located method if configured . |
701 | private function fetchRouteRules ( ) { $ this -> route_config = require_once ROOT . 'config' . DSC . 'routes.php' ; $ regex = array ( '(:string)' => "([a-zA-Z0-9-_.]+)" , '(:int)' => "([0-9]+)" ) ; foreach ( $ this -> route_config [ 'rule' ] as $ rule => $ value ) { $ new_rule = array ( ) ; foreach ( explode ( '/' , $ rule ) as $ split ) { if ( array_key_exists ( $ split , $ regex ) ) { $ new_rule [ ] = str_replace ( $ split , $ regex [ $ split ] , $ split ) ; } else { $ new_rule [ ] = preg_quote ( $ split ) ; } } $ this -> route_rules [ implode ( preg_quote ( '/' ) , $ new_rule ) ] = $ value ; } } | Fetches routes from route config . Replace placeholder with their regex . Store it to route rules property . |
702 | protected function locateMethod ( ) { if ( $ this -> request_uri === '' ) { $ callback = $ this -> route_rules [ '/' ] ; $ this -> located_controller = $ callback [ 'controller' ] ; $ this -> located_method = $ callback [ 'method' ] ; return TRUE ; } foreach ( $ this -> route_rules as $ rule => $ callback ) { preg_match ( '#^' . $ rule . '#' , $ this -> request_uri , $ matches ) ; if ( $ matches ) { $ controller = $ callback [ 'controller' ] ; $ method = $ callback [ 'method' ] ; $ index = 0 ; if ( strpos ( $ controller , '@' ) !== FALSE ) { $ at = substr ( $ controller , 1 ) ; if ( $ at == 0 || ! isset ( $ matches [ $ at ] ) ) { throw new Exception ( '@' . $ at . ' not found in regex.' ) ; } $ controller = $ matches [ $ at ] ; $ index = ++ $ at ; } if ( strpos ( $ method , '@' ) !== FALSE ) { $ at = substr ( $ method , 1 ) ; if ( $ at == 0 || ! isset ( $ matches [ $ at ] ) ) { throw new Exception ( '@' . $ at . ' not found in regex.' ) ; } $ method = $ matches [ $ at ] ; $ index = ++ $ at ; } $ this -> located_controller = $ controller ; $ this -> located_method = $ method ; $ this -> remaining_uri = array_slice ( explode ( '/' , $ this -> request_uri ) , $ index ) ; break ; } } } | Locating controller and it s method based on matched route rules . |
703 | public static function getCurrentURL ( ) { $ pageURL = 'http' ; if ( isset ( $ _SERVER [ "HTTPS" ] ) && $ _SERVER [ "HTTPS" ] == "on" ) { $ pageURL .= "s" ; } $ pageURL .= "://" ; if ( $ _SERVER [ "SERVER_PORT" ] != "80" ) { $ pageURL .= $ _SERVER [ "SERVER_NAME" ] . ":" . $ _SERVER [ "SERVER_PORT" ] . $ _SERVER [ "REQUEST_URI" ] ; } else { $ pageURL .= $ _SERVER [ "SERVER_NAME" ] . $ _SERVER [ "REQUEST_URI" ] ; } return $ pageURL ; } | Return current url of the request . |
704 | public function compile ( $ content ) { $ phpCode = '' ; foreach ( token_get_all ( $ content ) as $ token ) { $ phpCode .= is_array ( $ token ) ? $ this -> parsePHPToken ( $ token ) : $ token ; } if ( count ( $ this -> footer ) > 0 ) { $ phpCode = ltrim ( $ phpCode , PHP_EOL ) . PHP_EOL . implode ( PHP_EOL , array_reverse ( $ this -> footer ) ) ; } return $ phpCode ; } | Compile the given template content to the corresponding valid PHP . |
705 | private function parsePHPToken ( $ token ) { list ( $ type , $ expr ) = $ token ; if ( $ type == T_INLINE_HTML ) { $ expr = $ this -> compileStatements ( $ expr ) ; $ expr = $ this -> compileComments ( $ expr ) ; $ expr = $ this -> compileRawEchos ( $ expr ) ; $ expr = $ this -> compileRegularEchos ( $ expr ) ; } return $ expr ; } | Parse the PHP token . |
706 | private function compileComments ( $ expr ) { $ commentTags = [ '{{--' , '--}}' ] ; $ pattern = sprintf ( '/%s(.*?)%s/s' , $ commentTags [ 0 ] , $ commentTags [ 1 ] ) ; return preg_replace ( $ pattern , '' , $ expr ) ; } | Compile template comments into valid PHP . |
707 | private function compileEchos ( $ expr , $ escaped ) { $ tags = $ escaped ? [ '{{' , '}}' ] : [ '{!!' , '!!}' ] ; $ pattern = sprintf ( '/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s' , $ tags [ 0 ] , $ tags [ 1 ] ) ; return preg_replace_callback ( $ pattern , function ( $ matches ) use ( $ escaped ) { $ content = $ this -> compileEchoDefaults ( $ matches [ 2 ] ) ; if ( $ escaped ) { $ content = sprintf ( 'e(%s)' , $ content ) ; } if ( $ matches [ 1 ] ) { return substr ( $ matches [ 0 ] , 1 ) ; } $ lineFeeds = ! empty ( $ matches [ 3 ] ) ? $ matches [ 3 ] . $ matches [ 3 ] : '' ; return '<?php echo ' . $ content . '; ?>' . $ lineFeeds ; } , $ expr ) ; } | Compile the echo statements . |
708 | protected function compileInclude ( $ expr ) { $ expr = explode ( ',' , $ this -> stripParentheses ( $ expr ) , 2 ) ; $ vars = isset ( $ expr [ 1 ] ) ? trim ( $ expr [ 1 ] ) : '' ; if ( empty ( $ vars ) ) { return "<?php echo \$this->make({$expr[0]}, get_defined_vars()); ?>" ; } else { $ result = "<?php echo \$this->make({$expr[0]}, array_merge(get_defined_vars(), {$vars})); ?>" ; return $ result ; } } | Compile the include statements into valid PHP . |
709 | protected function compileForeach ( $ expr ) { preg_match ( '/\( *(.*) +as *([^\)]*)/is' , $ expr , $ matches ) ; $ iteratee = trim ( $ matches [ 1 ] ) ; $ iteration = trim ( $ matches [ 2 ] ) ; return "<?php foreach({$iteratee} as {$iteration}): ?>" ; } | Compile the foreach statements into valid PHP . |
710 | public function getValue ( ) : ArrayObject { $ this -> value = [ ] ; foreach ( ( array ) $ this as $ element ) { if ( $ element -> getElement ( ) instanceof Radio && $ element -> getElement ( ) -> checked ( ) ) { $ this -> value [ ] = $ element -> getElement ( ) -> getValue ( ) ; } } return new ArrayObject ( $ this -> value ) ; } | Gets all checked values as an ArrayObject . |
711 | public function next ( ) { $ this -> index ++ ; if ( $ this -> className ) { $ this -> value = $ this -> query -> getObject ( $ this -> className ) ; } else { $ this -> value = $ this -> query -> getRow ( ) ; } return $ this ; } | Move forward to next row |
712 | public function register ( $ function_name , $ timeout = null ) { return parent :: register ( Task :: getName ( $ function_name ) , $ timeout ) ; } | Registers a function name with the job server with an optional timeout . The timeout specifies how many seconds the server will wait before marking a job as failed . If the timeout is set to zero there is no timeout . |
713 | public function addFunction ( $ function_name , $ function , $ context = null , $ timeout = 0 ) { return parent :: addFunction ( Task :: getName ( $ function_name ) , Closure :: fromCallable ( $ function ) , $ context , $ timeout ) ; } | Registers a function name with the job server and specifies a callback corresponding to that function . Optionally specify extra application context data to be used when the callback is called and a timeout . |
714 | public static function all ( $ path ) { $ data = array ( ) ; if ( file_exists ( $ path ) ) { $ values = file_get_contents ( $ path ) ; $ values = explode ( "\n" , $ values ) ; foreach ( $ values as $ key => $ value ) { $ var = explode ( '=' , $ value ) ; if ( count ( $ var ) == 2 ) { if ( $ var [ 0 ] != "" ) $ data [ $ var [ 0 ] ] = $ var [ 1 ] ? $ var [ 1 ] : null ; } else { if ( $ var [ 0 ] != "" ) $ data [ $ var [ 0 ] ] = null ; } } array_filter ( $ data ) ; } return $ data ; } | Get all the env values as an array |
715 | public static function create ( $ path , $ key , $ value = null ) { $ data = CoreManager :: all ( $ path ) ; if ( ! CoreManager :: has ( $ data , $ key ) ) { $ contents = file_get_contents ( $ path ) ; $ value = str_replace ( ' ' , '_' , $ value ) ; $ data = "\n" . $ key . "=" . $ value ; $ result = file_put_contents ( $ path , $ data , FILE_APPEND | LOCK_EX ) ; return true ; Artisan :: call ( 'config:cache' ) ; } else { return false ; } } | Create a new key with value |
716 | public function getAcceptableContentTypes ( ) { if ( null !== $ this -> acceptableContentTypes ) { return $ this -> acceptableContentTypes ; } $ acceptableContentTypes = $ this -> headers -> getParameterListAsObject ( 'ACCEPT' ) ; return $ this -> acceptableContentTypes = $ acceptableContentTypes -> getParameterKeys ( ) ; } | Gets a list of content types acceptable by the client browser |
717 | public function set ( $ name , \ Closure $ closure ) { $ this -> extensions -> set ( $ name , $ closure ) ; return $ this ; } | Add a new extension |
718 | public static function C2s ( array $ p , & $ theta , & $ phi ) { $ x ; $ y ; $ z ; $ d2 ; $ x = $ p [ 0 ] ; $ y = $ p [ 1 ] ; $ z = $ p [ 2 ] ; $ d2 = $ x * $ x + $ y * $ y ; $ theta = ( $ d2 == 0.0 ) ? 0.0 : atan2 ( $ y , $ x ) ; $ phi = ( $ z == 0.0 ) ? 0.0 : atan2 ( $ z , sqrt ( $ d2 ) ) ; return ; } | - - - - - - - i a u C 2 s - - - - - - - |
719 | public static function removeRecognition ( string $ name ) : bool { if ( isset ( self :: $ recognitions [ $ name ] ) ) { unset ( self :: $ recognitions [ $ name ] ) ; return true ; } return false ; } | removes recognition with given name |
720 | public static function toType ( $ string ) { if ( null == $ string ) { return $ string ; } if ( is_string ( $ string ) && 'null' === strtolower ( $ string ) ) { return null ; } foreach ( self :: $ recognitions as $ recognition ) { $ value = $ recognition ( $ string ) ; if ( null !== $ value ) { return $ value ; } } return ( string ) $ string ; } | parses string to a type depending on the value of the string |
721 | public static function toBool ( $ string ) { if ( null === $ string ) { return null ; } return in_array ( strtolower ( $ string ) , self :: $ booleanTrue ) ; } | parses string to a boolean value |
722 | public static function toList ( $ string , string $ separator = self :: SEPARATOR_LIST ) { if ( null === $ string ) { return null ; } $ withoutParenthesis = self :: removeParenthesis ( $ string ) ; if ( '' === $ withoutParenthesis ) { return [ ] ; } if ( strstr ( $ withoutParenthesis , $ separator ) !== false ) { return explode ( $ separator , $ withoutParenthesis ) ; } return [ $ withoutParenthesis ] ; } | parses string to a list of strings |
723 | private static function removeParenthesis ( string $ string ) : string { if ( substr ( $ string , 0 , 1 ) === '[' && substr ( $ string , - 1 ) === ']' ) { return substr ( $ string , 1 , strlen ( $ string ) - 2 ) ; } return $ string ; } | removes leading and trailing parenthesis from list and map strings |
724 | public static function toMap ( $ string ) { if ( null === $ string ) { return null ; } elseif ( '' === $ string ) { return [ ] ; } $ map = [ ] ; foreach ( self :: toList ( $ string ) as $ keyValue ) { if ( strstr ( $ keyValue , ':' ) !== false ) { list ( $ key , $ value ) = explode ( ':' , $ keyValue , 2 ) ; $ map [ $ key ] = $ value ; } else { $ map [ ] = $ keyValue ; } } return $ map ; } | parses string to a map |
725 | public static function toRange ( $ string ) { if ( null === $ string ) { return null ; } elseif ( '' === $ string ) { return [ ] ; } if ( ! strstr ( $ string , '..' ) ) { return [ ] ; } list ( $ min , $ max ) = explode ( '..' , $ string , 2 ) ; if ( null == $ min || null == $ max ) { return [ ] ; } return range ( $ min , $ max ) ; } | parses string to a range |
726 | public static function toClass ( $ string ) { if ( empty ( $ string ) ) { return null ; } $ classnameMatches = [ ] ; if ( preg_match ( '/^([a-zA-Z_]{1}[a-zA-Z0-9_\\\\]*)\.class/' , $ string , $ classnameMatches ) != false ) { return new \ ReflectionClass ( $ classnameMatches [ 1 ] ) ; } return null ; } | parses string to a reflection class |
727 | public static function toClassname ( $ string ) { if ( empty ( $ string ) ) { return null ; } $ classnameMatches = [ ] ; if ( preg_match ( '/^([a-zA-Z_]{1}[a-zA-Z0-9_\\\\]*)\::class$/' , $ string , $ classnameMatches ) != false ) { if ( class_exists ( $ classnameMatches [ 1 ] ) ) { return $ classnameMatches [ 1 ] ; } } return null ; } | parses string as class name |
728 | private function parse ( string $ method , ... $ arguments ) { if ( null === $ this -> value ) { return $ this -> default ; } return self :: $ method ( $ this -> value , ... $ arguments ) ; } | does the actual parsing |
729 | protected function _splitResponse ( $ ch , $ data ) { $ curl_info = curl_getinfo ( $ ch ) ; $ header_size = $ curl_info [ "header_size" ] ; $ returner = [ 'header' => explode ( "\r\n\r\n" , trim ( substr ( $ data , 0 , $ header_size ) ) ) , 'body' => substr ( $ data , $ header_size ) , ] ; return $ returner ; } | Divides the header from the body of a server response . |
730 | protected function _init ( $ ch ) { curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; try { curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; } catch ( \ Exception $ e ) { } curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; curl_setopt ( $ ch , CURLOPT_HTTPGET , true ) ; curl_setopt ( $ ch , CURLOPT_ENCODING , "gzip" ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYHOST , false ) ; curl_setopt_array ( $ ch , $ this -> _options ) ; return $ ch ; } | Initializes to cURL connection for all methods . |
731 | public function getTopRequestors ( $ accessingObject ) { $ individual = false ; if ( $ accessingObject -> modelAlias === 'cascade\models\User' && isset ( $ accessingObject -> object_individual_id ) ) { $ individual = Registry :: getObject ( $ accessingObject -> object_individual_id , false ) ; if ( $ individual ) { $ requestors [ ] = $ individual -> primaryKey ; } $ requestors [ ] = $ accessingObject -> primaryKey ; } elseif ( $ accessingObject -> modelAlias === ':Individual\\ObjectIndividual' ) { $ requestors [ ] = $ accessingObject -> primaryKey ; } if ( empty ( $ requestors ) ) { return false ; } return $ requestors ; } | Get top requestors . |
732 | public static function getHostname ( string $ url ) { $ url = UrlHelper :: validateUrl ( $ url ) ; $ hostname = parse_url ( $ url , PHP_URL_HOST ) ; if ( $ hostname === false ) { throw new InvalidArgumentException ( "Could not determine hostname, url seems to be invalid: $url" ) ; } return $ hostname ; } | Returns the hostname of the provided url |
733 | public static function getPort ( string $ url ) { $ url = UrlHelper :: validateUrl ( $ url ) ; $ port = parse_url ( $ url , PHP_URL_PORT ) ; if ( $ port === false ) { throw new InvalidArgumentException ( "Could not determine port, url seems to be invalid: $url" ) ; } return $ port ; } | Returns the port of the provided url |
734 | public static function isHttps ( string $ url ) { $ url = UrlHelper :: validateUrl ( $ url ) ; $ parsedUrl = parse_url ( $ url ) ; if ( $ parsedUrl === false ) { throw new InvalidArgumentException ( "The provided url is not valid: $url" ) ; } return $ parsedUrl [ "scheme" ] === UrlHelper :: HTTPS_SCHEME ; } | Returns whether the provided url has the HTTPS scheme |
735 | public static function isHttp ( string $ url ) { $ url = UrlHelper :: validateUrl ( $ url ) ; $ parsedUrl = parse_url ( $ url ) ; if ( $ parsedUrl === false ) { throw new InvalidArgumentException ( "The provided url is not valid: $url" ) ; } return $ parsedUrl [ "scheme" ] === UrlHelper :: HTTP_SCHEME ; } | Returns whether the provided url has the HTTP scheme |
736 | public static function buildUrl ( string $ url , $ parameters = null , int $ encoding = PHP_QUERY_RFC3986 ) : string { if ( empty ( $ parameters ) ) { return $ url ; } $ url = UrlHelper :: removeTrailingSlash ( $ url ) ; if ( StringHelper :: contains ( $ url , '?' ) ) { $ url .= '&' ; } else { $ url .= "?" ; } return $ url . http_build_query ( $ parameters , null , '&' , $ encoding ) ; } | Constructs a url with the specified parameters . If there where already parameters the provided ones are added . the default encoding used is RFC3986 causing spaces to be represented by %20 . |
737 | public function getCardType ( ) : ? string { if ( ! $ this -> hasCardType ( ) ) { $ this -> setCardType ( $ this -> getDefaultCardType ( ) ) ; } return $ this -> cardType ; } | Get card type |
738 | public function register ( ) { $ user = $ this -> Users -> newEntity ( $ this -> request -> data ) ; if ( $ this -> request -> is ( 'post' ) && ! empty ( $ this -> request -> data ) ) { if ( $ this -> Users -> save ( $ user ) ) { $ this -> loadModel ( 'Wasabi/Core.Tokens' ) ; $ this -> Tokens -> invalidateExistingTokens ( $ user -> id , TokensTable :: TYPE_EMAIL_VERIFICATION ) ; $ token = $ this -> Tokens -> generateToken ( $ user , TokensTable :: TYPE_EMAIL_VERIFICATION ) ; $ this -> getMailer ( 'Wasabi/Core.User' ) -> send ( 'verifyEmail' , [ $ user , $ token ] ) ; $ this -> Flash -> success ( __d ( 'wasabi_core' , 'Registration successful! We have sent you an email to verify your email address. Please follow the instructions in this email.' ) ) ; $ this -> redirect ( [ 'action' => 'login' ] ) ; return ; } $ this -> Flash -> error ( $ this -> formErrorMessage ) ; } $ this -> set ( [ 'user' => $ user ] ) ; $ this -> viewBuilder ( ) -> layout ( 'Wasabi/Core.support' ) ; } | Register action GET | POST |
739 | public function verify ( $ id ) { if ( ! $ this -> request -> is ( [ 'get' , 'post' , 'put' ] ) ) { throw new MethodNotAllowedException ( ) ; } $ user = $ this -> Users -> get ( $ id ) ; if ( $ this -> request -> is ( [ 'post' , 'put' ] ) ) { if ( $ user -> verified ) { $ this -> Flash -> warning ( __d ( 'wasabi_core' , 'The email address of user <strong>{0}</strong> is already verified.' , $ user -> username ) ) ; $ this -> redirect ( $ this -> Filter -> getBacklink ( [ 'action' => 'index' ] , $ this -> request ) ) ; return ; } if ( $ this -> Users -> verify ( $ user , true ) ) { $ this -> getMailer ( 'Wasabi/Core.User' ) -> send ( 'verifiedByAdminEmail' , [ $ user ] ) ; $ this -> Flash -> success ( __d ( 'wasabi_core' , 'The email address of user <strong>{0}</strong> has been verified.' , $ user -> username ) ) ; $ this -> redirect ( $ this -> Filter -> getBacklink ( [ 'action' => 'index' ] , $ this -> request ) ) ; return ; } else { $ this -> Flash -> error ( $ this -> dbErrorMessage ) ; } } $ this -> set ( [ 'user' => $ user ] ) ; } | Verify action GET | POST | PUT |
740 | public function heartBeat ( ) { if ( ! $ this -> request -> isAll ( [ 'ajax' , 'post' ] ) ) { throw new MethodNotAllowedException ( ) ; } $ loginTime = $ this -> request -> session ( ) -> check ( 'loginTime' ) ? $ this -> request -> session ( ) -> read ( 'loginTime' ) : 0 ; $ maxLoggedInTime = ( int ) Wasabi :: setting ( 'Core.Login.HeartBeat.max_login_time' , 0 ) / 1000 ; $ logoutTime = $ loginTime + $ maxLoggedInTime ; if ( time ( ) <= $ logoutTime ) { $ this -> set ( [ 'status' => 200 , '_serialize' => [ 'status' ] ] ) ; } else { $ this -> Auth -> logout ( ) ; $ this -> set ( [ 'status' => 401 , '_serialize' => [ 'status' ] ] ) ; } } | HeartBeat action AJAX POST |
741 | public function profile ( ) { $ user = $ this -> Users -> get ( $ this -> Auth -> user ( 'id' ) ) ; if ( $ this -> request -> is ( 'put' ) && ! empty ( $ this -> request -> data ) ) { $ user = $ this -> Users -> patchEntity ( $ user , $ this -> request -> data ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> Auth -> setUser ( Hash :: merge ( $ this -> Auth -> user ( ) , $ user -> toArray ( ) ) ) ; $ this -> Flash -> success ( __d ( 'wasabi_core' , 'Your profile has been updated.' ) ) ; $ this -> redirect ( [ 'action' => 'profile' ] ) ; return ; } else { $ this -> Flash -> error ( $ this -> formErrorMessage ) ; } } $ this -> set ( [ 'user' => $ user , 'languages' => Hash :: map ( Configure :: read ( 'languages.backend' ) , '{n}' , function ( $ language ) { return [ 'value' => $ language -> id , 'text' => $ language -> name ] ; } ) ] ) ; } | Profile action GET | PUT |
742 | public function lostPassword ( ) { if ( $ this -> request -> is ( 'post' ) && ! empty ( $ this -> request -> data ) ) { $ user = $ this -> Users -> newEntity ( $ this -> request -> data , [ 'validate' => 'emailOnly' ] ) ; if ( ! $ user -> errors ( ) ) { if ( ( $ user = $ this -> Users -> existsWithEmail ( $ user -> email ) ) ) { $ this -> loadModel ( 'Wasabi/Core.Tokens' ) ; $ this -> Tokens -> invalidateExistingTokens ( $ user -> id , TokensTable :: TYPE_LOST_PASSWORD ) ; $ token = $ this -> Tokens -> generateToken ( $ user , TokensTable :: TYPE_LOST_PASSWORD ) ; $ this -> getMailer ( 'Wasabi/Core.User' ) -> send ( 'lostPasswordEmail' , [ $ user , $ token ] ) ; } $ this -> Flash -> success ( __d ( 'wasabi_core' , 'We have sent you an email to reset your password.' ) ) ; $ this -> redirect ( [ 'action' => 'login' ] ) ; return ; } else { $ this -> request -> session ( ) -> write ( 'data.lostPassword' , $ this -> request -> data ( ) ) ; $ this -> Flash -> error ( $ this -> formErrorMessage ) ; $ this -> redirect ( [ 'action' => 'lostPassword' ] ) ; return ; } } else { if ( $ this -> request -> session ( ) -> check ( 'data.lostPassword' ) ) { $ this -> request -> data = ( array ) $ this -> request -> session ( ) -> read ( 'data.lostPassword' ) ; $ this -> request -> session ( ) -> delete ( 'data.lostPassword' ) ; } $ user = $ this -> Users -> newEntity ( $ this -> request -> data , [ 'validate' => 'emailOnly' ] ) ; } $ this -> set ( 'user' , $ user ) ; $ this -> render ( null , 'Wasabi/Core.support' ) ; } | lostPassword action GET | POST |
743 | public function resetPassword ( $ tokenString ) { $ this -> loadModel ( 'Wasabi/Core.Tokens' ) ; if ( ! $ tokenString || ! ( $ token = $ this -> Tokens -> findByToken ( $ tokenString ) ) || $ token -> hasExpired ( ) || $ token -> used ) { $ this -> redirect ( '/' ) ; return ; } $ user = $ this -> Users -> get ( $ token -> user_id , [ 'fields' => [ 'id' ] ] ) ; if ( $ this -> request -> is ( 'put' ) && ! empty ( $ this -> request -> data ) ) { $ user = $ this -> Users -> patchEntity ( $ user , $ this -> request -> data , [ 'validate' => 'passwordOnly' ] ) ; $ connection = $ this -> Users -> connection ( ) ; $ connection -> begin ( ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> Tokens -> invalidateExistingTokens ( $ user -> id , TokensTable :: TYPE_LOST_PASSWORD ) ; $ connection -> commit ( ) ; $ this -> Flash -> success ( __d ( 'wasabi_core' , 'Your password has been changed successfully.' ) ) ; $ this -> redirect ( [ 'action' => 'login' ] ) ; return ; } else { $ connection -> rollback ( ) ; $ this -> Flash -> error ( $ this -> formErrorMessage ) ; } } $ this -> set ( 'user' , $ user ) ; $ this -> render ( null , 'Wasabi/Core.support' ) ; } | resetPassword action GET | POST |
744 | public function verifyByToken ( $ tokenString ) { $ this -> loadModel ( 'Wasabi/Core.Tokens' ) ; if ( ! $ this -> request -> is ( 'get' ) ) { throw new MethodNotAllowedException ( ) ; } if ( $ tokenString && ( bool ) ( $ token = $ this -> Tokens -> findByToken ( $ tokenString ) ) && ! $ token -> hasExpired ( ) && ! $ token -> used ) { $ user = $ this -> Users -> get ( $ token -> user_id ) ; $ connection = $ this -> Users -> connection ( ) ; $ connection -> begin ( ) ; if ( $ this -> Users -> verify ( $ user ) ) { $ this -> Tokens -> invalidateExistingTokens ( $ user -> id , TokensTable :: TYPE_EMAIL_VERIFICATION ) ; $ connection -> commit ( ) ; } else { $ connection -> rollback ( ) ; } } $ this -> render ( null , 'Wasabi/Core.support' ) ; } | verifyByToken action GET |
745 | public function start ( ) { header ( 'Content-Type: text/event-stream' ) ; header ( 'Cache-Control: no-cache' ) ; header ( 'Access-Control-Allow-Origin: *' ) ; if ( isset ( $ _SERVER [ 'HTTP_LAST_EVENT_ID' ] ) ) { $ this -> lastId = intval ( $ _SERVER [ 'HTTP_LAST_EVENT_ID' ] ) ; } elseif ( isset ( $ _GET [ 'lastEventId' ] ) ) { $ this -> lastId = intval ( $ _GET [ 'lastEventId' ] ) ; } if ( $ this -> padding > 0 ) { $ this -> putLine ( ':' . str_repeat ( ' ' , $ this -> padding ) ) ; } $ this -> putLine ( 'retry: ' . $ this -> retry ) ; $ this -> flush ( ) ; } | Start event source . Sends headers padding and retry delay . |
746 | public function encode ( ) { if ( ! empty ( $ this -> attributes ) ) { foreach ( $ this -> attributes as $ name => $ params ) { if ( is_numeric ( $ name ) ) { $ name = $ params ; } $ owner = $ this -> owner ; if ( $ owner -> hasAttribute ( $ name ) ) { $ owner -> setAttribute ( $ name , Json :: encode ( $ owner -> getAttribute ( $ name ) ) ) ; } } } } | Encode attributes to JSON strings |
747 | public function run ( ) { $ moduleFile = $ this -> getModulePath ( ) ; $ moduleName = $ this -> getModuleClass ( ) ; if ( ! file_exists ( $ moduleFile ) || ! is_readable ( $ moduleFile ) ) { throw new Exception ( "Module resource not found (" . $ this -> getModuleName ( ) . ")" , 404 ) ; } else { require_once ( $ moduleFile ) ; } if ( ! class_exists ( $ moduleName ) || ! in_array ( "TS3WA_Module" , class_parents ( $ moduleName ) ) ) { throw new Exception ( "Module resource not found (" . $ this -> getModuleName ( ) . ")" , 404 ) ; } $ this -> module = new $ moduleName ( $ this ) ; if ( ! method_exists ( $ this -> module , $ this -> getActionMethod ( ) ) ) { throw new Exception ( "Action resource not found (" . $ this -> getActionName ( ) . ")" , 404 ) ; } call_user_func ( array ( $ this -> module , $ this -> getActionMethod ( ) ) ) ; if ( $ this -> module -> isRender ( ) ) { $ this -> module -> dispatch ( ) ; } } | Starts the application by loading the requested module and action . |
748 | protected function makeAttribute ( $ name , array $ values ) { $ attr = $ name . '="' ; switch ( true ) { case $ values === [ true ] : $ attr = $ name ; return $ attr ; break ; case $ name === 'style' : case strpos ( $ name , 'on' ) === 0 : $ attr .= htmlspecialchars ( join ( ';' , $ values ) ) ; break ; default : $ attr .= htmlspecialchars ( join ( ' ' , $ values ) ) ; break ; } $ attr .= '"' ; return $ attr ; } | make attribute for tag |
749 | public function detectCloseMode ( $ name ) { $ name = strtolower ( $ name ) ; return isset ( $ this -> closeModeMapping [ $ name ] ) ? $ this -> closeModeMapping [ $ name ] : self :: CLOSE_NORMAL ; } | auto detect closing mode by tag name |
750 | public function peek ( string $ id ) { if ( ! isset ( $ this -> registered [ $ id ] ) ) { return null ; } return isset ( $ this -> instances [ $ id ] ) ? $ this -> instances [ $ id ] : null ; } | Get component but return null instead of creating new instance |
751 | public function set ( $ id , $ value ) : Slot { $ this -> offsetSet ( $ id , $ value ) ; return $ this -> slot ( $ id ) ; } | Set component or factory |
752 | public function newInstance ( $ id ) { if ( ! isset ( $ this -> registered [ $ id ] ) ) { throw new ComponentNotFoundException ( $ id ) ; } $ factory = $ this -> factories [ $ id ] ?? null ; if ( ! $ factory || ! is_callable ( $ factory ) || ! method_exists ( $ factory , '__invoke' ) ) { throw new FactoryNotFoundException ( $ id ) ; } $ slot = $ this -> slots [ $ id ] ?? new Slot ( $ id ) ; $ newInstance = $ this -> callbackFactory ( $ id , $ slot , $ factory ) ; return $ newInstance ; } | Create new instance bt stored factory but not save the instance inside container |
753 | public function extend ( $ id , callable $ extender ) : Slot { if ( ! isset ( $ this -> registered [ $ id ] ) ) { throw new ComponentNotFoundException ( $ id ) ; } $ slot = $ this -> slot ( $ id ) ; if ( $ slot -> isLocked ( ) ) { throw new SlotIsLockedException ( $ id , $ extender ) ; } $ factory = $ this -> factories [ $ id ] ; if ( ! $ factory || ! is_callable ( $ factory ) || ! method_exists ( $ factory , '__invoke' ) ) { throw new FactoryNotFoundException ( $ id ) ; } $ this -> factories [ $ id ] = function ( $ container ) use ( $ extender , $ factory , $ id , $ slot ) { $ newInstance = $ this -> callbackFactory ( $ id , $ slot , $ factory ) ; $ extender ( $ newInstance , $ container ) ; return $ newInstance ; } ; return $ slot ; } | Extend factory callback for custumization |
754 | private function replaceInstance ( $ id , $ slot , $ replace ) { if ( $ slot ) { if ( ! $ slot -> checkTypeRestriction ( $ replace ) ) { throw new SlotTypeRestrictionViolationException ( $ id , $ replace , $ slot -> getType ( ) ) ; } if ( ! $ slot -> checkInstanceOfRestriction ( $ replace ) ) { throw new SlotInstanceOfRestrictionViolationException ( $ id , $ replace , $ slot -> getInstanceOf ( ) ) ; } } $ this -> instances [ $ id ] = $ replace ; } | Replace with another instance |
755 | public function errorToException ( $ level = 0 , $ message = '' , $ file = null , $ line = 0 , $ context = array ( ) ) { $ deprecated = false ; switch ( $ level ) { case E_DEPRECATED : case E_USER_DEPRECATED : $ deprecated = true ; $ errors = "Deprecated" ; break ; case E_NOTICE : case E_USER_NOTICE : $ errors = "Notice" ; break ; case E_WARNING : case E_USER_WARNING : $ errors = "Warning" ; break ; case E_ERROR : case E_USER_ERROR : $ errors = "Fatal Error" ; break ; default : $ errors = "Unknown Error" ; break ; } if ( $ this -> debug ) { error_log ( sprintf ( "PHP %s: %s in %s on line %d" , $ errors , $ message , $ file , $ line ) ) ; } if ( $ this -> logDeprecated || ! $ deprecated ) { return $ this -> onAnyException ( new \ ErrorException ( $ message , 1 , $ level , $ file , $ line ) ) ; } else { } } | Raise error on any php error found . |
756 | public function onAnyException ( \ Exception $ exception ) { $ exception = FlattenException :: create ( $ exception ) ; return $ this -> logException ( $ exception , new Request ( ) ) ; } | Use to log any controlled exception . |
757 | public function onKernelException ( GetResponseForExceptionEvent $ event ) { if ( HttpKernel :: MASTER_REQUEST != $ event -> getRequestType ( ) ) { return ; } $ exception = FlattenException :: create ( $ event -> getException ( ) ) ; $ request = $ event -> getRequest ( ) ; return $ this -> logException ( $ exception , $ request ) ; } | Executed on kernel event exception . |
758 | private function transformRequest ( Request $ request ) { $ method = $ request -> getMethod ( ) ; $ url = ( string ) $ request -> getUrl ( ) ; $ transformed = $ this -> browser -> getMessageFactory ( ) -> createRequest ( $ method , $ url ) ; $ transformed -> setProtocolVersion ( $ request -> getProtocolVersion ( ) ) ; $ transformed -> setHeaders ( $ request -> getHeaders ( ) ) ; if ( $ body = $ request -> getBody ( ) ) { $ transformed -> setContent ( ( string ) $ body ) ; } return $ transformed ; } | Creates a Buzz Request |
759 | public function handleError ( ) { if ( ! $ this -> shutdownHandlerActive ) { return ; } $ error = error_get_last ( ) ; if ( $ error [ 'type' ] === E_ERROR ) { $ message = sprintf ( 'Error: "%s" in %s on %s' , $ error [ 'message' ] , $ error [ 'file' ] , $ error [ 'line' ] ) ; $ this -> task -> markError ( ) ; $ this -> task -> addOutput ( $ message ) ; $ this -> logger -> error ( $ message ) ; } $ this -> releaseLock ( ) ; } | Called upon PHP shutdown . |
760 | private function acquireLock ( ) { $ this -> logger -> info ( 'Acquire lock file.' ) ; if ( ! $ this -> lock -> lock ( ) ) { $ locked = false ; $ retry = 3 ; while ( $ retry > 0 ) { usleep ( 1000 ) ; if ( $ locked = $ this -> lock -> lock ( ) ) { break ; } $ retry -- ; } if ( ! $ locked ) { $ this -> logger -> error ( 'Could not acquire lock file.' ) ; throw new \ RuntimeException ( 'Another task appears to be running. If this is not the case, please remove the lock file.' ) ; } } } | Acquire the lock . |
761 | public function create ( $ options = array ( ) ) { $ clazz = $ this -> structure -> name ; $ instance = new $ clazz ( ) ; return $ this -> fill ( $ instance , $ options ) ; } | Create new entity with data given This will first invoke the validator then parse and fill in a new entity . |
762 | protected function _skipDottedIfSo ( ) { $ _f = $ this -> getBasename ( ) ; if ( $ this -> valid ( ) && ! empty ( $ _f ) && ( $ this -> getFlags ( ) & WebFilesystemIterator :: SKIP_DOTTED ) && $ _f { 0 } === '.' ) { $ this -> next ( ) ; } } | Make the iterator skip files beginning with a dot |
763 | public function locate ( $ path ) { $ repository = $ this -> getRepository ( ) ; if ( ! $ repository -> contains ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Their is no path %s in repository.' , $ path ) ) ; } $ resource = $ repository -> get ( $ path ) ; if ( ! ( $ resource instanceof FilesystemResource ) ) { throw new \ RuntimeException ( [ 'Expect %s! %s given' , FilesystemResource :: class , get_class ( $ resource ) ] ) ; } return $ resource ; } | Locate config files from path . |
764 | public function maxRole ( ) { $ roles = $ this -> roles ; $ r = $ roles -> first ( ) ; foreach ( $ roles as $ role ) { if ( $ role -> order > $ r -> order ) $ r = $ role ; } return $ r ; } | return the most supurior role for a user |
765 | public function getRolesFor ( User $ user ) { $ userRoles = $ user -> roles ( ) -> get ( ) ; $ roles = Role :: where ( 'order' , '<=' , $ this -> maxRole ( ) -> order ) ; foreach ( $ userRoles as $ role ) { $ roles = $ roles -> where ( 'name' , '!=' , $ role -> name ) ; } return $ roles -> get ( ) ; } | return all available role for this user |
766 | public function hasPermission ( $ permission ) { foreach ( $ this -> roles as $ role ) { if ( $ role -> hasPermission ( $ permission ) ) return true ; } return false ; } | check if user has permission |
767 | public function add ( $ name , $ value ) { $ name = $ this -> normalizeName ( $ name ) ; $ newValues = is_array ( $ value ) ? $ value : [ $ value ] ; $ data = [ ] ; if ( isset ( $ this -> data [ $ name ] ) ) { $ data = $ this -> data [ $ name ] ; } $ this -> data [ $ name ] = array_merge ( $ data , $ newValues ) ; } | Add header value If the header already exists data are merged method DOES NOT replace previous value . |
768 | public function set ( $ name , $ value ) { $ name = $ this -> normalizeName ( $ name ) ; $ newValues = is_array ( $ value ) ? $ value : [ $ value ] ; $ this -> data [ $ name ] = $ newValues ; } | Set header value If the header already exist value will be replaced . |
769 | public function get ( $ name ) { $ name = $ this -> normalizeName ( $ name ) ; $ data = [ ] ; if ( isset ( $ this -> data [ $ name ] ) ) { $ data = $ this -> data [ $ name ] ; } return $ data ; } | Get header by provided name |
770 | public function remove ( $ name ) { $ name = $ this -> normalizeName ( $ name ) ; if ( isset ( $ this -> data [ $ name ] ) ) { unset ( $ this -> data [ $ name ] ) ; } return $ this ; } | Remove header by provided name |
771 | private function normalizeHeaders ( $ headers ) { $ normalized = [ ] ; foreach ( $ headers as $ name => $ value ) { $ name = $ this -> normalizeName ( $ name ) ; $ normalized [ $ name ] = $ this -> normalizeData ( $ name , $ value ) ; } return $ normalized ; } | Normalize headers values |
772 | private function normalizeData ( $ name , $ data ) { if ( ! isset ( $ this -> ignoreProcessing [ $ name ] ) ) { return array_map ( 'trim' , explode ( ',' , $ data ) ) ; } else { return [ $ data ] ; } } | Normalize header value |
773 | public function overwrite ( $ key , $ value ) { list ( $ baseKey , $ searchKey ) = $ this -> fetchKey ( $ key ) ; $ registry = $ this -> get ( $ baseKey ) ; if ( $ registry === null ) { $ registry = $ this -> cache -> get ( $ baseKey ) ; } if ( is_null ( $ registry ) ) { throw new Exception ( "Item [$key] does not exists" ) ; } if ( $ baseKey != $ searchKey ) { array_set ( $ registry , $ searchKey , $ value ) ; $ this -> database -> table ( $ this -> config [ 'table' ] ) -> where ( 'key' , '=' , $ baseKey ) -> update ( array ( 'value' => json_encode ( $ registry ) ) ) ; $ this -> cache -> add ( $ baseKey , $ registry ) ; } else { $ this -> database -> table ( $ this -> config [ 'table' ] ) -> where ( 'key' , '=' , $ baseKey ) -> update ( array ( 'value' => json_encode ( $ value ) ) ) ; $ this -> cache -> add ( $ baseKey , $ value ) ; } return true ; } | Overwrite existing value from registry |
774 | public function store ( array $ values ) { foreach ( $ values as $ key => $ value ) { $ value = $ this -> forceTypes ( $ value ) ; $ jsonValue = json_encode ( $ value ) ; $ this -> database -> statement ( "INSERT INTO system_registries ( `key`, `value` ) VALUES ( ?, ? )
ON DUPLICATE KEY UPDATE `key` = ?, `value` = ?" , array ( $ key , $ jsonValue , $ key , $ jsonValue ) ) ; $ this -> cache -> add ( $ key , $ value ) ; } return true ; } | Store an array |
775 | public function forget ( $ key ) { list ( $ baseKey , $ searchKey ) = $ this -> fetchKey ( $ key ) ; $ registry = $ this -> get ( $ baseKey ) ; if ( $ registry === null ) { $ registry = $ this -> cache -> get ( $ baseKey ) ; } if ( is_null ( $ registry ) ) { throw new Exception ( "Item [$key] does not exists" ) ; } if ( $ baseKey !== $ searchKey ) { array_forget ( $ registry , $ searchKey ) ; $ this -> database -> table ( $ this -> config [ 'table' ] ) -> where ( 'key' , '=' , $ baseKey ) -> update ( array ( 'value' => json_encode ( $ registry ) ) ) ; $ this -> cache -> add ( $ baseKey , $ registry ) ; } else { $ this -> database -> table ( $ this -> config [ 'table' ] ) -> where ( 'key' , '=' , $ baseKey ) -> delete ( ) ; $ this -> cache -> remove ( $ baseKey ) ; } return true ; } | Remove existing value from registry |
776 | public function getPackageName ( ) : string { $ this -> findPackage ( ) ; if ( ! isset ( $ this -> package -> name ) ) { return '' ; } return $ this -> package -> name ; } | Get the name of the package in which the exception was created . |
777 | public function isLibrary ( ) : bool { $ this -> findPackage ( ) ; if ( ! isset ( $ this -> package -> type ) || $ this -> package -> type !== 'wpzapp-lib' ) { return false ; } return true ; } | Check whether the exception was created in a WP - ZAPP library . |
778 | protected function findPackage ( ) { if ( $ this -> package !== null ) { return ; } $ file = $ this -> getFile ( ) ; $ parts = explode ( DIRECTORY_SEPARATOR , $ file ) ; $ key = array_search ( 'src' , array_reverse ( $ parts , true ) , true ) ; if ( $ key === false ) { $ this -> package = new \ stdClass ( ) ; return ; } $ composerFile = implode ( DIRECTORY_SEPARATOR , array_slice ( $ parts , 0 , $ key ) ) . DIRECTORY_SEPARATOR . 'composer.json' ; if ( ! file_exists ( $ composerFile ) ) { $ this -> package = new \ stdClass ( ) ; return ; } $ composerContent = file_get_contents ( $ composerFile ) ; if ( $ composerContent === false ) { $ this -> package = new \ stdClass ( ) ; return ; } $ this -> package = json_decode ( $ composerContent ) ; if ( $ this -> package === null ) { $ this -> package = new \ stdClass ( ) ; } } | Find the composer file for the package in which the exception was created . |
779 | function layout ( $ options = [ ] ) { $ renderPipeline = $ this -> application [ 'spark.render_pipeline' ] ; if ( $ options === false ) { $ renderPipeline -> renderLayout = false ; return ; } if ( ! is_array ( $ options ) ) { $ options = [ 'script' => ( string ) $ options ] ; } if ( isset ( $ options [ 'script' ] ) ) { $ renderPipeline -> layout -> script = $ options [ 'script' ] ; } return $ this ; } | Set layout options |
780 | public function all ( $ columns = [ '*' ] ) { if ( ! empty ( $ this -> defaultOrderColumn ) ) { return $ this -> model -> orderBy ( $ this -> defaultOrderColumn , $ this -> defaultOrderDirection ) -> get ( $ columns ) ; } return $ this -> model -> get ( $ columns ) ; } | Retorna todos os registros deste Model . |
781 | public function paginate ( $ perPage = 15 , $ columns = [ '*' ] , $ sort = '' , $ order = 'asc' ) { $ m = $ this -> model ; if ( $ sort ) { $ m -> orderBy ( $ sort , $ order ) ; } else { if ( $ this -> defaultOrderColumn ) { $ m -> orderBy ( $ this -> defaultOrderColumn , $ order ) ; } } return $ m -> paginate ( $ perPage , $ columns ) ; } | Retorna resultados paginados . |
782 | function save ( $ filepath = '' ) { $ ret = $ this -> root -> innertext ( ) ; if ( $ filepath !== '' ) file_put_contents ( $ filepath , $ ret ) ; return $ ret ; } | save dom as string |
783 | public function renderImages ( ) { foreach ( $ this -> getVariables ( ) as $ key => $ variable ) { if ( is_file ( $ variable ) ) { $ type = pathinfo ( $ variable , PATHINFO_EXTENSION ) ; $ data = file_get_contents ( $ variable ) ; $ base64 = 'data:image/' . $ type . ';base64,' . base64_encode ( $ data ) ; $ this -> setVariable ( $ key , $ base64 ) ; } } } | Renders images into inline image using base64 encoding |
784 | public function setUnsubscribeLink ( ) { $ urlHelper = $ this -> getUrlHelper ( ) ; $ url = $ this -> getVariable ( 'server_url' ) . $ urlHelper ( 'newsletter' ) ; $ this -> setVariable ( 'unsubscribe' , $ url ) ; } | Set the unsubscribe link |
785 | public function transform ( $ users ) { if ( null == $ users ) { return "" ; } $ texts = [ ] ; foreach ( $ users as $ user ) { $ texts [ ] = $ user -> getUsername ( ) ; } return $ texts ; } | Transforms object to a string . |
786 | public static function createArray ( $ inputXml , $ version = '1.0' , $ encoding = 'UTF-8' , $ formatOutput = true ) { $ class = new self ( $ version , $ encoding , $ formatOutput ) ; $ xml = $ class -> xml ; if ( is_string ( $ inputXml ) ) { $ parsed = $ xml -> loadXML ( $ inputXml ) ; if ( ! $ parsed ) { throw new \ Exception ( '[XML2Array] Error parsing the XML string.' ) ; } } else { if ( get_class ( $ inputXml ) !== 'DOMDocument' ) { throw new \ Exception ( '[XML2Array] The input XML object should be of type: DOMDocument.' ) ; } $ xml = $ class -> xml = $ inputXml ; } $ array = [ ] ; $ array [ $ xml -> documentElement -> tagName ] = $ class -> convert ( $ xml -> documentElement ) ; return $ array ; } | This method converts an XML to and Array . |
787 | public function add ( string $ email , string $ name = null ) : void { $ replyToRecipient = $ this -> make ( ) ; $ replyToRecipient -> email = $ email ; if ( $ name !== null ) { $ replyToRecipient -> name = $ name ; } $ this -> set ( $ replyToRecipient ) ; } | Add a reply to recipient . |
788 | public function dumpObject ( ) { $ date = $ this -> age -> format ( 'Y-m-d' ) ; $ string = "Engine: $this->engine \n" ; $ string .= "Keyword: $this->keyword \n" ; $ string .= "PageUrl: $this->pageUrl \n" ; $ string .= "PageNumber: $this->pageNumber \n" ; $ string .= "Date: $date \n" ; $ string .= "Entries: \n" ; for ( $ i = 0 ; $ i < count ( $ this -> entries ) ; $ i ++ ) { $ url = $ this -> entries [ $ i ] [ 'url' ] ; $ title = $ this -> entries [ $ i ] [ 'title' ] ; $ snippet = $ this -> entries [ $ i ] [ 'snippet' ] ; $ pos = $ i + 1 ; $ string .= " $pos: \n" ; $ string .= " Url: $url\n" ; $ string .= " Title: $title\n" ; $ string .= " Snippet: $snippet\n" ; } return $ string ; } | Dump object data . |
789 | public function render ( $ options = array ( ) ) { $ alert = $ this -> alertManager -> getAlert ( ) ; $ options [ 'alerts' ] = $ alert ? $ alert -> all ( ) : array ( ) ; return $ this -> alertHelper -> render ( $ options , $ this -> getTemplate ( $ options ) ) ; } | Render alerts template . |
790 | public function renderFlash ( $ options = array ( ) ) { $ options [ 'alerts' ] = $ this -> alertManager -> getFlashAlerts ( ) ; if ( empty ( $ options [ 'alerts' ] ) ) { return '' ; } return $ this -> alertHelper -> render ( $ options , $ this -> getTemplate ( $ options ) ) ; } | Render flash alerts template . |
791 | public function chunk ( $ length ) { if ( $ length <= 0 ) { return $ this ; } $ chunks = [ ] ; foreach ( array_chunk ( $ this -> items , $ length , true ) as $ chunk ) { $ chunks [ ] = new static ( $ chunk ) ; } return new static ( $ chunks ) ; } | chunk the items |
792 | public function toArray ( ) { $ newItem = [ ] ; foreach ( $ this -> items as $ key => $ val ) { if ( $ val instanceof ArrayInterface ) { $ newItem [ $ key ] = $ val -> items ; } else { $ newItem [ $ key ] = $ val ; } } return $ newItem ; } | convert the items to arrays |
793 | public function firstWhere ( $ keyWhere , $ valueWhere ) { foreach ( $ this -> items as $ key => $ item ) { if ( $ keyWhere === $ key && $ valueWhere === $ item ) { return $ item ; } } return null ; } | get firse value of the items by where |
794 | public function forget ( $ key ) { if ( is_string ( $ key ) ) { $ this -> unsetVal ( $ key ) ; } else { foreach ( $ this -> items as $ keys => $ value ) { if ( $ key === $ keys ) { $ this -> unsetVal ( $ key ) ; } } } return $ this ; } | forget a item of the items |
795 | public function merge ( $ items ) { if ( $ items instanceof ArrayInterface ) { $ this -> items = array_merge ( $ this -> items , $ items -> all ( ) ) ; } else { $ this -> items = array_merge ( $ this -> items , $ items ) ; } return $ this ; } | merge data to a collection data |
796 | public function reject ( $ value , $ mode = 1 ) { if ( ! in_array ( $ mode , $ this -> fiterMode ) ) { throw new \ UnexpectedValueException ( "Mode must is 1 or 2" ) ; } $ this -> items = array_filter ( $ this -> items , function ( $ item ) use ( $ value , $ mode ) { return $ item !== $ value ; } , $ mode ) ; return $ this ; } | reject the item in items |
797 | public function accept ( $ value , $ mode = 1 ) { $ this -> items = array_filter ( $ this -> items , function ( $ item ) use ( $ value , $ mode ) { return $ item === $ value ; } , $ mode ) ; return $ this ; } | accept the item in items |
798 | public function beforeDelete ( Delete $ event ) { $ parent = $ event -> getEntity ( ) -> { $ this -> propertyName } ; if ( $ parent instanceof EntityInterface ) { $ parent -> delete ( ) ; } } | Deletes the related entity for before deleting current entity |
799 | public function getUrlFromPathWithValues ( array $ values = [ ] ) { $ url = $ this -> path ; preg_match_all ( '@{([a-zA-Z0-9_]*)}@' , $ url , $ matches ) ; if ( $ matches ) { foreach ( $ matches [ 1 ] as $ k => $ optional ) { $ url = str_ireplace ( $ matches [ 0 ] [ $ k ] , isset ( $ values [ $ optional ] ) ? $ values [ $ optional ] : null , $ url ) ; } } preg_match ( '@{/([a-zA-Z0-9_]*)}@' , $ url , $ expandables ) ; if ( $ expandables ) { $ list = explode ( ',' , $ expandables [ 1 ] ) ; $ head = '' ; if ( substr ( $ url , 0 , 2 ) == '{/' ) { $ name = array_shift ( $ list ) ; if ( isset ( $ values [ $ name ] ) ) { $ head = "/{$values[$name]}" ; } } $ tail = '' ; foreach ( $ list as $ name ) { if ( isset ( $ values [ $ name ] ) ) { $ head = "/{$values[$name]}" ; } } $ url = str_replace ( $ expandables [ 0 ] , $ head . $ tail , $ url ) ; } return $ url ; } | Generates a FQURL from the route path with the passed values |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.