idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
22,400 | public function sizedByteArray ( ) { $ start = $ this -> space ; $ length = $ this -> bb -> capacity ( ) - $ this -> space ; $ result = str_repeat ( "\0" , $ length ) ; $ this -> bb -> setPosition ( $ start ) ; $ this -> bb -> getX ( $ result ) ; return $ result ; } | Utility function to copy and return the FlatBuffer data from the underlying ByteBuffer . |
22,401 | public function writeLittleEndian ( $ offset , $ count , $ data ) { if ( ByteBuffer :: isLittleEndian ( ) ) { for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ this -> _buffer [ $ offset + $ i ] = chr ( $ data >> $ i * 8 ) ; } } else { for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ this -> _buffer [ $ offset + $ count - 1 - $... | write little endian value to the buffer . |
22,402 | public function readLittleEndian ( $ offset , $ count , $ force_bigendian = false ) { $ this -> assertOffsetAndLength ( $ offset , $ count ) ; $ r = 0 ; if ( ByteBuffer :: isLittleEndian ( ) && $ force_bigendian == false ) { for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ r |= ord ( $ this -> _buffer [ $ offset + $ i ] ) ... | read little endian value from the buffer |
22,403 | public function putBack ( $ data ) { if ( TStringFuncFactory :: create ( ) -> strlen ( $ this -> rBuf_ ) === 0 ) { $ this -> rBuf_ = $ data ; } else { $ this -> rBuf_ = ( $ data . $ this -> rBuf_ ) ; } } | Put previously read data back into the buffer |
22,404 | private function readFrame ( ) { $ buf = $ this -> transport_ -> readAll ( 4 ) ; $ val = unpack ( 'N' , $ buf ) ; $ sz = $ val [ 1 ] ; $ this -> rBuf_ = $ this -> transport_ -> readAll ( $ sz ) ; } | Reads a chunk of data into the internal read buffer . |
22,405 | public function write ( $ buf , $ len = null ) { if ( ! $ this -> write_ ) { return $ this -> transport_ -> write ( $ buf , $ len ) ; } if ( $ len !== null && $ len < TStringFuncFactory :: create ( ) -> strlen ( $ buf ) ) { $ buf = TStringFuncFactory :: create ( ) -> substr ( $ buf , 0 , $ len ) ; } $ this -> wBuf_ .= ... | Writes some data to the pending output buffer . |
22,406 | public function flush ( ) { if ( ! $ this -> write_ || TStringFuncFactory :: create ( ) -> strlen ( $ this -> wBuf_ ) == 0 ) { return $ this -> transport_ -> flush ( ) ; } $ out = pack ( 'N' , TStringFuncFactory :: create ( ) -> strlen ( $ this -> wBuf_ ) ) ; $ out .= $ this -> wBuf_ ; $ this -> wBuf_ = '' ; $ this -> ... | Writes the output buffer to the stream in the format of a 4 - byte length followed by the actual data . |
22,407 | public function writeMessageBegin ( $ name , $ type , $ seqid ) { return $ this -> concreteProtocol_ -> writeMessageBegin ( $ name , $ type , $ seqid ) ; } | Writes the message header . |
22,408 | public function serve ( ) { $ this -> transport_ -> listen ( ) ; while ( ! $ this -> stop_ ) { try { $ transport = $ this -> transport_ -> accept ( ) ; if ( $ transport != null ) { $ pid = pcntl_fork ( ) ; if ( $ pid > 0 ) { $ this -> handleParent ( $ transport , $ pid ) ; } elseif ( $ pid === 0 ) { $ this -> handleChi... | Listens for new client using the supplied transport . We fork when a new connection arrives . |
22,409 | private function handleChild ( TTransport $ transport ) { try { $ inputTransport = $ this -> inputTransportFactory_ -> getTransport ( $ transport ) ; $ outputTransport = $ this -> outputTransportFactory_ -> getTransport ( $ transport ) ; $ inputProtocol = $ this -> inputProtocolFactory_ -> getProtocol ( $ inputTranspor... | Code run by the child . |
22,410 | private function collectChildren ( ) { foreach ( $ this -> children_ as $ pid => $ transport ) { if ( pcntl_waitpid ( $ pid , $ status , WNOHANG ) > 0 ) { unset ( $ this -> children_ [ $ pid ] ) ; if ( $ transport ) { @ $ transport -> close ( ) ; } } } } | Collects any children we may have |
22,411 | protected function pushWriteContext ( Context $ c ) { $ this -> writeContextStack_ [ ] = $ this -> writeContext_ ; $ this -> writeContext_ = $ c ; } | Push a new write context onto the stack . |
22,412 | public function writeStructBegin ( $ name ) { $ this -> writeContext_ -> write ( ) ; $ this -> trans_ -> write ( self :: LBRACE ) ; $ this -> pushWriteContext ( new StructContext ( $ this ) ) ; } | Writes a struct header . |
22,413 | public static function serialize ( $ object ) { $ transport = new TMemoryBuffer ( ) ; $ protocol = new TBinaryProtocolAccelerated ( $ transport ) ; if ( function_exists ( 'thrift_protocol_write_binary' ) ) { thrift_protocol_write_binary ( $ protocol , $ object -> getName ( ) , TMessageType :: REPLY , $ object , 0 , $ p... | normal deserialization . |
22,414 | public function readAll ( $ len ) { $ data = '' ; $ got = 0 ; while ( ( $ got = TStringFuncFactory :: create ( ) -> strlen ( $ data ) ) < $ len ) { $ data .= $ this -> read ( $ len - $ got ) ; } return $ data ; } | Guarantees that the full amount of data is read . |
22,415 | public function listen ( ) { $ this -> listener_ = @ stream_socket_server ( $ this -> host_ . ':' . $ this -> port_ , $ errno , $ errstr , STREAM_SERVER_BIND | STREAM_SERVER_LISTEN , $ this -> context_ ) ; } | Opens a new socket server handle |
22,416 | protected function acceptImpl ( ) { $ handle = @ stream_socket_accept ( $ this -> listener_ , $ this -> acceptTimeout_ / 1000.0 ) ; if ( ! $ handle ) { return null ; } $ socket = new TSSLSocket ( ) ; $ socket -> setHandle ( $ handle ) ; return $ socket ; } | Implementation of accept . If not client is accepted in the given time |
22,417 | public function serve ( ) { $ this -> transport_ -> listen ( ) ; while ( ! $ this -> stop_ ) { try { $ transport = $ this -> transport_ -> accept ( ) ; if ( $ transport != null ) { $ inputTransport = $ this -> inputTransportFactory_ -> getTransport ( $ transport ) ; $ outputTransport = $ this -> outputTransportFactory_... | Listens for new client using the supplied transport . It handles TTransportExceptions to avoid timeouts etc killing it |
22,418 | public function setSendTimeout ( $ timeout ) { $ this -> sendTimeoutSec_ = floor ( $ timeout / 1000 ) ; $ this -> sendTimeoutUsec_ = ( $ timeout - ( $ this -> sendTimeoutSec_ * 1000 ) ) * 1000 ; } | Sets the send timeout . |
22,419 | public function readAll ( $ len ) { $ data = $ this -> read ( $ len ) ; if ( TStringFuncFactory :: create ( ) -> strlen ( $ data ) !== $ len ) { throw new TTransportException ( 'TCurlClient could not read ' . $ len . ' bytes' ) ; } return $ data ; } | Guarantees that the full amount of data is read . Since TCurlClient gets entire payload at once parent readAll cannot be used . |
22,420 | public function loadClass ( $ class ) { if ( ( true === $ this -> apc && ( $ file = $ this -> findFileInApc ( $ class ) ) ) or ( $ file = $ this -> findFile ( $ class ) ) ) { require_once $ file ; } } | Loads the given class definition or interface . |
22,421 | protected function findFileInApc ( $ class ) { if ( false === $ file = apc_fetch ( $ this -> apc_prefix . $ class ) ) { apc_store ( $ this -> apc_prefix . $ class , $ file = $ this -> findFile ( $ class ) ) ; } return $ file ; } | Loads the given class or interface in APC . |
22,422 | public function findFile ( $ class ) { if ( '\\' == $ class [ 0 ] ) { $ class = substr ( $ class , 1 ) ; } if ( false !== $ pos = strrpos ( $ class , '\\' ) ) { $ namespace = substr ( $ class , 0 , $ pos ) ; foreach ( $ this -> namespaces as $ ns => $ dirs ) { if ( 0 !== strpos ( $ namespace , $ ns ) ) { continue ; } f... | Find class in namespaces or definitions directories |
22,423 | public function cacheFile ( $ type = 'jpg' , $ quality = 80 , $ actual = false , $ extras = [ ] ) { if ( $ type === 'guess' ) { $ type = $ this -> guessType ( ) ; } if ( ! $ this -> forceCache && ! count ( $ this -> operations ) && $ type === $ this -> guessType ( ) ) { return $ this -> getFilename ( $ this -> getFileP... | This is the same as the Gregwar Image class except this one fires a Grav Event on creation of new cached file |
22,424 | public function getHash ( $ type = 'guess' , $ quality = 80 , $ extras = [ ] ) { if ( null === $ this -> hash ) { $ this -> generateHash ( $ type , $ quality , $ extras ) ; } return $ this -> hash ; } | Gets the hash . |
22,425 | public function init ( ) { $ grav = Grav :: instance ( ) ; $ config = $ grav [ 'config' ] ; $ events = $ grav [ 'events' ] ; foreach ( $ this -> items as $ instance ) { if ( $ config [ "plugins.{$instance->name}.enabled" ] && $ instance instanceof Plugin ) { $ instance -> setConfig ( $ config ) ; $ events -> addSubscri... | Registers all plugins . |
22,426 | public static function all ( ) { $ plugins = Grav :: instance ( ) [ 'plugins' ] ; $ list = [ ] ; foreach ( $ plugins as $ instance ) { $ name = $ instance -> name ; $ result = self :: get ( $ name ) ; if ( $ result ) { $ list [ $ name ] = $ result ; } } return $ list ; } | Return list of all plugin data with their blueprints . |
22,427 | public static function get ( $ name ) { $ blueprints = new Blueprints ( 'plugins://' ) ; $ blueprint = $ blueprints -> get ( "{$name}/blueprints" ) ; $ file = CompiledYamlFile :: instance ( "plugins://{$name}/{$name}" . YAML_EXT ) ; if ( ! $ file -> exists ( ) ) { return null ; } $ obj = new Data ( ( array ) $ file -> ... | Get a plugin by name |
22,428 | public static function unZip ( $ zip_file , $ destination ) { $ zip = new \ ZipArchive ( ) ; $ archive = $ zip -> open ( $ zip_file ) ; if ( $ archive === true ) { Folder :: create ( $ destination ) ; $ unzip = $ zip -> extractTo ( $ destination ) ; if ( ! $ unzip ) { self :: $ error = self :: ZIP_EXTRACT_ERROR ; Folde... | Unzip a file to somewhere |
22,429 | private static function loadInstaller ( $ installer_file_folder , $ is_install ) { $ installer = null ; $ installer_file_folder = rtrim ( $ installer_file_folder , DS ) ; $ install_file = $ installer_file_folder . DS . 'install.php' ; if ( file_exists ( $ install_file ) ) { require_once $ install_file ; } else { return... | Instantiates and returns the package installer class |
22,430 | public static function uninstall ( $ path , $ options = [ ] ) { $ options = array_merge ( self :: $ options , $ options ) ; if ( ! self :: isValidDestination ( $ path , $ options [ 'exclude_checks' ] ) ) { return false ; } $ installer_file_folder = $ path ; $ is_install = false ; $ installer = self :: loadInstaller ( $... | Uninstalls one or more given package |
22,431 | public static function isValidDestination ( $ destination , $ exclude = [ ] ) { self :: $ error = 0 ; self :: $ target = $ destination ; if ( is_link ( $ destination ) ) { self :: $ error = self :: IS_LINK ; } elseif ( file_exists ( $ destination ) ) { self :: $ error = self :: EXISTS ; } elseif ( ! file_exists ( $ des... | Runs a set of checks on the destination and sets the Error if any |
22,432 | public static function isGravInstance ( $ target ) { self :: $ error = 0 ; self :: $ target = $ target ; if ( ! file_exists ( $ target . DS . 'index.php' ) || ! file_exists ( $ target . DS . 'bin' ) || ! file_exists ( $ target . DS . 'user' ) || ! file_exists ( $ target . DS . 'system' . DS . 'config' . DS . 'system.ya... | Validates if the given path is a Grav Instance |
22,433 | public static function lastErrorMsg ( ) { if ( is_string ( self :: $ error ) ) { return self :: $ error ; } switch ( self :: $ error ) { case 0 : $ msg = 'No Error' ; break ; case self :: EXISTS : $ msg = 'The target path "' . self :: $ target . '" already exists' ; break ; case self :: IS_LINK : $ msg = 'The target pa... | Returns the last error occurred in a string message format |
22,434 | public function base ( $ path = null ) { if ( $ path !== null ) { $ path = trim ( $ path , '/' ) ; $ this -> base = $ path ? '/' . $ path : null ; $ this -> baseRoute = [ ] ; } return $ this -> base ; } | Get or set base path for the pages . |
22,435 | public function init ( ) { $ config = $ this -> grav [ 'config' ] ; $ this -> ignore_files = $ config -> get ( 'system.pages.ignore_files' ) ; $ this -> ignore_folders = $ config -> get ( 'system.pages.ignore_folders' ) ; $ this -> ignore_hidden = $ config -> get ( 'system.pages.ignore_hidden' ) ; $ this -> instances =... | Class initialization . Must be called before using this class . |
22,436 | public function lastModified ( $ modified = null ) { if ( $ modified && $ modified > $ this -> last_modified ) { $ this -> last_modified = $ modified ; } return $ this -> last_modified ; } | Get or set last modification time . |
22,437 | public function addPage ( PageInterface $ page , $ route = null ) { if ( ! isset ( $ this -> instances [ $ page -> path ( ) ] ) ) { $ this -> instances [ $ page -> path ( ) ] = $ page ; } $ route = $ page -> route ( $ route ) ; if ( $ page -> parent ( ) ) { $ this -> children [ $ page -> parent ( ) -> path ( ) ] [ $ pa... | Adds a page and assigns a route to it . |
22,438 | public function sort ( PageInterface $ page , $ order_by = null , $ order_dir = null , $ sort_flags = null ) { if ( $ order_by === null ) { $ order_by = $ page -> orderBy ( ) ; } if ( $ order_dir === null ) { $ order_dir = $ page -> orderDir ( ) ; } $ path = $ page -> path ( ) ; $ children = $ this -> children [ $ path... | Sort sub - pages in a page . |
22,439 | public function children ( $ path ) { $ children = $ this -> children [ ( string ) $ path ] ?? [ ] ; return new Collection ( $ children , [ ] , $ this ) ; } | Get children of the path . |
22,440 | public function ancestor ( $ route , $ path = null ) { if ( $ path !== null ) { $ page = $ this -> dispatch ( $ route , true ) ; if ( $ page && $ page -> path ( ) === $ path ) { return $ page ; } $ parent = $ page ? $ page -> parent ( ) : null ; if ( $ parent && ! $ parent -> root ( ) ) { return $ this -> ancestor ( $ ... | Get a page ancestor . |
22,441 | public function inherited ( $ route , $ field = null ) { if ( $ field !== null ) { $ page = $ this -> dispatch ( $ route , true ) ; $ parent = $ page ? $ page -> parent ( ) : null ; if ( $ parent && $ parent -> value ( 'header.' . $ field ) !== null ) { return $ parent ; } if ( $ parent && ! $ parent -> root ( ) ) { re... | Get a page ancestor trait . |
22,442 | public function root ( ) { $ locator = $ this -> grav [ 'locator' ] ; return $ this -> instances [ rtrim ( $ locator -> findResource ( 'page://' ) , DS ) ] ; } | Get root page . |
22,443 | public function blueprints ( $ type ) { if ( $ this -> blueprints === null ) { $ this -> blueprints = new Blueprints ( self :: getTypes ( ) ) ; } try { $ blueprint = $ this -> blueprints -> get ( $ type ) ; } catch ( \ RuntimeException $ e ) { $ blueprint = $ this -> blueprints -> get ( 'default' ) ; } if ( empty ( $ b... | Get a blueprint for a page type . |
22,444 | public function all ( PageInterface $ current = null ) { $ all = new Collection ( ) ; $ current = $ current ? : $ this -> root ( ) ; if ( ! $ current -> root ( ) ) { $ all [ $ current -> path ( ) ] = [ 'slug' => $ current -> slug ( ) ] ; } foreach ( $ current -> children ( ) as $ next ) { $ all -> append ( $ this -> al... | Get all pages |
22,445 | private static function getParents ( $ rawRoutes ) { $ grav = Grav :: instance ( ) ; $ pages = $ grav [ 'pages' ] ; $ parents = $ pages -> getList ( null , 0 , $ rawRoutes ) ; if ( isset ( $ grav [ 'admin' ] ) ) { $ admin = $ grav [ 'admin' ] ; $ page = $ admin -> getPage ( $ admin -> route ) ; $ page_route = $ page ->... | Get available parents routes |
22,446 | public static function getTypes ( ) { if ( ! self :: $ types ) { $ grav = Grav :: instance ( ) ; $ scanBlueprintsAndTemplates = function ( ) use ( $ grav ) { $ event = new Event ( ) ; $ event -> types = self :: $ types ; $ grav -> fireEvent ( 'onGetPageBlueprints' , $ event ) ; self :: $ types -> scanBlueprints ( 'them... | Get available page types . |
22,447 | public function accessLevels ( ) { $ accessLevels = [ ] ; foreach ( $ this -> all ( ) as $ page ) { if ( isset ( $ page -> header ( ) -> access ) ) { if ( \ is_array ( $ page -> header ( ) -> access ) ) { foreach ( $ page -> header ( ) -> access as $ index => $ accessLevel ) { if ( \ is_array ( $ accessLevel ) ) { fore... | Get access levels of the site pages |
22,448 | public static function getHomeRoute ( ) { if ( empty ( self :: $ home_route ) ) { $ grav = Grav :: instance ( ) ; $ config = $ grav [ 'config' ] ; $ language = $ grav [ 'language' ] ; $ home = $ config -> get ( 'system.home.alias' ) ; if ( $ language -> enabled ( ) ) { $ home_aliases = $ config -> get ( 'system.home.al... | Gets the home route |
22,449 | protected function buildPages ( ) { $ this -> sort = [ ] ; $ config = $ this -> grav [ 'config' ] ; $ language = $ this -> grav [ 'language' ] ; $ locator = $ this -> grav [ 'locator' ] ; $ pages_dir = $ locator -> findResource ( 'page://' ) ; if ( $ config -> get ( 'system.cache.enabled' ) ) { $ cache = $ this -> grav... | Builds pages . |
22,450 | public function resetPages ( $ pages_dir ) { $ this -> recurse ( $ pages_dir ) ; $ this -> buildRoutes ( ) ; if ( $ this -> grav [ 'config' ] -> get ( 'system.cache.enabled' ) ) { $ cache = $ this -> grav [ 'cache' ] ; $ taxonomy = $ this -> grav [ 'taxonomy' ] ; $ cache -> save ( $ this -> pages_cache_id , [ $ this ->... | Accessible method to manually reset the pages cache |
22,451 | protected function arrayShuffle ( $ list ) { $ keys = array_keys ( $ list ) ; shuffle ( $ keys ) ; $ new = [ ] ; foreach ( $ keys as $ key ) { $ new [ $ key ] = $ list [ $ key ] ; } return $ new ; } | Shuffles an associative array |
22,452 | public function delete ( $ username ) : bool { $ file_path = Grav :: instance ( ) [ 'locator' ] -> findResource ( 'account://' . $ username . YAML_EXT ) ; return $ file_path && unlink ( $ file_path ) ; } | Remove user account . |
22,453 | public function controls ( $ display = true ) { if ( $ display ) { $ this -> attributes [ 'controls' ] = true ; } else { unset ( $ this -> attributes [ 'controls' ] ) ; } return $ this ; } | Allows to set or remove the HTML5 default controls |
22,454 | public function preload ( $ preload ) { $ validPreloadAttrs = [ 'auto' , 'metadata' , 'none' ] ; if ( \ in_array ( $ preload , $ validPreloadAttrs , true ) ) { $ this -> attributes [ 'preload' ] = $ preload ; } return $ this ; } | Allows to set the preload behaviour |
22,455 | public function muted ( $ status = false ) { if ( $ status ) { $ this -> attributes [ 'muted' ] = true ; } else { unset ( $ this -> attributes [ 'muted' ] ) ; } return $ this ; } | Allows to set the muted attribute |
22,456 | public function loop ( $ status = false ) { if ( $ status ) { $ this -> attributes [ 'loop' ] = true ; } else { unset ( $ this -> attributes [ 'loop' ] ) ; } return $ this ; } | Allows to set the loop attribute |
22,457 | public function autoplay ( $ status = false ) { if ( $ status ) { $ this -> attributes [ 'autoplay' ] = true ; } else { unset ( $ this -> attributes [ 'autoplay' ] ) ; } return $ this ; } | Allows to set the autoplay attribute |
22,458 | public static function lastModifiedFolder ( $ path ) { $ last_modified = 0 ; $ locator = Grav :: instance ( ) [ 'locator' ] ; $ flags = \ RecursiveDirectoryIterator :: SKIP_DOTS ; if ( $ locator -> isStream ( $ path ) ) { $ directory = $ locator -> getRecursiveIterator ( $ path , $ flags ) ; } else { $ directory = new ... | Recursively find the last modified time under given path . |
22,459 | public static function lastModifiedFile ( $ path , $ extensions = 'md|yaml' ) { $ last_modified = 0 ; $ locator = Grav :: instance ( ) [ 'locator' ] ; $ flags = \ RecursiveDirectoryIterator :: SKIP_DOTS ; if ( $ locator -> isStream ( $ path ) ) { $ directory = $ locator -> getRecursiveIterator ( $ path , $ flags ) ; } ... | Recursively find the last modified time under given path by file . |
22,460 | public static function hashAllFiles ( $ path ) { $ flags = \ RecursiveDirectoryIterator :: SKIP_DOTS ; $ files = [ ] ; $ locator = Grav :: instance ( ) [ 'locator' ] ; if ( $ locator -> isStream ( $ path ) ) { $ directory = $ locator -> getRecursiveIterator ( $ path , $ flags ) ; } else { $ directory = new \ RecursiveD... | Recursively md5 hash all files in a path |
22,461 | public static function shift ( & $ path ) { $ parts = explode ( '/' , trim ( $ path , '/' ) , 2 ) ; $ result = array_shift ( $ parts ) ; $ path = array_shift ( $ parts ) ; return $ result ? : null ; } | Shift first directory out of the path . |
22,462 | public static function copy ( $ source , $ target , $ ignore = null ) { $ source = rtrim ( $ source , '\\/' ) ; $ target = rtrim ( $ target , '\\/' ) ; if ( ! is_dir ( $ source ) ) { throw new \ RuntimeException ( 'Cannot copy non-existing folder.' ) ; } self :: create ( $ target ) ; $ success = true ; $ files = self :... | Recursively copy directory in filesystem . |
22,463 | public static function move ( $ source , $ target ) { if ( ! file_exists ( $ source ) || ! is_dir ( $ source ) ) { throw new \ RuntimeException ( 'Cannot move non-existing folder.' ) ; } if ( $ source === $ target ) { return ; } if ( file_exists ( $ target ) ) { throw new \ RuntimeException ( 'Cannot move files to exis... | Move directory in filesystem . |
22,464 | public static function delete ( $ target , $ include_target = true ) { if ( ! is_dir ( $ target ) ) { return false ; } $ success = self :: doDelete ( $ target , $ include_target ) ; if ( ! $ success ) { $ error = error_get_last ( ) ; throw new \ RuntimeException ( $ error [ 'message' ] ) ; } if ( $ include_target ) { @... | Recursively delete directory from filesystem . |
22,465 | public static function rcopy ( $ src , $ dest ) { if ( ! is_dir ( $ src ) ) { copy ( $ src , $ dest ) ; return true ; } if ( ! is_dir ( $ dest ) ) { static :: create ( $ dest ) ; } $ i = new \ DirectoryIterator ( $ src ) ; foreach ( $ i as $ f ) { if ( $ f -> isFile ( ) ) { copy ( $ f -> getRealPath ( ) , "{$dest}/" . ... | Recursive copy of one directory to another |
22,466 | public static function setMethod ( $ method = 'auto' ) { if ( ! \ in_array ( $ method , [ 'auto' , 'curl' , 'fopen' ] , true ) ) { $ method = 'auto' ; } self :: $ method = $ method ; return new self ( ) ; } | Sets the preferred method to use for making HTTP calls . |
22,467 | public static function progress ( ) { static $ filesize = null ; $ args = func_get_args ( ) ; $ isCurlResource = is_resource ( $ args [ 0 ] ) && get_resource_type ( $ args [ 0 ] ) === 'curl' ; $ notification_code = ! $ isCurlResource ? $ args [ 0 ] : false ; $ bytes_transferred = $ isCurlResource ? $ args [ 2 ] : $ arg... | Progress normalized for cURL and Fopen Accepts a variable length of arguments passed in by stream method |
22,468 | private static function getAuto ( ) { if ( ! ini_get ( 'open_basedir' ) && self :: isFopenAvailable ( ) ) { return self :: getFopen ( func_get_args ( ) ) ; } if ( self :: isCurlAvailable ( ) ) { return self :: getCurl ( func_get_args ( ) ) ; } return null ; } | Automatically picks the preferred method |
22,469 | private static function getFopen ( ) { if ( \ count ( $ args = func_get_args ( ) ) === 1 ) { $ args = $ args [ 0 ] ; } $ uri = $ args [ 0 ] ; $ options = $ args [ 1 ] ?? [ ] ; $ callback = $ args [ 2 ] ?? null ; if ( $ callback ) { $ options [ 'fopen' ] [ 'notification' ] = [ 'self' , 'progress' ] ; } if ( isset ( $ op... | Starts a HTTP request via fopen |
22,470 | private static function getCurl ( ) { $ args = func_get_args ( ) ; $ args = count ( $ args ) > 1 ? $ args : array_shift ( $ args ) ; $ uri = $ args [ 0 ] ; $ options = $ args [ 1 ] ?? [ ] ; $ callback = $ args [ 2 ] ?? null ; $ ch = curl_init ( $ uri ) ; $ response = static :: curlExecFollow ( $ ch , $ options , $ call... | Starts a HTTP request via cURL |
22,471 | public function getParam ( $ param ) { $ value = $ this -> getGravParam ( $ param ) ; if ( $ value === null ) { $ value = $ this -> getQueryParam ( $ param ) ; } return $ value ; } | Return value of the parameter looking into both Grav parameters and query parameters . |
22,472 | public function initializeLocator ( UniformResourceLocator $ locator ) { $ locator -> reset ( ) ; $ schemes = ( array ) $ this -> get ( 'streams.schemes' , [ ] ) ; foreach ( $ schemes as $ scheme => $ config ) { if ( isset ( $ config [ 'paths' ] ) ) { $ locator -> addPath ( $ scheme , '' , $ config [ 'paths' ] ) ; } $ ... | Initialize resource locator by using the configuration . |
22,473 | public function getStreams ( ) { $ schemes = [ ] ; foreach ( ( array ) $ this -> get ( 'streams.schemes' ) as $ scheme => $ config ) { $ type = $ config [ 'type' ] ?? 'ReadOnlyStream' ; if ( $ type [ 0 ] !== '\\' ) { $ type = '\\RocketTheme\\Toolbox\\StreamWrapper\\' . $ type ; } $ schemes [ $ scheme ] = $ type ; } ret... | Get available streams and their types from the configuration . |
22,474 | public function init ( Grav $ grav ) { $ this -> config = $ grav [ 'config' ] ; $ this -> now = time ( ) ; if ( null === $ this -> enabled ) { $ this -> enabled = ( bool ) $ this -> config -> get ( 'system.cache.enabled' ) ; } $ uri = $ grav [ 'uri' ] ; $ prefix = $ this -> config -> get ( 'system.cache.prefix' ) ; $ u... | Initialization that sets a base key and the driver based on configuration settings |
22,475 | public function purgeOldCache ( ) { $ cache_dir = dirname ( $ this -> cache_dir ) ; $ current = basename ( $ this -> cache_dir ) ; $ count = 0 ; foreach ( new \ DirectoryIterator ( $ cache_dir ) as $ file ) { $ dir = $ file -> getBasename ( ) ; if ( $ dir === $ current || $ file -> isDot ( ) || $ file -> isFile ( ) ) {... | Deletes the old out of date file - based caches |
22,476 | public function save ( $ id , $ data , $ lifetime = null ) { if ( $ this -> enabled ) { if ( $ lifetime === null ) { $ lifetime = $ this -> getLifetime ( ) ; } $ this -> driver -> save ( $ id , $ data , $ lifetime ) ; } } | Stores a new cached entry . |
22,477 | public static function clearCache ( $ remove = 'standard' ) { $ locator = Grav :: instance ( ) [ 'locator' ] ; $ output = [ ] ; $ user_config = USER_DIR . 'config/system.yaml' ; switch ( $ remove ) { case 'all' : $ remove_paths = self :: $ all_remove ; break ; case 'assets-only' : $ remove_paths = self :: $ assets_remo... | Helper method to clear all Grav caches |
22,478 | public function setLifetime ( $ future ) { if ( ! $ future ) { return ; } $ interval = $ future - $ this -> now ; if ( $ interval > 0 && $ interval < $ this -> getLifetime ( ) ) { $ this -> lifetime = $ interval ; } } | Set the cache lifetime programmatically |
22,479 | public static function encode ( $ bytes ) { $ i = 0 ; $ index = 0 ; $ base32 = '' ; $ bytesLen = \ strlen ( $ bytes ) ; while ( $ i < $ bytesLen ) { $ currByte = \ ord ( $ bytes [ $ i ] ) ; if ( $ index > 3 ) { if ( ( $ i + 1 ) < $ bytesLen ) { $ nextByte = \ ord ( $ bytes [ $ i + 1 ] ) ; } else { $ nextByte = 0 ; } $ ... | Encode in Base32 |
22,480 | public static function decode ( $ base32 ) { $ bytes = [ ] ; $ base32Len = \ strlen ( $ base32 ) ; $ base32LookupLen = \ count ( self :: $ base32Lookup ) ; for ( $ i = $ base32Len * 5 / 8 - 1 ; $ i >= 0 ; -- $ i ) { $ bytes [ ] = 0 ; } for ( $ i = 0 , $ index = 0 , $ offset = 0 ; $ i < $ base32Len ; $ i ++ ) { $ lookup... | Decode in Base32 |
22,481 | public function copy ( ) { $ list = [ ] ; foreach ( $ this -> getIterator ( ) as $ key => $ value ) { $ list [ $ key ] = \ is_object ( $ value ) ? clone $ value : $ value ; } return $ this -> createFrom ( $ list ) ; } | Create a copy from this collection by cloning all objects in the collection . |
22,482 | public function group ( $ property ) { $ list = [ ] ; foreach ( $ this -> getIterator ( ) as $ element ) { $ list [ ( string ) $ element -> getProperty ( $ property ) ] [ ] = $ element ; } return $ list ; } | Group items in the collection by a field and return them as associated array . |
22,483 | public function collectionGroup ( $ property ) { $ collections = [ ] ; foreach ( $ this -> group ( $ property ) as $ id => $ elements ) { $ collection = $ this -> createFrom ( $ elements ) ; $ collections [ $ id ] = $ collection ; } return $ collections ; } | Group items in the collection by a field and return them as associated array of collections . |
22,484 | public function getPathFromKey ( string $ key ) : string { return sprintf ( $ this -> dataPattern , $ this -> dataFolder , $ key , substr ( $ key , 0 , 2 ) ) ; } | Get filesystem path from the key . |
22,485 | public function addPage ( PageInterface $ page ) { $ this -> items [ $ page -> path ( ) ] = [ 'slug' => $ page -> slug ( ) ] ; return $ this ; } | Add a single page to a collection |
22,486 | public function intersect ( Collection $ collection ) { $ array1 = $ this -> items ; $ array2 = $ collection -> toArray ( ) ; $ this -> items = array_uintersect ( $ array1 , $ array2 , function ( $ val1 , $ val2 ) { return strcmp ( $ val1 [ 'slug' ] , $ val2 [ 'slug' ] ) ; } ) ; return $ this ; } | Intersect another collection with the current collection |
22,487 | public function batch ( $ size ) { $ chunks = array_chunk ( $ this -> items , $ size , true ) ; $ list = [ ] ; foreach ( $ chunks as $ chunk ) { $ list [ ] = new static ( $ chunk , $ this -> params , $ this -> pages ) ; } return $ list ; } | Split collection into array of smaller collections . |
22,488 | public function remove ( $ key = null ) { if ( $ key instanceof PageInterface ) { $ key = $ key -> path ( ) ; } elseif ( null === $ key ) { $ key = ( string ) key ( $ this -> items ) ; } if ( ! \ is_string ( $ key ) ) { throw new \ InvalidArgumentException ( 'Invalid argument $key.' ) ; } parent :: remove ( $ key ) ; r... | Remove item from the list . |
22,489 | public function order ( $ by , $ dir = 'asc' , $ manual = null , $ sort_flags = null ) { $ this -> items = $ this -> pages -> sortCollection ( $ this , $ by , $ dir , $ manual , $ sort_flags ) ; return $ this ; } | Reorder collection . |
22,490 | public function isLast ( $ path ) { return $ this -> items && $ path === array_keys ( $ this -> items ) [ \ count ( $ this -> items ) - 1 ] ; } | Check to see if this item is the last in the collection . |
22,491 | public function visible ( ) { $ visible = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && $ page -> visible ( ) ) { $ visible [ $ path ] = $ slug ; } } $ this -> items = $ visible ; return $ this ; } | Creates new collection with only visible pages |
22,492 | public function modular ( ) { $ modular = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && $ page -> modular ( ) ) { $ modular [ $ path ] = $ slug ; } } $ this -> items = $ modular ; return $ this ; } | Creates new collection with only modular pages |
22,493 | public function published ( ) { $ published = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && $ page -> published ( ) ) { $ published [ $ path ] = $ slug ; } } $ this -> items = $ published ; return $ this ; } | Creates new collection with only published pages |
22,494 | public function routable ( ) { $ routable = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && $ page -> routable ( ) ) { $ routable [ $ path ] = $ slug ; } } $ this -> items = $ routable ; return $ this ; } | Creates new collection with only routable pages |
22,495 | public function ofType ( $ type ) { $ items = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && $ page -> template ( ) === $ type ) { $ items [ $ path ] = $ slug ; } } $ this -> items = $ items ; return $ this ; } | Creates new collection with only pages of the specified type |
22,496 | public function ofOneOfTheseTypes ( $ types ) { $ items = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && \ in_array ( $ page -> template ( ) , $ types , true ) ) { $ items [ $ path ] = $ slug ; } } $ this -> items = $ items ; return $ this ; ... | Creates new collection with only pages of one of the specified types |
22,497 | public function ofOneOfTheseAccessLevels ( $ accessLevels ) { $ items = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null && isset ( $ page -> header ( ) -> access ) ) { if ( \ is_array ( $ page -> header ( ) -> access ) ) { $ valid = false ; forea... | Creates new collection with only pages of one of the specified access levels |
22,498 | public function toExtendedArray ( ) { $ items = [ ] ; foreach ( $ this -> items as $ path => $ slug ) { $ page = $ this -> pages -> get ( $ path ) ; if ( $ page !== null ) { $ items [ $ page -> route ( ) ] = $ page -> toArray ( ) ; } } return $ items ; } | Get the extended version of this Collection with each page keyed by route |
22,499 | public static function getObjectFieldValue ( $ object , $ field ) { $ op = $ value = null ; $ pos = strpos ( $ field , '(' ) ; if ( false !== $ pos ) { list ( $ op , $ field ) = explode ( '(' , $ field , 2 ) ; $ field = rtrim ( $ field , ')' ) ; } if ( isset ( $ object [ $ field ] ) ) { $ value = $ object [ $ field ] ;... | Accesses the field of a given object . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.