idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
35,400
protected function create_imagefile_preview ( stored_file $ file , $ mode ) { global $ CFG ; require_once ( $ CFG -> libdir . '/gdlib.php' ) ; if ( $ mode === 'tinyicon' ) { $ data = $ file -> generate_image_thumbnail ( 24 , 24 ) ; } else if ( $ mode === 'thumb' ) { $ data = $ file -> generate_image_thumbnail ( 90 , 90...
Generates a preview for the stored image file
35,401
public function get_file_by_id ( $ fileid ) { global $ DB ; $ sql = "SELECT " . self :: instance_sql_fields ( 'f' , 'r' ) . " FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.id = ?" ; if ( $ filerecord = $ DB -> get_reco...
Fetch file using local file id .
35,402
public function get_file_by_hash ( $ pathnamehash ) { global $ DB ; $ sql = "SELECT " . self :: instance_sql_fields ( 'f' , 'r' ) . " FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.pathnamehash = ?" ; if ( $ filerecord ...
Fetch file using local file full pathname hash
35,403
public function get_file ( $ contextid , $ component , $ filearea , $ itemid , $ filepath , $ filename ) { $ filepath = clean_param ( $ filepath , PARAM_PATH ) ; $ filename = clean_param ( $ filename , PARAM_FILE ) ; if ( $ filename === '' ) { $ filename = '.' ; } $ pathnamehash = $ this -> get_pathname_hash ( $ contex...
Fetch locally stored file .
35,404
public function get_external_files ( $ repositoryid , $ sort = '' ) { global $ DB ; $ sql = "SELECT " . self :: instance_sql_fields ( 'f' , 'r' ) . " FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE r.repositoryid = ?" ; if...
Returns all files belonging to given repository
35,405
public function get_area_tree ( $ contextid , $ component , $ filearea , $ itemid ) { $ result = array ( 'dirname' => '' , 'dirfile' => null , 'subdirs' => array ( ) , 'files' => array ( ) ) ; $ files = $ this -> get_area_files ( $ contextid , $ component , $ filearea , $ itemid , '' , true ) ; foreach ( $ files as $ h...
Returns array based tree structure of area files
35,406
public function delete_area_files_select ( $ contextid , $ component , $ filearea , $ itemidstest , array $ params = null ) { global $ DB ; $ where = "contextid = :contextid AND component = :component AND filearea = :filearea AND itemid $itemidstest" ; $ params [ 'contextid'...
Delete all the files from certain areas where itemid is limited by an arbitrary bit of SQL .
35,407
public function delete_component_files ( $ component ) { global $ DB ; $ filerecords = $ DB -> get_recordset ( 'files' , array ( 'component' => $ component ) ) ; foreach ( $ filerecords as $ filerecord ) { $ this -> get_file_instance ( $ filerecord ) -> delete ( ) ; } $ filerecords -> close ( ) ; }
Delete all files associated with the given component .
35,408
public function move_area_files_to_new_context ( $ oldcontextid , $ newcontextid , $ component , $ filearea , $ itemid = false ) { $ count = 0 ; $ oldfiles = $ this -> get_area_files ( $ oldcontextid , $ component , $ filearea , $ itemid , 'id' , false ) ; foreach ( $ oldfiles as $ oldfile ) { $ filerecord = new stdCla...
Move all the files in a file area from one context to another .
35,409
public function create_directory ( $ contextid , $ component , $ filearea , $ itemid , $ filepath , $ userid = null ) { global $ DB ; if ( ! is_number ( $ contextid ) or $ contextid < 1 ) { throw new file_exception ( 'storedfileproblem' , 'Invalid contextid' ) ; } $ component = clean_param ( $ component , PARAM_COMPONE...
Recursively creates directory .
35,410
protected function create_file ( $ newrecord ) { global $ DB ; $ newrecord -> id = $ DB -> insert_record ( 'files' , $ newrecord ) ; if ( $ newrecord -> filename !== '.' ) { if ( $ pluginsfunction = get_plugins_with_function ( 'after_file_created' ) ) { foreach ( $ pluginsfunction as $ plugintype => $ plugins ) { forea...
Add new file record to database and handle callbacks .
35,411
public function synchronise_stored_file_from_file ( stored_file $ file , $ path , $ filerecord ) { list ( $ contenthash , $ filesize ) = $ this -> add_file_to_pool ( $ path , null , $ filerecord ) ; $ file -> set_synchronized ( $ contenthash , $ filesize ) ; }
Synchronise stored file from file .
35,412
public function synchronise_stored_file_from_string ( stored_file $ file , $ content , $ filerecord ) { list ( $ contenthash , $ filesize ) = $ this -> add_string_to_pool ( $ content , $ filerecord ) ; $ file -> set_synchronized ( $ contenthash , $ filesize ) ; }
Synchronise stored file from string .
35,413
public function add_file_to_pool ( $ pathname , $ contenthash = null , $ newrecord = null ) { $ this -> call_before_file_created_plugin_functions ( $ newrecord , $ pathname ) ; return $ this -> filesystem -> add_file_from_path ( $ pathname , $ contenthash ) ; }
Add file content to sha1 pool .
35,414
public function add_string_to_pool ( $ content , $ newrecord = null ) { $ this -> call_before_file_created_plugin_functions ( $ newrecord , null , $ content ) ; return $ this -> filesystem -> add_file_from_string ( $ content ) ; }
Add string content to sha1 pool .
35,415
protected function call_before_file_created_plugin_functions ( $ newrecord , $ pathname = null , $ content = null ) { $ pluginsfunction = get_plugins_with_function ( 'before_file_created' ) ; foreach ( $ pluginsfunction as $ plugintype => $ plugins ) { foreach ( $ plugins as $ pluginfunction ) { $ pluginfunction ( $ ne...
before_file_created hook .
35,416
public static function pack_reference ( $ params ) { $ params = ( array ) $ params ; $ reference = array ( ) ; $ reference [ 'contextid' ] = is_null ( $ params [ 'contextid' ] ) ? null : clean_param ( $ params [ 'contextid' ] , PARAM_INT ) ; $ reference [ 'component' ] = is_null ( $ params [ 'component' ] ) ? null : cl...
When user referring to a moodle file we build the reference field
35,417
public static function unpack_reference ( $ str , $ cleanparams = false ) { $ decoded = base64_decode ( $ str , true ) ; if ( $ decoded === false ) { throw new file_reference_exception ( null , $ str , null , null , 'Invalid base64 format' ) ; } $ params = @ unserialize ( $ decoded ) ; if ( $ params === false ) { throw...
Unpack reference field
35,418
public function search_server_files ( $ query , $ from = 0 , $ limit = 20 , $ count = false ) { global $ DB ; $ params = array ( 'contextlevel' => CONTEXT_USER , 'directory' => '.' , 'query' => $ query ) ; if ( $ count ) { $ select = 'COUNT(1)' ; } else { $ select = self :: instance_sql_fields ( 'f' , 'r' ) ; } $ like ...
Search through the server files .
35,419
public function search_references ( $ reference ) { global $ DB ; if ( is_null ( $ reference ) ) { throw new coding_exception ( 'NULL is not a valid reference to an external file' ) ; } self :: unpack_reference ( $ reference ) ; $ referencehash = sha1 ( $ reference ) ; $ sql = "SELECT " . self :: instance_sql_fields ( ...
Returns all aliases that refer to some stored_file via the given reference
35,420
public function search_references_count ( $ reference ) { global $ DB ; if ( is_null ( $ reference ) ) { throw new coding_exception ( 'NULL is not a valid reference to an external file' ) ; } self :: unpack_reference ( $ reference ) ; $ referencehash = sha1 ( $ reference ) ; $ sql = "SELECT COUNT(f.id) ...
Returns the number of aliases that refer to some stored_file via the given reference
35,421
public function get_references_by_storedfile ( stored_file $ storedfile ) { global $ DB ; $ params = array ( ) ; $ params [ 'contextid' ] = $ storedfile -> get_contextid ( ) ; $ params [ 'component' ] = $ storedfile -> get_component ( ) ; $ params [ 'filearea' ] = $ storedfile -> get_filearea ( ) ; $ params [ 'itemid' ...
Returns all aliases that link to the given stored_file
35,422
public function get_references_count_by_storedfile ( stored_file $ storedfile ) { global $ DB ; $ params = array ( ) ; $ params [ 'contextid' ] = $ storedfile -> get_contextid ( ) ; $ params [ 'component' ] = $ storedfile -> get_component ( ) ; $ params [ 'filearea' ] = $ storedfile -> get_filearea ( ) ; $ params [ 'it...
Returns the number of aliases that link to the given stored_file
35,423
public function update_references_to_storedfile ( stored_file $ storedfile ) { global $ CFG , $ DB ; $ params = array ( ) ; $ params [ 'contextid' ] = $ storedfile -> get_contextid ( ) ; $ params [ 'component' ] = $ storedfile -> get_component ( ) ; $ params [ 'filearea' ] = $ storedfile -> get_filearea ( ) ; $ params ...
Updates all files that are referencing this file with the new contenthash and filesize
35,424
public function import_external_file ( stored_file $ storedfile , $ maxbytes = 0 ) { global $ CFG ; $ storedfile -> import_external_file_contents ( $ maxbytes ) ; $ storedfile -> delete_reference ( ) ; return $ storedfile ; }
Convert file alias to local file
35,425
public static function mimetype ( $ fullpath , $ filename = null ) { if ( empty ( $ filename ) ) { $ filename = $ fullpath ; } $ type = mimeinfo ( 'type' , $ filename ) ; if ( $ type === 'document/unknown' ) { $ type = self :: mimetype_from_file ( $ fullpath ) ; } return $ type ; }
Return mimetype by given file pathname .
35,426
public static function mimetype_from_file ( $ fullpath ) { if ( file_exists ( $ fullpath ) ) { $ finfo = new finfo ( FILEINFO_MIME_TYPE ) ; return mimeinfo_from_type ( 'type' , $ finfo -> file ( $ fullpath ) ) ; } return 'document/unknown' ; }
Inspect a file on disk for it s mimetype .
35,427
public function update_references ( $ referencefileid , $ lastsync , $ lifetime , $ contenthash , $ filesize , $ status , $ timemodified = null ) { global $ DB ; $ referencefileid = clean_param ( $ referencefileid , PARAM_INT ) ; $ lastsync = clean_param ( $ lastsync , PARAM_INT ) ; validate_param ( $ contenthash , PAR...
Updates a reference to the external resource and all files that use it
35,428
function toHtml ( ) { global $ CFG , $ PAGE ; $ this -> _generateId ( ) ; $ elementid = $ this -> getAttribute ( 'id' ) ; $ mainhtml = html_writer :: tag ( 'div' , $ this -> items [ $ this -> getValue ( ) ] -> mainhtml , array ( 'id' => $ elementid . '_items_main' , 'class' => 'formlistingmain' ) ) ; $ html = html_writ...
Returns HTML for listing form element .
35,429
public function execute ( $ image ) { $ width = $ this -> argument ( 0 ) -> value ( ) ; $ height = $ this -> argument ( 1 ) -> value ( ) ; $ constraints = $ this -> argument ( 2 ) -> type ( 'closure' ) -> value ( ) ; $ resized = $ image -> getSize ( ) -> resize ( $ width , $ height , $ constraints ) ; $ this -> modify ...
Resizes image dimensions
35,430
protected function modify ( $ image , $ dst_x , $ dst_y , $ src_x , $ src_y , $ dst_w , $ dst_h , $ src_w , $ src_h ) { $ modified = imagecreatetruecolor ( $ dst_w , $ dst_h ) ; $ resource = $ image -> getCore ( ) ; $ transIndex = imagecolortransparent ( $ resource ) ; if ( $ transIndex != - 1 ) { $ rgba = imagecolorsf...
Wrapper function for imagecopyresampled
35,431
public function execute ( $ image ) { switch ( $ image -> exif ( 'Orientation' ) ) { case 2 : $ image -> flip ( ) ; break ; case 3 : $ image -> rotate ( 180 ) ; break ; case 4 : $ image -> rotate ( 180 ) -> flip ( ) ; break ; case 5 : $ image -> rotate ( 270 ) -> flip ( ) ; break ; case 6 : $ image -> rotate ( 270 ) ; ...
Correct image orientation according to Exif data
35,432
public function canvas ( $ width , $ height , $ background = null ) { return $ this -> createDriver ( ) -> newImage ( $ width , $ height , $ background ) ; }
Creates an empty image canvas
35,433
public function execute ( $ image ) { $ gamma = $ this -> argument ( 0 ) -> type ( 'numeric' ) -> required ( ) -> value ( ) ; return imagegammacorrect ( $ image -> getCore ( ) , 1 , $ gamma ) ; }
Applies gamma correction to a given image
35,434
protected function processTiff ( ) { $ format = 'tiff' ; $ compression = \ Imagick :: COMPRESSION_UNDEFINED ; $ imagick = $ this -> image -> getCore ( ) ; $ imagick -> setFormat ( $ format ) ; $ imagick -> setImageFormat ( $ format ) ; $ imagick -> setCompression ( $ compression ) ; $ imagick -> setImageCompression ( $...
Processes and returns encoded image as TIFF string
35,435
protected function processPsd ( ) { $ format = 'psd' ; $ compression = \ Imagick :: COMPRESSION_UNDEFINED ; $ imagick = $ this -> image -> getCore ( ) ; $ imagick -> setFormat ( $ format ) ; $ imagick -> setImageFormat ( $ format ) ; $ imagick -> setCompression ( $ compression ) ; $ imagick -> setImageCompression ( $ c...
Processes and returns encoded image as PSD string
35,436
protected function processDataUrl ( ) { $ mime = $ this -> image -> mime ? $ this -> image -> mime : 'image/png' ; return sprintf ( 'data:%s;base64,%s' , $ mime , base64_encode ( $ this -> process ( $ this -> image , $ mime , $ this -> quality ) ) ) ; }
Processes and returns encoded image as data - url string
35,437
protected function setFormat ( $ format = null ) { if ( $ format == '' && $ this -> image instanceof Image ) { $ format = $ this -> image -> mime ; } $ this -> format = $ format ? $ format : 'jpg' ; return $ this ; }
Determines output format
35,438
protected function setQuality ( $ quality ) { $ quality = is_null ( $ quality ) ? 90 : $ quality ; $ quality = $ quality === 0 ? 1 : $ quality ; if ( $ quality < 0 || $ quality > 100 ) { throw new \ Intervention \ Image \ Exception \ InvalidArgumentException ( 'Quality must range from 0 to 100.' ) ; } $ this -> quality...
Determines output quality
35,439
public function encode ( $ image , $ format , $ quality ) { return $ this -> encoder -> process ( $ image , $ format , $ quality ) ; }
Encodes given image
35,440
public function execute ( $ image ) { $ width = $ this -> argument ( 0 ) -> type ( 'digit' ) -> required ( ) -> value ( ) ; $ height = $ this -> argument ( 1 ) -> type ( 'digit' ) -> value ( $ width ) ; $ constraints = $ this -> argument ( 2 ) -> type ( 'closure' ) -> value ( ) ; $ position = $ this -> argument ( 3 ) -...
Crops and resized an image at the same time
35,441
public function cloneCore ( $ core ) { $ width = imagesx ( $ core ) ; $ height = imagesy ( $ core ) ; $ clone = imagecreatetruecolor ( $ width , $ height ) ; imagealphablending ( $ clone , false ) ; imagesavealpha ( $ clone , true ) ; $ transparency = imagecolorallocatealpha ( $ clone , 0 , 0 , 0 , 127 ) ; imagefill ( ...
Returns clone of given core
35,442
public function relativePosition ( Size $ size ) { $ x = $ this -> pivot -> x - $ size -> pivot -> x ; $ y = $ this -> pivot -> y - $ size -> pivot -> y ; return new Point ( $ x , $ y ) ; }
Calculate the relative position to another Size based on the pivot point settings of both sizes .
35,443
public function fit ( Size $ size , $ position = 'center' ) { $ auto_height = clone $ size ; $ auto_height -> resize ( $ this -> width , null , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) ; if ( $ auto_height -> fitsInto ( $ this ) ) { $ size = $ auto_height ; } else { $ auto_width = clone $ size ...
Resize given Size to best fitting size of current size .
35,444
public function fitsInto ( Size $ size ) { return ( $ this -> width <= $ size -> width ) && ( $ this -> height <= $ size -> height ) ; }
Checks if given size fits into current size
35,445
public function align ( $ position , $ offset_x = 0 , $ offset_y = 0 ) { switch ( strtolower ( $ position ) ) { case 'top' : case 'top-center' : case 'top-middle' : case 'center-top' : case 'middle-top' : $ x = intval ( $ this -> width / 2 ) ; $ y = 0 + $ offset_y ; break ; case 'top-right' : case 'right-top' : $ x = $...
Aligns current size s pivot point to given position and moves point automatically by offset .
35,446
public function initFromImagick ( \ Imagick $ object ) { $ object = $ this -> removeAnimation ( $ object ) ; $ object -> setImageOrientation ( \ Imagick :: ORIENTATION_UNDEFINED ) ; return new Image ( new Driver , $ object ) ; }
Initiates new image from Imagick object
35,447
private function removeAnimation ( \ Imagick $ object ) { $ imagick = new \ Imagick ; foreach ( $ object as $ frame ) { $ imagick -> addImage ( $ frame -> getImage ( ) ) ; break ; } $ object -> destroy ( ) ; return $ imagick ; }
Turns object into one frame Imagick object by removing all frames except first
35,448
public function execute ( $ image ) { $ colors = [ ] ; $ size = $ image -> getSize ( ) ; for ( $ x = 0 ; $ x <= ( $ size -> width - 1 ) ; $ x ++ ) { for ( $ y = 0 ; $ y <= ( $ size -> height - 1 ) ; $ y ++ ) { $ colors [ ] = $ image -> pickColor ( $ x , $ y , 'array' ) ; } } $ this -> setOutput ( md5 ( serialize ( $ co...
Calculates checksum of given image
35,449
public function execute ( $ image ) { $ width = $ this -> argument ( 0 ) -> type ( 'digit' ) -> required ( ) -> value ( ) ; $ additionalConstraints = $ this -> argument ( 1 ) -> type ( 'closure' ) -> value ( ) ; $ this -> arguments [ 0 ] = $ width ; $ this -> arguments [ 1 ] = null ; $ this -> arguments [ 2 ] = functio...
Resize image proportionally to given width
35,450
public function initFromUrl ( $ url ) { $ options = [ 'http' => [ 'method' => "GET" , 'header' => "Accept-language: en\r\n" . "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\n" ] ] ; $ context = stream_context_create ( $ options ) ; if ( $ data = @ file_...
Init from given URL
35,451
public function isFilePath ( ) { if ( is_string ( $ this -> data ) ) { try { return is_file ( $ this -> data ) ; } catch ( \ Exception $ e ) { return false ; } } return false ; }
Determines if current source data is file path
35,452
public function isDataUrl ( ) { $ data = $ this -> decodeDataUrl ( $ this -> data ) ; return is_null ( $ data ) ? false : true ; }
Determines if current source data is data - url
35,453
public function isBase64 ( ) { if ( ! is_string ( $ this -> data ) ) { return false ; } return base64_encode ( base64_decode ( $ this -> data ) ) === $ this -> data ; }
Determines if current source data is base64 encoded
35,454
private function decodeDataUrl ( $ data_url ) { if ( ! is_string ( $ data_url ) ) { return null ; } $ pattern = "/^data:(?:image\/[a-zA-Z\-\.]+)(?:charset=\".+\")?;base64,(?P<data>.+)$/" ; preg_match ( $ pattern , $ data_url , $ matches ) ; if ( is_array ( $ matches ) && array_key_exists ( 'data' , $ matches ) ) { retu...
Parses and decodes binary image data from data - url
35,455
public function init ( $ data ) { $ this -> data = $ data ; switch ( true ) { case $ this -> isGdResource ( ) : return $ this -> initFromGdResource ( $ this -> data ) ; case $ this -> isImagick ( ) : return $ this -> initFromImagick ( $ this -> data ) ; case $ this -> isInterventionImage ( ) : return $ this -> initFrom...
Initiates new image from mixed data
35,456
public function format ( $ type ) { switch ( strtolower ( $ type ) ) { case 'rgba' : return $ this -> getRgba ( ) ; case 'hex' : return $ this -> getHex ( '#' ) ; case 'int' : case 'integer' : return $ this -> getInt ( ) ; case 'array' : return $ this -> getArray ( ) ; case 'obj' : case 'object' : return $ this ; defau...
Formats current color instance into given format
35,457
public function execute ( $ image ) { $ backupName = $ this -> argument ( 0 ) -> value ( ) ; $ clone = clone $ image ; $ image -> setBackup ( $ clone -> getCore ( ) , $ backupName ) ; return true ; }
Saves a backups of current state of image core
35,458
public function border ( $ width , $ color = null ) { $ this -> border_width = is_numeric ( $ width ) ? intval ( $ width ) : 0 ; $ this -> border_color = is_null ( $ color ) ? '#000000' : $ color ; }
Set border width and color of current shape
35,459
public function execute ( $ image ) { $ width = $ this -> argument ( 0 ) -> type ( 'digit' ) -> required ( ) -> value ( ) ; $ height = $ this -> argument ( 1 ) -> type ( 'digit' ) -> required ( ) -> value ( ) ; $ x = $ this -> argument ( 2 ) -> type ( 'digit' ) -> value ( ) ; $ y = $ this -> argument ( 3 ) -> type ( 'd...
Crop an image instance
35,460
public function execute ( $ image ) { $ format = $ this -> argument ( 0 ) -> value ( ) ; $ quality = $ this -> argument ( 1 ) -> between ( 0 , 100 ) -> value ( ) ; $ response = new Response ( $ image , $ format , $ quality ) ; $ this -> setOutput ( $ response -> make ( ) ) ; return true ; }
Builds HTTP response from given image
35,461
public function basePath ( ) { if ( $ this -> dirname && $ this -> basename ) { return ( $ this -> dirname . '/' . $ this -> basename ) ; } return null ; }
Get fully qualified path
35,462
public static function canvas ( $ width , $ height , $ background = null ) { return self :: getManager ( ) -> canvas ( $ width , $ height , $ background ) ; }
Statically creates an empty image canvas
35,463
public static function cache ( Closure $ callback , $ lifetime = null , $ returnObj = false ) { return self :: getManager ( ) -> cache ( $ callback , $ lifetime , $ returnObj ) ; }
Create new cached image and run callback statically
35,464
public function applyToImage ( Image $ image , $ x = 0 , $ y = 0 ) { return parent :: applyToImage ( $ image , $ x , $ y ) ; }
Draw current circle on given image
35,465
private function formatPoints ( $ points ) { $ ipoints = [ ] ; $ count = 1 ; foreach ( $ points as $ key => $ value ) { if ( $ count % 2 === 0 ) { $ y = $ value ; $ ipoints [ ] = [ 'x' => $ x , 'y' => $ y ] ; } else { $ x = $ value ; } $ count ++ ; } return $ ipoints ; }
Format polygon points to Imagick format
35,466
public function gdResourceToTruecolor ( & $ resource ) { $ width = imagesx ( $ resource ) ; $ height = imagesy ( $ resource ) ; $ canvas = imagecreatetruecolor ( $ width , $ height ) ; imagealphablending ( $ canvas , false ) ; $ transparent = imagecolorallocatealpha ( $ canvas , 255 , 255 , 255 , 127 ) ; imagefilledrec...
Transform GD resource into Truecolor version
35,467
public function getCommandName ( ) { preg_match ( "/\\\\([\w]+)Command$/" , get_class ( $ this -> command ) , $ matches ) ; return isset ( $ matches [ 1 ] ) ? lcfirst ( $ matches [ 1 ] ) . '()' : 'Method' ; }
Returns name of current arguments command
35,468
public function value ( $ default = null ) { $ arguments = $ this -> command -> arguments ; if ( is_array ( $ arguments ) ) { return isset ( $ arguments [ $ this -> key ] ) ? $ arguments [ $ this -> key ] : $ default ; } return $ default ; }
Returns value of current argument
35,469
public function encode ( $ format = null , $ quality = 90 ) { return $ this -> driver -> encode ( $ this , $ format , $ quality ) ; }
Starts encoding of current image
35,470
public function save ( $ path = null , $ quality = null ) { $ path = is_null ( $ path ) ? $ this -> basePath ( ) : $ path ; if ( is_null ( $ path ) ) { throw new Exception \ NotWritableException ( "Can't write to undefined path." ) ; } $ data = $ this -> encode ( pathinfo ( $ path , PATHINFO_EXTENSION ) , $ quality ) ;...
Saves encoded image in filesystem
35,471
private function garbageCollect ( ) { $ this -> setDefaultValueBinder ( ) ; unset ( $ this -> sheetImports , $ this -> spreadsheet ) ; $ this -> currentFile -> delete ( ) ; }
Garbage collect .
35,472
public function registerListeners ( array $ listeners ) { foreach ( $ listeners as $ event => $ listener ) { $ this -> events [ $ event ] [ ] = $ listener ; } }
Register local event listeners .
35,473
protected function bindToLaravelApp ( ) { $ this -> bindSandbox ( ) ; $ this -> bindSwooleTable ( ) ; if ( $ this -> isServerWebsocket ) { $ this -> bindRoom ( ) ; $ this -> bindWebsocket ( ) ; } }
Set bindings to Laravel app .
35,474
protected function createPidFile ( ) { $ pidFile = $ this -> getPidFile ( ) ; $ pid = $ this -> container -> make ( Server :: class ) -> master_pid ; file_put_contents ( $ pidFile , $ pid ) ; }
Create pid file .
35,475
public function addProcess ( Process $ process ) : void { $ this -> container -> make ( Server :: class ) -> addProcess ( $ process ) ; }
Add process to http server
35,476
protected function isAsyncTaskPayload ( $ payload ) : bool { $ data = json_decode ( $ payload , true ) ; if ( JSON_ERROR_NONE !== json_last_error ( ) ) { return false ; } return isset ( $ data [ 'job' ] ) ; }
Indicates if the payload is async task .
35,477
public function initialize ( ) { if ( ! $ this -> app instanceof Container ) { throw new SandboxException ( 'A base app has not been set.' ) ; } $ this -> setInitialConfig ( ) ; $ this -> setInitialProviders ( ) ; $ this -> setInitialResetters ( ) ; return $ this ; }
Initialize based on base app .
35,478
public function run ( Request $ request ) { if ( ! $ this -> getSnapshot ( ) instanceof Container ) { throw new SandboxException ( 'Sandbox is not enabled.' ) ; } $ shouldUseOb = $ this -> config -> get ( 'swoole_http.ob_output' , true ) ; if ( $ shouldUseOb ) { return $ this -> prepareObResponse ( $ request ) ; } retu...
Run framework .
35,479
protected function prepareResponse ( Request $ request ) { $ response = $ this -> handleRequest ( $ request ) ; $ this -> terminate ( $ request , $ response ) ; return $ response ; }
Handle request for non - ob case .
35,480
protected function prepareObResponse ( Request $ request ) { ob_start ( ) ; $ response = $ this -> handleRequest ( $ request ) ; $ content = '' ; $ isFile = false ; if ( $ isStream = $ response instanceof StreamedResponse ) { $ response -> sendContent ( ) ; } elseif ( $ response instanceof SymfonyResponse ) { $ content...
Handle request for ob output .
35,481
protected function handleRequest ( Request $ request ) { if ( $ this -> isLaravel ( ) ) { return $ this -> getKernel ( ) -> handle ( $ request ) ; } return $ this -> getApplication ( ) -> dispatch ( $ request ) ; }
Handle request through Laravel or Lumen .
35,482
public function enable ( ) { if ( ! $ this -> config instanceof ConfigContract ) { throw new SandboxException ( 'Please initialize after setting base app.' ) ; } $ this -> setInstance ( $ app = $ this -> getApplication ( ) ) ; $ this -> resetApp ( $ app ) ; }
Set laravel snapshot to container and facade .
35,483
public function setInstance ( Container $ app ) { $ app -> instance ( 'app' , $ app ) ; $ app -> instance ( Container :: class , $ app ) ; if ( $ this -> framework === 'lumen' ) { $ app -> instance ( LumenApplication :: class , $ app ) ; } Container :: setInstance ( $ app ) ; Context :: setApp ( $ app ) ; Facade :: cle...
Replace app s self bindings .
35,484
public static function from ( $ filename ) { $ extension = strtok ( pathinfo ( $ filename , PATHINFO_EXTENSION ) , '?' ) ; return self :: getMimeTypeFromExtension ( $ extension ) ; }
Get the MIME type for a file based on the file s extension .
35,485
protected function setInitialProviders ( ) { $ app = $ this -> getBaseApp ( ) ; $ providers = $ this -> config -> get ( 'swoole_http.providers' , [ ] ) ; foreach ( $ providers as $ provider ) { if ( class_exists ( $ provider ) && ! in_array ( $ provider , $ this -> providers ) ) { $ providerClass = new $ provider ( $ a...
Initialize customized service providers .
35,486
public function push ( $ payload ) : void { if ( ! $ this -> broadcast && $ this -> sender && ! $ this -> hasDescriptor ( $ this -> sender ) ) { $ this -> addDescriptor ( $ this -> sender ) ; } if ( $ this -> shouldBroadcast ( ) ) { $ this -> addDescriptors ( $ this -> getWebsocketConnections ( ) ) ; } foreach ( $ this...
Push message to related descriptors
35,487
public static function version ( string $ expression = self :: VERSION_WITHOUT_BUG_FIX ) : string { if ( static :: is ( static :: LARAVEL ) ) { return static :: extractVersion ( constant ( 'Illuminate\Foundation\Application::VERSION' ) , $ expression ) ; } $ app = call_user_func ( 'Laravel\Lumen\Application::getInstanc...
Returns application version
35,488
public function handle ( $ server , $ frame ) { $ packet = $ frame -> data ; $ packetLength = strlen ( $ packet ) ; $ payload = '' ; if ( Packet :: getPayload ( $ packet ) ) { return false ; } if ( $ isPing = Packet :: isSocketType ( $ packet , 'ping' ) ) { $ payload .= Packet :: PONG ; } if ( $ isPing && $ packetLengt...
If return value is true will skip decoding .
35,489
protected function isSwooleQueuePacket ( $ packet ) { if ( ! is_string ( $ packet ) ) { return false ; } $ decoded = json_decode ( $ packet , true ) ; return JSON_ERROR_NONE === json_last_error ( ) && isset ( $ decoded [ 'job' ] ) ; }
Indicates if a packet is swoole s queue job .
35,490
protected function configureSwooleServer ( ) { $ config = $ this -> app -> make ( 'config' ) ; $ options = $ config -> get ( 'swoole_http.server.options' ) ; if ( $ config -> get ( 'queue.default' ) !== 'swoole' && ! $ this -> isWebsocket ) { unset ( $ options [ 'task_worker_num' ] ) ; } static :: $ server -> set ( $ o...
Set swoole server configurations .
35,491
protected function registerDatabaseDriver ( ) { $ this -> app -> extend ( DatabaseManager :: class , function ( DatabaseManager $ db ) { $ db -> extend ( 'mysql-coroutine' , function ( $ config , $ name ) { $ config [ 'name' ] = $ name ; $ connection = new MySqlConnection ( $ this -> getNewMySqlConnection ( $ config , ...
Register database driver for coroutine mysql .
35,492
protected function getNewMySqlConnection ( array $ config , string $ connection = null ) { if ( $ connection && isset ( $ config [ $ connection ] ) ) { $ config = array_merge ( $ config , $ config [ $ connection ] ) ; } return ConnectorFactory :: make ( FW :: version ( ) ) -> connect ( $ config ) ; }
Get a new mysql connection .
35,493
protected function registerSwooleQueueDriver ( ) { $ this -> app -> afterResolving ( 'queue' , function ( QueueManager $ manager ) { $ manager -> addConnector ( 'swoole' , function ( ) { return new SwooleTaskConnector ( $ this -> app -> make ( Server :: class ) ) ; } ) ; } ) ; }
Register queue driver for swoole async task .
35,494
public function decode ( $ frame ) { $ data = json_decode ( $ frame -> data , true ) ; return [ 'event' => $ data [ 'event' ] ?? null , 'data' => $ data [ 'data' ] ?? null , ] ; }
Input message on websocket connected . Define and return event name and payload data here .
35,495
protected function initRoomsTable ( ) : void { $ this -> rooms = new Table ( $ this -> config [ 'room_rows' ] ) ; $ this -> rooms -> column ( 'value' , Table :: TYPE_STRING , $ this -> config [ 'room_size' ] ) ; $ this -> rooms -> create ( ) ; }
Init rooms table
35,496
protected function initFdsTable ( ) { $ this -> fds = new Table ( $ this -> config [ 'client_rows' ] ) ; $ this -> fds -> column ( 'value' , Table :: TYPE_STRING , $ this -> config [ 'client_size' ] ) ; $ this -> fds -> create ( ) ; }
Init descriptors table
35,497
public function setValue ( $ key , array $ value , string $ table ) { $ this -> checkTable ( $ table ) ; $ this -> $ table -> set ( $ key , [ 'value' => json_encode ( $ value ) ] ) ; return $ this ; }
Set value to table
35,498
public function getValue ( string $ key , string $ table ) { $ this -> checkTable ( $ table ) ; $ value = $ this -> $ table -> get ( $ key ) ; return $ value ? json_decode ( $ value [ 'value' ] , true ) : [ ] ; }
Get value from table
35,499
protected function checkTable ( string $ table ) { if ( ! property_exists ( $ this , $ table ) || ! $ this -> $ table instanceof Table ) { throw new \ InvalidArgumentException ( "Invalid table name: `{$table}`." ) ; } }
Check table for exists