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...
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 ) { $ scheme...
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 ...
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 -> get...
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 ] ; $ fragmen...
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...
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 relativ...
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 ; } ...
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 charac...
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 ...
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 ( ...
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' ) ....
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 = ( ...
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 <...
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...
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 , ]...
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' ] ?? [ ] ...
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 ...
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 conf...
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 -> da...
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 , $ m...
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 ; }...
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, ' . cou...
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 -> setAddResour...
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' : retu...
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 ) u...
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 , $...
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 -> getResourceN...
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 :: UCP...
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' => [ 'f...
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 ( $ na...
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 -> getAl...
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 ,...
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 H...
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 -> Mess...
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 ...
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 (...
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 ( 'Discu...
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...
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 ( \ arr...
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 fa...
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 ...
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 (...
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 / $ le...
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 ; retu...
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 ( ! Req...
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 ...
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 -> _norma...
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 : ...
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 [ $ d...
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 [ $...
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 ( $ d...
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 ] = ...
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' , 'has...
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...
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 = $ changeD...
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 ( $ valu...
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...
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_memo...
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