idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
15,300
|
public static function isValidRelative ( string $ url , UrlInterface $ baseUrl ) : bool { try { return self :: myParse ( $ baseUrl , $ url ) ; } catch ( UrlPathLogicException $ exception ) { return false ; } }
|
Checks if a relative url is valid .
|
15,301
|
private static function myParse ( ? UrlInterface $ baseUrl = null , string $ url , ? SchemeInterface & $ scheme = null , ? HostInterface & $ host = null , ? int & $ port = null , ? UrlPathInterface & $ path = null , ? string & $ queryString = null , ? string & $ fragment = null , ? string & $ error = null ) : bool { if ( $ baseUrl === null && $ url === '' ) { $ error = 'Url "" is empty.' ; return false ; } self :: mySplit ( $ url , $ schemeString , $ authorityString , $ pathString ) ; if ( ! self :: myParseScheme ( $ baseUrl , $ schemeString , $ scheme , $ error ) ) { $ error = 'Url "' . $ url . '" is invalid: ' . $ error ; return false ; } if ( ! self :: myParseAuthority ( $ baseUrl , $ authorityString , $ host , $ port , $ error ) ) { $ error = 'Url "' . $ url . '" is invalid: ' . $ error ; return false ; } if ( $ port === null ) { $ port = $ scheme -> getDefaultPort ( ) ; } if ( ! self :: myParsePath ( $ baseUrl , $ pathString , $ path , $ queryString , $ fragment , $ error ) ) { $ error = 'Url "' . $ url . '" is invalid: ' . $ error ; return false ; } return true ; }
|
Tries to parse a url and returns the result or error text .
|
15,302
|
private static function mySplit ( string $ url , ? string & $ schemeString = null , ? string & $ authorityString = null , ? string & $ pathString = null ) : void { $ schemeString = null ; $ authorityString = null ; $ pathString = null ; $ parts = explode ( '://' , $ url , 2 ) ; if ( count ( $ parts ) === 2 ) { $ schemeString = $ parts [ 0 ] ; $ parts = explode ( '/' , $ parts [ 1 ] , 2 ) ; $ authorityString = $ parts [ 0 ] ; $ pathString = '/' . ( count ( $ parts ) === 2 ? $ parts [ 1 ] : '' ) ; return ; } if ( substr ( $ url , 0 , 2 ) === '//' ) { $ parts = explode ( '/' , substr ( $ url , 2 ) , 2 ) ; $ authorityString = $ parts [ 0 ] ; $ pathString = '/' . ( count ( $ parts ) === 2 ? $ parts [ 1 ] : '' ) ; return ; } $ pathString = $ url ; }
|
Splits a url in its main components .
|
15,303
|
private static function myParseScheme ( ? UrlInterface $ baseUrl = null , ? string $ schemeString , ? SchemeInterface & $ scheme = null , ? string & $ error = null ) : bool { if ( $ schemeString === null ) { if ( $ baseUrl === null ) { $ error = 'Scheme is missing.' ; return false ; } $ scheme = $ baseUrl -> getScheme ( ) ; return true ; } try { $ scheme = Scheme :: parse ( $ schemeString ) ; } catch ( SchemeInvalidArgumentException $ e ) { $ error = $ e -> getMessage ( ) ; return false ; } return true ; }
|
Parse scheme .
|
15,304
|
private static function myParseAuthority ( ? UrlInterface $ baseUrl = null , ? string $ authorityString , ? HostInterface & $ host = null , ? int & $ port = null , ? string & $ error = null ) : bool { if ( $ authorityString === null && $ baseUrl !== null ) { $ host = $ baseUrl -> getHost ( ) ; $ port = $ baseUrl -> getPort ( ) ; return true ; } $ parts = explode ( '@' , $ authorityString , 2 ) ; if ( count ( $ parts ) > 1 ) { $ authorityString = $ parts [ 1 ] ; } $ parts = explode ( ':' , $ authorityString , 2 ) ; $ port = null ; if ( count ( $ parts ) === 2 && $ parts [ 1 ] !== '' ) { if ( preg_match ( '/[^0-9]/' , $ parts [ 1 ] , $ matches ) ) { $ error = 'Port "' . $ parts [ 1 ] . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } $ port = intval ( $ parts [ 1 ] ) ; if ( ! self :: myValidatePort ( $ port , $ error ) ) { return false ; } } try { $ host = Host :: parse ( $ parts [ 0 ] ) ; } catch ( HostInvalidArgumentException $ e ) { $ error = $ e -> getMessage ( ) ; return false ; } return true ; }
|
Parse authority part .
|
15,305
|
private static function myParsePath ( ? UrlInterface $ baseUrl = null , string $ pathString , ? UrlPathInterface & $ path = null , ? string & $ queryString = null , ? string & $ fragment = null , ? string & $ error = null ) : bool { $ parts = explode ( '#' , $ pathString , 2 ) ; $ pathString = $ parts [ 0 ] ; $ fragment = count ( $ parts ) > 1 ? $ parts [ 1 ] : null ; if ( ! self :: myValidateFragment ( $ fragment , $ error ) ) { return false ; } $ parts = explode ( '?' , $ pathString , 2 ) ; $ pathString = $ parts [ 0 ] ; $ queryString = count ( $ parts ) > 1 ? $ parts [ 1 ] : null ; if ( ! self :: myValidateQueryString ( $ queryString , $ error ) ) { return false ; } if ( ! self :: myParseUrlPath ( $ baseUrl , $ pathString , $ path , $ error ) ) { return false ; } if ( $ pathString === '' && $ baseUrl !== null && $ queryString === null ) { $ queryString = $ baseUrl -> getQueryString ( ) ; $ fragment = $ fragment ? : $ baseUrl -> getFragment ( ) ; } return true ; }
|
Parse path .
|
15,306
|
private static function myParseUrlPath ( ? UrlInterface $ baseUrl = null , string $ pathString , ? UrlPathInterface & $ path = null , ? string & $ error = null ) : bool { if ( $ baseUrl !== null && $ pathString === '' ) { $ path = $ baseUrl -> getPath ( ) ; return true ; } try { $ path = UrlPath :: parse ( $ pathString ) ; } catch ( UrlPathInvalidArgumentException $ e ) { $ error = $ e -> getMessage ( ) ; return false ; } if ( $ baseUrl !== null ) { $ path = $ baseUrl -> getPath ( ) -> withUrlPath ( $ path ) ; } return true ; }
|
Try to validate or parse path .
|
15,307
|
private static function myValidateParts ( int $ port , UrlPathInterface $ urlPath , ? string $ queryString , ? string $ fragment , ? string & $ error ) : bool { if ( ! self :: myValidatePort ( $ port , $ error ) ) { return false ; } if ( $ urlPath -> isRelative ( ) ) { $ error = 'Url path "' . $ urlPath . '" is relative.' ; return false ; } if ( ! self :: myValidateQueryString ( $ queryString , $ error ) ) { return false ; } if ( ! self :: myValidateFragment ( $ fragment , $ error ) ) { return false ; } return true ; }
|
Validates parts of url .
|
15,308
|
private static function myValidatePort ( int $ port , ? string & $ error ) : bool { if ( $ port < 0 ) { $ error = 'Port ' . $ port . ' is out of range: Minimum port number is 0.' ; return false ; } if ( $ port > 65535 ) { $ error = 'Port ' . $ port . ' is out of range: Maximum port number is 65535.' ; return false ; } return true ; }
|
Validates a port .
|
15,309
|
private static function myValidateQueryString ( ? string $ queryString , ? string & $ error ) : bool { if ( $ queryString === null ) { return true ; } if ( preg_match ( '/[^0-9a-zA-Z._~!\$&\'()*\+,;=:@\[\]\/\?%-]/' , $ queryString , $ matches ) ) { $ error = 'Query string "' . $ queryString . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } return true ; }
|
Validates a query string .
|
15,310
|
private static function myValidateFragment ( ? string $ fragment , ? string & $ error ) : bool { if ( $ fragment === null ) { return true ; } if ( preg_match ( '/[^0-9a-zA-Z._~!\$&\'()*\+,;=:@\[\]\/\?%-]/' , $ fragment , $ matches ) ) { $ error = 'Fragment "' . $ fragment . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } return true ; }
|
Validates a fragment .
|
15,311
|
public function setDisabled ( $ disabled ) { $ this -> disabled = ( bool ) $ disabled ; if ( $ this -> disabled ) { $ this -> attributes = $ this -> attributes -> reject ( function ( $ value , $ key ) { return Str :: startsWith ( $ key , [ 'data-' ] ) ; } ) ; } return $ this ; }
|
Set disabled state .
|
15,312
|
protected function renderValue ( ) { if ( $ this -> withTooltip || ! $ this -> withTitle ) return $ this -> renderIcon ( ) ; return $ this -> withIcon ? $ this -> renderIcon ( ) . ' ' . $ this -> getTitle ( ) : $ this -> getTitle ( ) ; }
|
Render the value .
|
15,313
|
protected function getStyleClass ( ) { $ classes = array_merge ( [ $ this -> getBaseStyleClass ( ) , $ this -> getSize ( ) , $ this -> getColor ( ) , ] , $ this -> extraClass ) ; return implode ( ' ' , array_filter ( array_unique ( $ classes , SORT_STRING ) ) ) ; }
|
Get the button class .
|
15,314
|
public static function check ( ) { $ route = isset ( $ _GET [ '_framework_url_' ] ) ? $ _GET [ '_framework_url_' ] : '' ; $ out = config ( 'maintenance.out' , [ ] ) ; $ out [ ] = config ( 'panel.route' , 'vinala' ) ; if ( config ( 'panel.setup' , true ) ) { if ( config ( 'maintenance.enabled' , false ) && ! in_array ( $ route , $ out ) ) { return static :: $ enabled = true ; } } return static :: $ enabled = false ; }
|
Check if the app is under maintenance .
|
15,315
|
public static function launch ( ) { if ( static :: check ( ) ) { clean ( ) ; $ view = config ( 'maintenance.view' ) ; $ view = str_replace ( '.' , '/' , $ view ) . '.php' ; $ view = '../resources/views/' . $ view ; if ( ! file_exists ( $ view ) ) { throw new \ Exception ( 'The view \'' . config ( 'maintenance.view' ) . '\' not found' ) ; } include $ view ; out ( '' ) ; } }
|
Launch maintenance view .
|
15,316
|
public static function create ( int $ hour , int $ minute , int $ second ) : Time { return new static ( $ hour , $ minute , $ second ) ; }
|
Creates instance from time values
|
15,317
|
public static function now ( ? string $ timezone = null ) : Time { $ timezone = $ timezone ? : date_default_timezone_get ( ) ; assert ( Validate :: isTimezone ( $ timezone ) , sprintf ( 'Invalid timezone: %s' , $ timezone ) ) ; $ dateTime = new DateTimeImmutable ( 'now' , new DateTimeZone ( $ timezone ) ) ; $ hour = ( int ) $ dateTime -> format ( 'G' ) ; $ minute = ( int ) $ dateTime -> format ( 'i' ) ; $ second = ( int ) $ dateTime -> format ( 's' ) ; return new static ( $ hour , $ minute , $ second ) ; }
|
Creates instance for the current time
|
15,318
|
public static function fromNative ( DateTimeInterface $ dateTime ) : Time { $ hour = ( int ) $ dateTime -> format ( 'G' ) ; $ minute = ( int ) $ dateTime -> format ( 'i' ) ; $ second = ( int ) $ dateTime -> format ( 's' ) ; return new static ( $ hour , $ minute , $ second ) ; }
|
Creates an instance from a native DateTime
|
15,319
|
protected function guardTime ( int $ hour , int $ minute , int $ second ) : void { if ( $ hour < static :: MIN_HOUR || $ hour > static :: MAX_HOUR ) { $ message = sprintf ( 'Hour (%d) out of range[%d, %d]' , $ hour , static :: MIN_HOUR , static :: MAX_HOUR ) ; throw new DomainException ( $ message ) ; } if ( $ minute < static :: MIN_MINUTE || $ minute > static :: MAX_MINUTE ) { $ message = sprintf ( 'Minute (%d) out of range[%d, %d]' , $ minute , static :: MIN_MINUTE , static :: MAX_MINUTE ) ; throw new DomainException ( $ message ) ; } if ( $ second < static :: MIN_SECOND || $ second > static :: MAX_SECOND ) { $ message = sprintf ( 'Second (%d) out of range[%d, %d]' , $ second , static :: MIN_SECOND , static :: MAX_SECOND ) ; throw new DomainException ( $ message ) ; } }
|
Validates the time
|
15,320
|
public function mock ( string $ class ) : MockedCode { $ generator = new MockCodeGenerator ( $ this -> vfsRoot ) ; try { $ rc = new \ ReflectionClass ( $ class ) ; return $ generator -> generate ( $ rc ) ; } catch ( \ ReflectionException $ e ) { throw new DecoyException ( 'Class not found: ' . $ class , $ e ) ; } catch ( MockCodeGeneratorException $ e ) { throw new DecoyException ( 'Failed to generate mock code for class: ' . $ class , $ e ) ; } }
|
Generate mock class
|
15,321
|
public function sendDigestMail ( UserInterface $ user , array $ messages ) { $ template = $ this -> parameters [ 'digest' ] [ 'template' ] ; $ from = $ this -> parameters [ 'digest' ] [ 'from' ] ; $ content = $ this -> templating -> render ( $ template , [ 'date' => date ( 'Y-m-d H:i:s' ) , 'messages' => $ messages , ] ) ; return $ this -> sendEmailMessage ( $ content , $ from , $ user -> getEmail ( ) ) ; }
|
Send digest mail .
|
15,322
|
public function getFileContents ( ) : string { if ( ! $ this -> file || $ this -> file === 'Unknown' ) { return '' ; } if ( ! isset ( static :: $ files [ $ this -> file ] ) ) { static :: $ files [ $ this -> file ] = file_get_contents ( $ this -> file ) ; } return static :: $ files [ $ this -> file ] ? : '' ; }
|
Returns the contents of the file assigned to this frame as a string .
|
15,323
|
protected function setData ( array $ data ) : Frame { $ this -> file = $ data [ 'file' ] ?? '' ; $ this -> line = $ data [ 'line' ] ?? 0 ; $ this -> class = $ data [ 'class' ] ?? '' ; $ this -> function = $ data [ 'function' ] ?? '' ; $ this -> type = $ data [ 'type' ] ?? '' ; $ this -> args = $ data [ 'args' ] ?? [ ] ; if ( $ this -> class ) { $ parts = explode ( '\\' , $ this -> class ) ; $ this -> shortClass = array_pop ( $ parts ) ; $ this -> namespace = implode ( '\\' , $ parts ) ; } else { $ this -> shortClass = '' ; $ this -> namespace = '' ; } return $ this ; }
|
Sets the Frame s data .
|
15,324
|
protected function flattenArgs ( array $ args , int $ depth = 0 ) : array { $ result = [ ] ; foreach ( $ args as $ key => $ value ) { if ( is_object ( $ value ) ) { $ result [ $ key ] = [ 'object' , get_class ( $ value ) ] ; } elseif ( is_array ( $ value ) ) { if ( $ depth > $ this -> nestingLimit ) { $ result [ $ key ] = [ 'array' , '*DEEP NESTED ARRAY*' ] ; } else { $ result [ $ key ] = [ 'array' , $ this -> flattenArgs ( $ value , ++ $ depth ) ] ; } } elseif ( null === $ value ) { $ result [ $ key ] = [ 'null' , null ] ; } elseif ( is_bool ( $ value ) ) { $ result [ $ key ] = [ 'boolean' , $ value ] ; } elseif ( is_resource ( $ value ) ) { $ result [ $ key ] = [ 'resource' , get_resource_type ( $ value ) ] ; } elseif ( $ value instanceof \ __PHP_Incomplete_Class ) { $ array = new \ ArrayObject ( $ value ) ; $ result [ $ key ] = [ 'incomplete-object' , $ array [ '__PHP_Incomplete_Class_Name' ] ] ; } else { $ result [ $ key ] = [ 'string' , ( string ) $ value ] ; } } return $ result ; }
|
Flattens the args to make them easier to serialize .
|
15,325
|
public function afterSave ( ) { if ( $ this -> getDI ( ) -> get ( 'config' ) -> useMail ) { if ( $ this -> active == 'N' ) { $ emailConfirmation = new EmailConfirmations ( ) ; $ emailConfirmation -> usersId = $ this -> id ; if ( $ emailConfirmation -> save ( ) ) { $ this -> getDI ( ) -> getFlash ( ) -> notice ( 'A confirmation mail has been sent to ' . $ this -> email ) ; } } } }
|
Send a confirmation e - mail to the user if the account is not active
|
15,326
|
public function getData ( ) { if ( is_null ( $ this -> data ) ) { try { $ this -> data = $ this -> getParser ( ) -> parse ( $ this -> getYmlData ( ) ) ; } catch ( ParseException $ exp ) { throw new RoutesFileParseException ( "Fail to parse routes file: " . $ exp -> getMessage ( ) , 0 , $ exp ) ; } } return $ this -> data ; }
|
Returns parsed data from YML
|
15,327
|
protected function setMapDefaults ( array $ data ) { $ defaults = [ 'tokens' , 'defaults' , 'host' , 'accepts' ] ; foreach ( $ data as $ name => $ value ) { if ( in_array ( $ name , $ defaults ) ) { $ this -> map -> $ name ( $ value ) ; } } }
|
Gets the YML parser data and sets the map default defined
|
15,328
|
public function get_data ( $ path = NULL ) { $ myIndexList = array ( ) ; $ path = $ this -> fix_path ( $ path ) ; if ( is_null ( $ path ) || ( strlen ( $ path ) < 1 ) ) { $ retval = $ this -> data ; } else { $ myIndexList = $ this -> explode_path ( $ path ) ; $ retval = $ this -> get_data_segment ( $ this -> data , $ myIndexList [ 0 ] ) ; unset ( $ myIndexList [ 0 ] ) ; if ( count ( $ myIndexList ) > 0 ) { foreach ( $ myIndexList as $ indexName ) { $ retval = $ this -> get_data_segment ( $ retval , $ indexName ) ; if ( is_null ( $ retval ) ) { break ; } } } } return ( $ retval ) ; }
|
Takes a path & returns the appropriate index in the session .
|
15,329
|
public function set_data ( $ path , $ data ) { if ( is_object ( $ data ) ) { throw new InvalidArgumentException ( "objects are not supported" ) ; } else { $ myIndexList = $ this -> explode_path ( $ path ) ; $ retval = 0 ; if ( $ path === '/' || count ( $ myIndexList ) == 0 ) { $ this -> data = $ data ; $ retval = 1 ; } elseif ( count ( $ myIndexList ) == 1 ) { if ( ! is_array ( $ this -> data ) ) { $ this -> data = array ( ) ; } $ this -> data [ $ myIndexList [ 0 ] ] = $ data ; $ retval = 1 ; } elseif ( count ( $ myIndexList ) > 1 ) { $ this -> internal_iterator ( $ this -> data , $ path , $ data ) ; $ retval = 1 ; } } return ( $ retval ) ; }
|
Sets data into the given path with options to override our internal prefix and to force - overwrite data if it s not an array .
|
15,330
|
public function explode_path ( $ path ) { $ path = preg_replace ( '/\/{2,}/' , '/' , $ path ) ; $ path = $ this -> fix_path ( $ path ) ; $ retval = explode ( '/' , $ path ) ; if ( $ retval [ 0 ] == '' || strlen ( $ retval [ 0 ] ) < 1 ) { $ checkItOut = array_shift ( $ retval ) ; } return ( $ retval ) ; }
|
Performs all the work of exploding the path and fixing it .
|
15,331
|
private function format ( & $ url ) { if ( $ url == '/' ) { $ value = 'project_home' ; $ url = '' ; } else { $ value = $ url ; $ url = '/' . $ url ; } return $ value ; }
|
Format the name and the url of Route .
|
15,332
|
public static function get ( $ url , $ callback ) { $ route = new self ( $ url ) ; $ route -> setClosure ( $ callback ) ; $ route -> setMethod ( 'get' ) ; $ route -> add ( ) ; return $ route ; }
|
To add HTTP get request .
|
15,333
|
public static function view ( $ url , $ view , $ data = null ) { $ callback = function ( ) use ( $ view , $ data ) { $ view = view ( $ view ) ; if ( ! is_null ( $ data ) ) { foreach ( $ data as $ key => $ value ) { $ view = $ view -> with ( $ key , $ value ) ; } } return $ view ; } ; static :: get ( $ url , $ callback ) ; }
|
Show view in route call .
|
15,334
|
public static function post ( $ url , $ callback ) { $ route = new self ( $ url ) ; $ route -> setClosure ( $ callback ) ; $ route -> setMethod ( 'post' ) ; $ route -> add ( ) ; return $ route ; }
|
To add HTTP post request .
|
15,335
|
public static function resource ( $ url , $ controller ) { $ route = new self ( $ url ) ; $ route -> targets = [ 'index' , 'show' , 'insert' , 'add' , 'update' , 'edit' , 'delete' ] ; $ route -> setResourceMethods ( $ url , $ controller ) ; return $ route ; }
|
Call resource route .
|
15,336
|
public static function target ( $ url , $ target ) { $ route = new self ( $ url ) ; $ route -> setMethod ( 'call' ) ; $ segements = explode ( '@' , $ target ) ; exception_if ( count ( $ segements ) != 2 , \ LogicException :: class , 'The method name in targeted route expect two names, the controller and method, ' . count ( $ segements ) . ' given in ' . $ target ) ; $ controller = $ segements [ 0 ] ; $ method = $ segements [ 1 ] ; $ route -> setResource ( $ url , '' , $ controller , $ method ) ; return $ route ; }
|
Call target route .
|
15,337
|
private function setResourceMethods ( $ url , $ controller ) { $ this -> setIndexResource ( $ url , '' , $ controller ) ; $ url = ( $ url == '/' ) ? '' : $ url ; $ this -> setIndexResource ( $ url , '/index' , $ controller ) ; $ this -> setShowResource ( $ url , '/show/{param}' , $ controller ) ; $ this -> setAddResource ( $ url , '/add' , $ controller ) ; $ this -> setInsertResource ( $ url , '/insert' , $ controller ) ; $ this -> setEditResource ( $ url , '/edit/{param}' , $ controller ) ; $ this -> setUpdateResource ( $ url , '/update' , $ controller ) ; $ this -> setUpdateResource ( $ url , '/update/{param}' , $ controller ) ; $ this -> setDeleteResource ( $ url , '/delete/{param}' , $ controller ) ; }
|
Set the methods resource .
|
15,338
|
private function getResourceName ( $ url , $ target ) { switch ( $ target ) { case 'index' : return [ $ url , $ url . '/index' ] ; break ; case 'show' : return [ $ url . '/show/{param}' ] ; break ; case 'add' : return [ $ url . '/add' ] ; break ; case 'insert' : return [ $ url . '/insert' ] ; break ; case 'edit' : return [ $ url . '/edit/{param}' ] ; break ; case 'update' : return [ $ url . '/update' , $ url . '/update/{param}' ] ; break ; case 'update' : return [ $ url . '/delete/{param}' ] ; break ; } }
|
Get the resource name .
|
15,339
|
private function getResourceClosure ( $ controller , $ method ) { if ( $ method == 'show' || $ method == 'edit' || $ method == 'delete' ) { return function ( $ id ) use ( $ controller , $ method ) { return $ controller :: $ method ( $ id ) ; } ; } elseif ( $ method == 'update' ) { return function ( $ request , $ id ) use ( $ controller , $ method ) { return $ controller :: $ method ( $ request , $ id ) ; } ; } elseif ( $ method == 'insert' ) { return function ( $ request ) use ( $ controller , $ method ) { return $ controller :: $ method ( $ request ) ; } ; } else { return function ( ) use ( $ controller , $ method ) { return $ controller :: $ method ( ) ; } ; } }
|
Return a resource closure for resource route .
|
15,340
|
private function setResource ( $ url , $ route , $ controller , $ target ) { $ url = $ url . $ route ; $ route = new self ( $ url ) ; $ closure = $ this -> getResourceClosure ( $ controller , $ target ) ; $ route -> setClosure ( $ closure ) ; $ route -> setMethod ( 'resource' ) ; $ route -> setTarget ( $ controller , $ target ) ; $ this -> addResource ( $ route ) ; $ route -> add ( ) ; return $ route ; }
|
Set a resource routes .
|
15,341
|
public function only ( ) { $ targets = func_get_args ( ) ; $ result = [ ] ; foreach ( $ this -> targets as $ method ) { if ( in_array ( $ method , $ targets ) ) { array_push ( $ result , $ method ) ; } else { if ( ! is_null ( $ this -> getResourceName ( $ this -> name , $ method ) ) ) { foreach ( $ this -> getResourceName ( $ this -> name , $ method ) as $ resource ) { if ( array_has ( $ this -> resources , $ resource ) ) { $ this -> resources [ $ resource ] -> delete ( ) ; unset ( $ this -> resources [ $ resource ] ) ; } } } } } $ this -> targets = $ result ; return $ this ; }
|
Choose the resource methods to work .
|
15,342
|
public function checkSessionByRPC ( $ objParam , & $ nCheckReturn = null ) { if ( ! CLib :: IsObjectWithProperties ( $ objParam , [ UCProConst :: CKX_MID , UCProConst :: CKT_SS_ID , UCProConst :: CKT_SS_URL , 'cookie_array' ] ) ) { return UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_PARAM ; } $ nRet = UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_FAILURE ; $ nCheckReturn = CConst :: ERROR_UNKNOWN ; $ sMId = $ objParam -> { UCProConst :: CKX_MID } ; $ sSessionId = $ objParam -> { UCProConst :: CKT_SS_ID } ; $ sSessionUrl = $ objParam -> { UCProConst :: CKT_SS_URL } ; $ arrCookie = $ objParam -> { 'cookie_array' } ; if ( ! CLib :: IsExistingString ( $ sMId , true ) ) { return UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_PARAM_MID ; } if ( ! CLib :: IsExistingString ( $ sSessionId , true ) ) { return UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_PARAM_SS_ID ; } if ( ! CLib :: IsExistingString ( $ sSessionUrl , true ) ) { return UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_PARAM_SS_URL ; } if ( false === filter_var ( $ sSessionUrl , FILTER_VALIDATE_URL ) ) { return UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_PARAM_SS_URL2 ; } $ nTimeout = 5 ; $ cRequest = CRequest :: GetInstance ( ) ; $ arrResponse = [ ] ; $ nCall = $ cRequest -> Get ( [ 'url' => $ sSessionUrl , 'data' => [ UCProConst :: CKX_MID => $ sMId , UCProConst :: CKT_SS_ID => $ sSessionId , ] , 'version' => '1.0' , 'timeout' => $ nTimeout , 'cookie' => $ arrCookie , ] , $ arrResponse ) ; if ( CConst :: ERROR_SUCCESS == $ nCall ) { if ( CVData :: GetInstance ( ) -> IsValidVData ( $ arrResponse ) ) { $ nRet = UCProError :: SUCCESS ; $ nCheckReturn = $ arrResponse [ 'errorid' ] ; } else { $ nRet = UCProError :: UCPROSESSION_CHECKSESSIONBYRPC_INVALID_VDATA ; } } else { $ nRet = $ nCall ; } return $ nRet ; }
|
check session from remote server
|
15,343
|
public function shareOnCompanyPage ( Activity $ activity , array $ content ) { $ id = $ activity -> getLocation ( ) -> getIdentifier ( ) ; return $ this -> connect -> request ( 'POST' , 'companies/' . $ id . '/shares' , [ 'headers' => [ 'x-li-format' => 'json' , ] , 'body' => json_encode ( $ content ) , 'query' => [ 'format' => 'json' , ] ] ) ; }
|
Share a news on a company page
|
15,344
|
public function getCompanyUpdate ( Activity $ activity , NewsItem $ newsItem ) { $ id = $ activity -> getLocation ( ) -> getIdentifier ( ) ; return $ this -> connect -> request ( 'GET' , 'companies/' . $ id . '/updates/key=' . $ newsItem -> getUpdateKey ( ) , [ 'query' => [ 'format' => 'json' , ] ] ) ; }
|
Get a company update statistics
|
15,345
|
public function getUserUpdate ( Activity $ activity , NewsItem $ newsItem ) { return $ this -> connect -> request ( 'GET' , 'people/~/network/updates/key=' . $ newsItem -> getUpdateKey ( ) , [ 'query' => [ 'format' => 'json' , ] ] ) ; }
|
Get a user update statistics
|
15,346
|
public function addConnection ( string $ name = null , Connection $ connection = null ) : self { if ( is_null ( $ name ) ) { $ this -> defaultConnection = $ connection ; } else { $ this -> registry [ $ name ] = $ connection ; } return $ this ; }
|
Adds a connection
|
15,347
|
public function getConnection ( string $ name = null ) : Connection { if ( is_null ( $ name ) and ! is_null ( $ this -> defaultConnection ) ) { return $ this -> defaultConnection ; } if ( is_null ( $ name ) or ! array_key_exists ( $ name , $ this -> registry ) ) { throw new MongoDBConnectionNameNotFoundException ( $ name ) ; } return $ this -> registry [ $ name ] ; }
|
Gets a connection
|
15,348
|
protected function initializeTokenCharacters ( ) { $ allowed = 'abcdefghijklmnopqrstuvwxyz' ; $ allowed .= strtoupper ( $ allowed ) ; $ allowed .= '0123456789' ; $ this -> tokenChars = str_split ( $ allowed ) ; shuffle ( $ this -> tokenChars ) ; }
|
Initialize the list of characters that are used to create tokens
|
15,349
|
protected function getTokenCharacters ( $ count = 1 ) { $ result = '' ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ result .= $ this -> tokenChars [ mt_rand ( 0 , count ( $ this -> tokenChars ) - 1 ) ] ; } return $ result ; }
|
Get random characters
|
15,350
|
private function getCompleteUrl ( $ uri = '' ) { $ uri = $ uri === '' ? $ this -> urlResolver -> getPath ( ) : $ uri ; $ url = sprintf ( '%s%s' , $ this -> urlResolver -> getDomain ( ) , $ uri ) ; if ( $ this -> isGet ( ) && $ this -> GET ) { $ url = sprintf ( '%s?%s' , $ url , http_build_query ( $ this -> GET -> getAll ( ) ) ) ; } return $ url ; }
|
Get the full url address for the request
|
15,351
|
protected function buildResponse ( ) { $ this -> curl -> persist ( ) ; $ response = $ this -> curl -> exec ( ) ; $ info = $ this -> curl -> getInfo ( ) ; $ errors = [ 'text' => $ this -> curl -> error ( ) , 'code' => $ this -> curl -> errno ( ) ] ; try { return new Response ( new ResponseBuilder ( $ response , $ info , $ errors ) , new Filesystem ( ) ) ; } catch ( ResponseBuilderException $ e ) { throw new RequestException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
|
Construct an instance of the Response based on data received from the server
|
15,352
|
protected function _containerGetPath ( $ container , $ path ) { $ path = $ this -> _normalizeIterable ( $ path ) ; $ service = $ container ; foreach ( $ path as $ segment ) { $ service = $ this -> _containerGet ( $ service , $ segment ) ; } return $ service ; }
|
Retrieves a value from a chain of nested containers by path .
|
15,353
|
public function guessIdentifier ( callable $ fn = null ) { static $ guesser ; static $ table ; if ( isset ( $ table ) ) { return $ table ; } if ( isset ( $ fn ) ) { $ guesser = $ fn ; } if ( ! isset ( $ guesser ) ) { $ guesser = function ( $ class ) { $ class = preg_replace ( '@\\\\?Model$@' , '' , $ class ) ; return Helper :: normalize ( $ class ) ; } ; } $ class = get_class ( $ this ) ; if ( strpos ( $ class , '@anonymous' ) !== false ) { $ class = ( new ReflectionClass ( $ this ) ) -> getParentClass ( ) -> name ; } return $ guesser ( $ class ) ; }
|
Return the guesstimated identifier optionally by using the callback passed as an argument .
|
15,354
|
public function getIpAddress ( ) { foreach ( $ this -> headers as $ k ) { if ( isset ( $ this -> server [ $ k ] ) ) { $ ips = explode ( ',' , $ this -> server [ $ k ] ) ; $ ip = trim ( end ( $ ips ) ) ; $ ip = filter_var ( $ ip , FILTER_VALIDATE_IP ) ; if ( false !== $ ip ) { return $ ip ; } } } return false ; }
|
Returns client s accurate IP Address
|
15,355
|
public function Delete ( $ MessageID = '' , $ TransientKey = FALSE ) { $ this -> Permission ( 'Garden.Messages.Manage' ) ; $ this -> DeliveryType ( DELIVERY_TYPE_BOOL ) ; $ Session = Gdn :: Session ( ) ; if ( $ TransientKey !== FALSE && $ Session -> ValidateTransientKey ( $ TransientKey ) ) { $ Message = $ this -> MessageModel -> Delete ( array ( 'MessageID' => $ MessageID ) ) ; $ this -> MessageModel -> SetMessageCache ( ) ; } if ( $ this -> _DeliveryType === DELIVERY_TYPE_ALL ) Redirect ( 'dashboard/message' ) ; $ this -> Render ( ) ; }
|
Delete a message .
|
15,356
|
public function Edit ( $ MessageID = '' ) { $ this -> AddJsFile ( 'jquery.autogrow.js' ) ; $ this -> AddJsFile ( 'messages.js' ) ; $ this -> Permission ( 'Garden.Messages.Manage' ) ; $ this -> AddSideMenu ( 'dashboard/message' ) ; $ this -> SetData ( 'Locations' , $ this -> _GetLocationData ( ) ) ; $ this -> AssetData = $ this -> _GetAssetData ( ) ; $ this -> Form -> SetModel ( $ this -> MessageModel ) ; $ this -> Message = $ this -> MessageModel -> GetID ( $ MessageID ) ; $ this -> Message = $ this -> MessageModel -> DefineLocation ( $ this -> Message ) ; if ( is_numeric ( $ MessageID ) && $ MessageID > 0 ) $ this -> Form -> AddHidden ( 'MessageID' , $ MessageID ) ; $ CategoriesData = CategoryModel :: Categories ( ) ; $ Categories = array ( ) ; foreach ( $ CategoriesData as $ Row ) { if ( $ Row [ 'CategoryID' ] < 0 ) continue ; $ Categories [ $ Row [ 'CategoryID' ] ] = str_repeat ( ' ' , max ( 0 , $ Row [ 'Depth' ] - 1 ) ) . $ Row [ 'Name' ] ; } $ this -> SetData ( 'Categories' , $ Categories ) ; if ( ! $ this -> Form -> AuthenticatedPostBack ( ) ) { $ this -> Form -> SetData ( $ this -> Message ) ; } else { if ( $ MessageID = $ this -> Form -> Save ( ) ) { $ this -> MessageModel -> SetMessageCache ( ) ; $ this -> InformMessage ( T ( 'Your changes have been saved.' ) ) ; } } $ this -> Render ( ) ; }
|
Form to edit an existing message .
|
15,357
|
public function Index ( ) { $ this -> Permission ( 'Garden.Messages.Manage' ) ; $ this -> AddSideMenu ( 'dashboard/message' ) ; $ this -> AddJsFile ( 'jquery.autogrow.js' ) ; $ this -> AddJsFile ( 'jquery.tablednd.js' ) ; $ this -> AddJsFile ( 'jquery-ui.js' ) ; $ this -> AddJsFile ( 'messages.js' ) ; $ this -> Title ( T ( 'Messages' ) ) ; $ this -> MessageData = $ this -> MessageModel -> Get ( 'Sort' ) ; $ this -> Render ( ) ; }
|
Main page . Show all messages .
|
15,358
|
protected function _GetAssetData ( ) { $ AssetData = array ( ) ; $ AssetData [ 'Content' ] = T ( 'Above Main Content' ) ; $ AssetData [ 'Panel' ] = T ( 'Below Sidebar' ) ; $ this -> EventArguments [ 'AssetData' ] = & $ AssetData ; $ this -> FireEvent ( 'AfterGetAssetData' ) ; return $ AssetData ; }
|
Get descriptions of asset locations on page .
|
15,359
|
protected function _GetLocationData ( ) { $ ControllerData = array ( ) ; $ ControllerData [ '[Base]' ] = T ( 'All Pages' ) ; $ ControllerData [ '[NonAdmin]' ] = T ( 'All Forum Pages' ) ; $ ControllerData [ 'Dashboard/Profile/Index' ] = T ( 'Profile Page' ) ; $ ControllerData [ 'Vanilla/Discussions/Index' ] = T ( 'Discussions Page' ) ; $ ControllerData [ 'Vanilla/Discussion/Index' ] = T ( 'Comments Page' ) ; $ ControllerData [ 'Dashboard/Entry/SignIn' ] = T ( 'Sign In' ) ; $ this -> EventArguments [ 'ControllerData' ] = & $ ControllerData ; $ this -> FireEvent ( 'AfterGetLocationData' ) ; return $ ControllerData ; }
|
Get descriptions of asset locations across site .
|
15,360
|
public function validate ( $ subject ) : bool { if ( isset ( $ this -> schema [ 'items' ] ) && \ is_array ( $ this -> schema [ 'items' ] ) ) { $ schemaFirstKey = \ array_keys ( $ this -> schema [ 'items' ] ) [ 0 ] ; $ schemaType = \ is_int ( $ schemaFirstKey ) ? 'array' : 'object' ; if ( $ schemaType === 'array' ) { if ( ! $ this -> validateAdditionalItems ( $ subject , $ this -> schema ) ) { return false ; } } } return true ; }
|
Validates subject against additionalItems
|
15,361
|
private function validateAdditionalItems ( array $ subject , array $ schema ) : bool { $ subject = \ array_slice ( $ subject , count ( $ schema [ 'items' ] ) ) ; if ( \ is_bool ( $ schema [ 'additionalItems' ] ) ) { return $ this -> validateAdditionalItemsSchemaBoolean ( $ subject , $ schema ) ; } if ( \ is_int ( \ array_keys ( $ schema [ 'additionalItems' ] ) [ 0 ] ) ) { return $ this -> validateAdditionalItemsSchemaArray ( $ subject , $ schema ) ; } return $ this -> validateAdditionalItemsSchemaObject ( $ subject , $ schema ) ; }
|
Validates against additionalItems
|
15,362
|
private function validateAdditionalItemsSchemaBoolean ( array $ subject , array $ schema ) : bool { if ( ( $ schema [ 'additionalItems' ] === false ) && count ( $ subject ) > 0 ) { return false ; } return true ; }
|
Validate against additionalItems for boolean - type schema
|
15,363
|
private function validateAdditionalItemsSchemaObject ( array $ subject , array $ schema ) : bool { for ( $ i = 0 ; $ i < count ( $ subject ) ; $ i ++ ) { $ nodeValidator = new NodeValidator ( $ schema [ 'additionalItems' ] , $ this -> rootSchema ) ; if ( ! $ nodeValidator -> validate ( $ subject [ $ i ] ) ) { return false ; } } return true ; }
|
Validate against additionalItems for object - type schema
|
15,364
|
public function set ( $ key , $ data ) { $ file = $ this -> getFilePath ( $ key ) ; if ( $ handle = fopen ( $ file , 'w' ) ) { fwrite ( $ handle , $ data ) ; fclose ( $ handle ) ; } }
|
Set cache data
|
15,365
|
public function clean ( ) { $ directory = scandir ( $ this -> path ) ; if ( ! empty ( $ directory ) ) { foreach ( $ directory as $ item ) { if ( $ item !== '.' && $ item !== '..' ) { $ this -> remove ( $ item ) ; } } } return $ this ; }
|
Clean all cache
|
15,366
|
protected function allowAdd ( $ data = array ( ) ) { $ user = JFactory :: getUser ( ) ; return ( $ user -> authorise ( 'core.create' , $ this -> extension ) || count ( $ user -> getAuthorisedCategories ( $ this -> extension , 'core.create' ) ) ) ; }
|
Method to check if you can add a new record .
|
15,367
|
protected function allowEdit ( $ data = array ( ) , $ key = 'parent_id' ) { $ recordId = ( int ) isset ( $ data [ $ key ] ) ? $ data [ $ key ] : 0 ; $ user = JFactory :: getUser ( ) ; if ( $ user -> authorise ( 'core.edit' , $ this -> extension . '.category.' . $ recordId ) ) { return true ; } if ( $ user -> authorise ( 'core.edit.own' , $ this -> extension . '.category.' . $ recordId ) ) { $ record = $ this -> getModel ( ) -> getItem ( $ recordId ) ; if ( empty ( $ record ) ) { return false ; } $ ownerId = $ record -> created_user_id ; if ( $ ownerId == $ user -> id ) { return true ; } } return false ; }
|
Method to check if you can edit a record .
|
15,368
|
public function batch ( $ model = null ) { JSession :: checkToken ( ) or jexit ( JText :: _ ( 'JINVALID_TOKEN' ) ) ; $ model = $ this -> getModel ( 'Category' ) ; $ this -> setRedirect ( 'index.php?option=com_categories&view=categories&extension=' . $ this -> extension ) ; return parent :: batch ( $ model ) ; }
|
Method to run batch operations .
|
15,369
|
protected function getRedirectToItemAppend ( $ recordId = null , $ urlVar = 'id' ) { $ append = parent :: getRedirectToItemAppend ( $ recordId ) ; $ append .= '&extension=' . $ this -> extension ; return $ append ; }
|
Gets the URL arguments to append to an item redirect .
|
15,370
|
protected function postSaveHook ( JModelLegacy $ model , $ validData = array ( ) ) { $ item = $ model -> getItem ( ) ; if ( isset ( $ item -> params ) && is_array ( $ item -> params ) ) { $ registry = new Registry ; $ registry -> loadArray ( $ item -> params ) ; $ item -> params = ( string ) $ registry ; } if ( isset ( $ item -> metadata ) && is_array ( $ item -> metadata ) ) { $ registry = new Registry ; $ registry -> loadArray ( $ item -> metadata ) ; $ item -> metadata = ( string ) $ registry ; } }
|
Function that allows child controller access to model data after the data has been saved .
|
15,371
|
protected function guardAgainstEmpty ( $ data , $ dataName = 'Argument' , $ exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException' ) { if ( empty ( $ data ) ) { $ message = sprintf ( '%s cannot be empty' , $ dataName ) ; throw new $ exceptionClass ( $ message ) ; } }
|
Verify that the data is not empty
|
15,372
|
public function set ( $ key , $ value ) { if ( ! $ value instanceof RelationInterface ) { throw new InvalidArgumentException ( "Only RelationInterface objects can be putted in a " . "RelationsMap." ) ; } return parent :: set ( $ key , $ value ) ; }
|
Puts a new relation in the map .
|
15,373
|
final protected function valueInBounds ( $ value ) { return is_null ( $ value ) || ( ( is_null ( $ this -> getMinLength ( ) ) || strlen ( $ value ) >= $ this -> getMinLength ( ) ) && ( is_null ( $ this -> getMaxLength ( ) ) || strlen ( $ value ) <= $ this -> getMaxLength ( ) ) ) ; }
|
Checks if the length of the string is within bounds
|
15,374
|
public function bitsPerCharacter ( $ string ) { if ( is_string ( $ string ) === false ) { throw new \ InvalidArgumentException ( 'Argument must be a string.' ) ; } $ sum = 0 ; $ length = strlen ( $ string ) ; foreach ( array_values ( array_count_values ( str_split ( $ string ) ) ) as $ count ) { $ freq = $ count / $ length ; $ sum += $ freq * log ( $ freq , 2 ) ; } return ( int ) ceil ( - $ sum ) ; }
|
Calculate the number of bits needed to encode a single character of the given string .
|
15,375
|
public function addSearcher ( SearchInterface $ searcher ) { if ( $ searcher instanceof self && count ( $ searcher -> getSearchers ( ) ) ) { foreach ( $ searcher -> getSearchers ( ) as $ compositeSearcher ) { $ this -> addSearcher ( $ compositeSearcher ) ; } return $ this ; } $ this -> searchers [ ] = $ searcher ; return $ this ; }
|
Add a search providers
|
15,376
|
protected function loadMigrations ( ) { $ migrationsDir = $ this -> docRoot . '/src/Database/Migrations' ; foreach ( scandir ( $ migrationsDir ) as $ file ) { if ( $ file !== '.' && $ file !== '..' ) { require "{$migrationsDir}/{$file}" ; } } }
|
Load migrations .
|
15,377
|
protected function checkDatabaseInformation ( ) { $ this -> title ( "Database Information" ) ; $ errors = [ ] ; $ driver = Request :: $ post -> get ( 'driver' ) ; if ( $ driver == "pdo_pgsql" || $ driver == "pdo_mysql" ) { if ( ! Request :: $ post -> get ( 'host' ) ) { $ errors [ ] = "Server is required" ; } if ( ! Request :: $ post -> get ( 'user' ) ) { $ errors [ ] = "Username is required" ; } if ( ! Request :: $ post -> get ( 'dbname' ) ) { $ errors [ ] = "Database name is required" ; } } elseif ( $ driver == "pdo_sqlite" ) { if ( ! Request :: $ post -> get ( 'path' ) ) { $ errors [ ] = "Database path is required" ; } } if ( ! count ( $ errors ) ) { $ info = [ 'driver' => $ driver , ] ; switch ( $ driver ) { case "pdo_pgsql" : case "pdo_mysql" : $ info = $ info + [ 'host' => Request :: $ post -> get ( 'host' ) , 'user' => Request :: $ post -> get ( 'user' ) , 'password' => Request :: $ post -> get ( 'password' ) , 'dbname' => Request :: $ post -> get ( 'dbname' ) ] ; break ; case "pdo_sqlite" : $ info [ 'path' ] = Request :: $ post -> get ( 'path' ) ; break ; } try { $ db = ConnectionManager :: create ( $ info ) ; $ sm = $ db -> getSchemaManager ( ) ; $ sm -> listTables ( ) ; } catch ( DBALException $ e ) { $ errors [ ] = "Unable to connect to database: " . $ e -> getMessage ( ) ; } } if ( count ( $ errors ) ) { $ this -> title ( "Database Information" ) ; return $ this -> render ( "steps/database_information.phtml" , [ 'errors' => $ errors ] ) ; } $ _SESSION [ 'db' ] = $ info ; }
|
Check the database form fields and connection .
|
15,378
|
protected function checkAccountInformation ( ) { $ errors = [ ] ; if ( ! Request :: $ post -> get ( 'username' ) ) { $ errors [ ] = "Username is required" ; } if ( strlen ( Request :: $ post -> get ( 'username' ) ) < 3 ) { $ errors [ ] = "Username must be at least 3 characters long" ; } if ( ! Request :: $ post -> get ( 'password' ) ) { $ errors [ ] = "Password is required" ; } if ( strlen ( Request :: $ post -> get ( 'password' ) ) < 6 ) { $ errors [ ] = "Password must be at least 6 characters long" ; } if ( ! Request :: $ post -> get ( 'email' ) ) { $ errors [ ] = "Email is required" ; } if ( count ( $ errors ) ) { $ this -> title ( "Admin Account" ) ; return $ this -> render ( "steps/account_information.phtml" , [ 'errors' => $ errors ] ) ; } $ _SESSION [ 'admin' ] = [ 'username' => Request :: $ post -> get ( 'username' ) , 'password' => Request :: $ post -> get ( 'password' ) , 'confirm_password' => Request :: $ post -> get ( 'password' ) , 'email' => Request :: $ post -> get ( 'email' ) ] ; }
|
Check admin account information .
|
15,379
|
public function beforeFind ( Model $ model , $ query ) { $ runtime = $ this -> runtime [ $ model -> alias ] ; if ( $ runtime ) { if ( ! is_array ( $ query [ 'conditions' ] ) ) { $ query [ 'conditions' ] = array ( ) ; } $ conditions = array_filter ( array_keys ( $ query [ 'conditions' ] ) ) ; $ fields = $ this -> _normalizeFields ( $ model ) ; foreach ( $ fields as $ flag => $ date ) { if ( true === $ runtime || $ flag === $ runtime ) { if ( ! in_array ( $ flag , $ conditions ) && ! in_array ( $ model -> name . '.' . $ flag , $ conditions ) ) { $ query [ 'conditions' ] [ $ model -> alias . '.' . $ flag ] = false ; } if ( $ flag === $ runtime ) { break ; } } } return $ query ; } }
|
Before find callback
|
15,380
|
public function existsAndNotDeleted ( Model $ model , $ id ) { if ( $ id === null ) { $ id = $ model -> getID ( ) ; } if ( $ id === false ) { return false ; } $ exists = $ model -> find ( 'count' , array ( 'conditions' => array ( $ model -> alias . '.' . $ model -> primaryKey => $ id ) ) ) ; return ( $ exists ? true : false ) ; }
|
Check if a record exists for the given id
|
15,381
|
public function beforeDelete ( Model $ model , $ cascade = true ) { $ runtime = $ this -> runtime [ $ model -> alias ] ; if ( $ runtime ) { if ( $ model -> beforeDelete ( $ cascade ) ) { return $ this -> delete ( $ model , $ model -> id ) ; } return false ; } return true ; }
|
Before delete callback
|
15,382
|
public function delete ( $ model , $ id ) { $ runtime = $ this -> runtime [ $ model -> alias ] ; $ data = array ( ) ; $ fields = $ this -> _normalizeFields ( $ model ) ; foreach ( $ fields as $ flag => $ date ) { if ( true === $ runtime || $ flag === $ runtime ) { $ data [ $ flag ] = true ; if ( $ date ) { $ data [ $ date ] = date ( 'Y-m-d H:i:s' ) ; } if ( $ flag === $ runtime ) { break ; } } } $ record = $ model -> find ( 'first' , array ( 'fields' => $ model -> primaryKey , 'conditions' => array ( $ model -> primaryKey => $ id ) , 'recursive' => - 1 ) ) ; if ( ! empty ( $ record ) ) { $ model -> set ( $ model -> primaryKey , $ id ) ; unset ( $ model -> data [ $ model -> alias ] [ 'modified' ] ) ; unset ( $ model -> data [ $ model -> alias ] [ 'updated' ] ) ; return $ model -> save ( array ( $ model -> alias => $ data ) , false , array_keys ( $ data ) ) ; } return true ; }
|
Mark record as deleted
|
15,383
|
public function undelete ( $ model , $ id ) { $ runtime = $ this -> runtime [ $ model -> alias ] ; $ this -> softDelete ( $ model , false ) ; $ data = array ( ) ; $ fields = $ this -> _normalizeFields ( $ model ) ; foreach ( $ fields as $ flag => $ date ) { if ( true === $ runtime || $ flag === $ runtime ) { $ data [ $ flag ] = false ; if ( $ date ) { $ data [ $ date ] = null ; } if ( $ flag === $ runtime ) { break ; } } } $ model -> create ( ) ; $ model -> set ( $ model -> primaryKey , $ id ) ; $ result = $ model -> save ( array ( $ model -> alias => $ data ) , false , array_keys ( $ data ) ) ; $ this -> softDelete ( $ model , $ runtime ) ; return $ result ; }
|
Mark record as not deleted
|
15,384
|
public function purgeDeletedCount ( $ model , $ expiration = '-90 days' ) { $ this -> softDelete ( $ model , false ) ; return $ model -> find ( 'count' , array ( 'conditions' => $ this -> _purgeDeletedConditions ( $ model , $ expiration ) , 'recursive' => - 1 , 'contain' => array ( ) ) ) ; }
|
Returns number of outdated softdeleted records prepared for purge
|
15,385
|
protected function _purgeDeletedConditions ( $ model , $ expiration = '-90 days' ) { $ purgeDate = date ( 'Y-m-d H:i:s' , strtotime ( $ expiration ) ) ; $ conditions = array ( ) ; foreach ( $ this -> settings [ $ model -> alias ] as $ flag => $ date ) { $ conditions [ $ model -> alias . '.' . $ flag ] = true ; if ( $ date ) { $ conditions [ $ model -> alias . '.' . $ date . ' <' ] = $ purgeDate ; } } return $ conditions ; }
|
Returns conditions for finding outdated records
|
15,386
|
protected function _normalizeFields ( $ model , $ settings = array ( ) ) { if ( empty ( $ settings ) ) { $ settings = $ this -> settings [ $ model -> alias ] ; } $ result = array ( ) ; foreach ( $ settings as $ flag => $ date ) { if ( is_numeric ( $ flag ) ) { $ flag = $ date ; $ date = false ; } $ result [ $ flag ] = $ date ; } return $ result ; }
|
Return normalized field array
|
15,387
|
protected function _softDeleteAssociations ( $ model , $ active ) { if ( empty ( $ model -> belongsTo ) ) { return ; } $ fields = array_keys ( $ this -> _normalizeFields ( $ model ) ) ; $ parentModels = array_keys ( $ model -> belongsTo ) ; foreach ( $ parentModels as $ parentModel ) { foreach ( array ( 'hasOne' , 'hasMany' ) as $ assocType ) { if ( empty ( $ model -> { $ parentModel } -> { $ assocType } ) ) { continue ; } foreach ( $ model -> { $ parentModel } -> { $ assocType } as $ assoc => $ assocConfig ) { $ modelName = empty ( $ assocConfig [ 'className' ] ) ? $ assoc : @ $ assocConfig [ 'className' ] ; if ( ( ! empty ( $ model -> plugin ) && strstr ( $ model -> plugin . '.' , $ model -> alias ) === false ? $ model -> plugin . '.' : '' ) . $ model -> alias !== $ modelName ) { continue ; } $ conditions = & $ model -> { $ parentModel } -> { $ assocType } [ $ assoc ] [ 'conditions' ] ; if ( ! is_array ( $ conditions ) ) { $ model -> { $ parentModel } -> { $ assocType } [ $ assoc ] [ 'conditions' ] = array ( ) ; } $ multiFields = 1 < count ( $ fields ) ; foreach ( $ fields as $ field ) { if ( $ active ) { if ( ! isset ( $ conditions [ $ field ] ) && ! isset ( $ conditions [ $ assoc . '.' . $ field ] ) ) { if ( is_string ( $ active ) ) { if ( $ field == $ active ) { $ conditions [ $ assoc . '.' . $ field ] = false ; } elseif ( isset ( $ conditions [ $ assoc . '.' . $ field ] ) ) { unset ( $ conditions [ $ assoc . '.' . $ field ] ) ; } } elseif ( ! $ multiFields ) { $ conditions [ $ assoc . '.' . $ field ] = false ; } } } elseif ( isset ( $ conditions [ $ assoc . '.' . $ field ] ) ) { unset ( $ conditions [ $ assoc . '.' . $ field ] ) ; } } } } } }
|
Modifies conditions of hasOne and hasMany associations
|
15,388
|
public function with ( $ transformer ) { $ concrete = self :: getTransformerFactory ( ) -> make ( $ transformer ) ; $ this -> resource -> setTransformer ( $ concrete ) ; return Presentation :: of ( $ this -> resource ) ; }
|
Set a transformer on the resource .
|
15,389
|
public function generateWhere ( $ conditions , & $ where , & $ values , & $ types ) { $ where = "" ; if ( count ( $ conditions ) == 0 ) { return ; } $ idx = 0 ; $ max = count ( $ conditions ) ; foreach ( $ conditions as $ criteria ) { $ column = $ criteria [ 'column' ] ; $ operator = $ criteria [ 'operator' ] ; $ value = $ criteria [ 'value' ] ; $ where .= "$column " ; if ( $ operator === "IN" ) { $ where .= "IN (" ; $ subIdx = 0 ; $ subMax = count ( $ value ) ; foreach ( $ value as $ subValue ) { $ where .= "?" ; $ values [ ] = $ this -> prepareData ( $ subValue ) ; $ types [ ] = $ this -> determinateType ( $ subValue ) ; if ( ( $ subIdx + 1 ) < $ subMax ) { $ where .= "," ; } $ subIdx ++ ; } $ where .= ")" ; } else { $ where .= "$operator " ; $ where .= "?" ; $ values [ ] = $ this -> prepareData ( $ value ) ; $ types [ ] = $ this -> determinateType ( $ value ) ; } if ( ( $ idx + 1 ) < $ max ) { $ where .= " AND " ; } $ idx ++ ; } }
|
Generate Where clause
|
15,390
|
public function generateOrder ( $ sortBy , $ sortOrder , & $ order ) { if ( ! empty ( $ sortBy ) ) { if ( empty ( $ sortOrder ) ) { $ sortOrder = "ASC" ; } $ order = "$sortBy $sortOrder" ; } }
|
Generate Order By
|
15,391
|
public function generateLimit ( $ limitCount , $ limitOffset , & $ limit ) { $ limit = "" ; if ( empty ( $ limitCount ) ) { return ; } $ limit = "$limitCount" ; if ( ! empty ( $ limitOffset ) ) { $ limit .= ",$limitOffset" ; } }
|
Generate Limit part
|
15,392
|
public function generateInsert ( $ columnOrder , $ changeData , & $ start , & $ data , & $ values , & $ types ) { $ start = "(" ; $ data = "(" ; $ idx = 0 ; $ max = count ( $ columnOrder ) ; foreach ( $ columnOrder as $ column ) { $ value = null ; if ( isset ( $ changeData [ $ column -> name ] ) ) { $ value = $ changeData [ $ column -> name ] ; } $ start .= "`" . $ column -> name . "`" ; $ data .= "?" ; $ values [ ] = $ this -> prepareData ( $ changeData [ $ column -> name ] ) ; $ types [ ] = $ this -> determinateType ( $ changeData [ $ column -> name ] ) ; if ( ( $ idx + 1 ) < $ max ) { $ start .= "," ; $ data .= "," ; } $ idx ++ ; } $ start .= ")" ; $ data .= ")" ; }
|
Generate Insert parts
|
15,393
|
public function generateUpdate ( $ changeData , & $ data , & $ values , & $ types ) { $ data = "" ; $ idx = 0 ; $ max = count ( $ changeData ) ; foreach ( $ changeData as $ column => $ value ) { $ data .= "$column = ?" ; $ values [ ] = $ this -> prepareData ( $ value ) ; $ types [ ] = $ this -> determinateType ( $ value ) ; if ( ( $ idx + 1 ) < $ max ) { $ data .= "," ; } $ idx ++ ; } }
|
Generate Update Lines
|
15,394
|
public function start ( $ key ) { $ key = strtolower ( $ key ) ; $ this -> benchmarks [ $ key ] = [ 'start_time' => microtime ( true ) , 'stop_time' => 0.0 , 'avg_time' => 0.0 , 'start_memory' => memory_get_usage ( true ) , 'stop_memory' => 0 , 'avg_memory' => 0 , 'peak_memory' => 0 , 'running' => true ] ; }
|
Starts a benchmark running .
|
15,395
|
public function stop ( $ key ) { $ benchmark = $ this -> get ( $ key ) ; $ benchmark [ 'stop_time' ] = microtime ( true ) ; $ benchmark [ 'avg_time' ] = $ benchmark [ 'stop_time' ] - $ benchmark [ 'start_time' ] ; $ benchmark [ 'stop_memory' ] = memory_get_usage ( true ) ; $ benchmark [ 'avg_memory' ] = ( ( $ benchmark [ 'stop_memory' ] - $ benchmark [ 'start_memory' ] ) / 1024 ) / 1024 ; $ benchmark [ 'peak_memory' ] = memory_get_peak_usage ( true ) / 1024 / 1024 ; $ benchmark [ 'running' ] = false ; $ this -> benchmarks [ $ key ] = $ benchmark ; }
|
Stops a timer running and calculates the statistics .
|
15,396
|
public function get ( $ key ) { $ key = strtolower ( $ key ) ; if ( ! array_key_exists ( $ key , $ this -> benchmarks ) ) { throw new \ RuntimeException ( 'No Benchmark exists for: ' . $ key ) ; } return $ this -> benchmarks [ $ key ] ; }
|
Returns a single benchmark item .
|
15,397
|
public function output ( $ key ) { $ key = strtolower ( $ key ) ; $ benchmark = $ this -> get ( $ key ) ; return sprintf ( '[%s] %s seconds, %sMB memory (%sMB peak)' , $ key , number_format ( $ benchmark [ 'avg_time' ] , 4 ) , number_format ( $ benchmark [ 'avg_memory' ] , 2 ) , number_format ( $ benchmark [ 'peak_memory' ] , 2 ) ) ; }
|
Returns a single benchmark formatted as a string .
|
15,398
|
public static function createStatement ( $ sql , & $ connection = null , $ fetchMode = \ PDO :: FETCH_ASSOC ) { $ _db = self :: _checkConnection ( $ connection ) ; $ _statement = $ _db -> prepare ( $ sql ) ; if ( false !== $ fetchMode ) { $ _statement -> setFetchMode ( $ fetchMode ) ; } return $ _statement ; }
|
Creates and returns an optionally parameter - bound \ PDOStatement object
|
15,399
|
public static function query ( $ sql , $ parameters = null , & $ connection = null , $ fetchMode = \ PDO :: FETCH_ASSOC ) { return DataReader :: create ( $ sql , $ parameters , $ connection , $ fetchMode ) ; }
|
Creates and returns an optionally parameter - bound \ PDOStatement object suitable for iteration
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.