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 ( '/' , $ ...
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_matc...
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 [ "REQ...
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_reve...
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 ) ; } retur...
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 -> compileEc...
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->ma...
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 -> ...
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 [ $...
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 (...
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 ; } } ret...
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 ) { retur...
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 [ $ ...
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...
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 ] ; } }...
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 , "...
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 ) { $ r...
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 $...
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 -> invalidateExistingToken...
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' ...
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...
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 -> A...
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 -> ema...
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...
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 ( ) && ! $ t...
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 [ 'lastEventI...
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 -> getA...
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 ( $ modul...
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 : $ at...
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 FactoryNotFoundExcept...
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...
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 SlotInstanceOf...
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 = "Notic...
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 , ...
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 ( ) ) ; ...
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 ->...
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 ( ...
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 FilesystemRe...
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 exis...
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` = ?, `val...
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 ...
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 ; ...
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' ] ) ) {...
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 ( $ perP...
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 -> set...
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 \ ...
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 ( ...
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 $ ...
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 ...
Generates a FQURL from the route path with the passed values