idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
700 | public function splice ( $ offset , $ length = null , $ replacement = [ ] ) { if ( func_num_args ( ) == 1 ) { return new DataStore ( array_splice ( $ this -> rows , $ offset ) , $ this -> metaData ) ; } return new DataStore ( array_splice ( $ this -> rows , $ offset , $ length , $ replacement ) , $ this -> metaData ) ; } | Splice the data and replace |
701 | public function where ( $ key , $ value ) { $ dstore = new DataStore ; $ dstore -> meta ( $ this -> metaData ) ; foreach ( $ this -> rows as $ row ) { if ( $ row [ $ key ] == $ value ) { $ dstore -> append ( $ row ) ; } } return $ dstore ; } | Return rows that has column equal to certain value |
702 | public function whereIn ( $ key , $ values = array ( ) ) { $ dstore = new DataStore ; $ dstore -> meta ( $ this -> metaData ) ; foreach ( $ this -> rows as $ row ) { if ( in_array ( $ row [ $ key ] , $ values ) ) { $ dstore -> append ( $ row ) ; } } return $ dstore ; } | Return rows that column contains value in an array . |
703 | private function _mapKeyIndex ( $ arr , $ keys ) { $ maps = array ( ) ; foreach ( $ arr as $ index => $ row ) { $ key = "n" ; foreach ( $ keys as $ cName ) { $ key .= $ row [ $ cName ] ; } if ( ! isset ( $ maps [ $ key ] ) ) { $ maps [ $ key ] = array ( ) ; } array_push ( $ maps [ $ key ] , $ index ) ; } return $ maps ; } | Map Key Index |
704 | public function join ( $ secondStore , $ matching ) { $ dstore = new DataStore ; $ firstKeys = array_keys ( $ matching ) ; $ secondKeys = array_values ( $ matching ) ; $ firstMaps = $ this -> _mapKeyIndex ( $ this -> rows , $ firstKeys ) ; $ secondMaps = $ this -> _mapKeyIndex ( $ secondStore -> all ( ) , $ secondKeys ) ; foreach ( $ firstMaps as $ key => $ indices ) { if ( isset ( $ secondMaps [ $ key ] ) ) { foreach ( $ indices as $ i ) { foreach ( $ secondMaps [ $ key ] as $ j ) { $ dstore -> push ( array_merge ( $ this -> rows [ $ i ] , $ secondStore -> get ( $ j ) ) ) ; } } } } $ columnMeta = array_merge ( $ this -> metaData [ "columns" ] , $ secondStore -> meta ( ) [ "columns" ] ) ; $ dstore -> meta ( array ( "columns" => $ columnMeta ) ) ; return $ dstore ; } | Join with another datastore on a matching keys |
705 | public function leftJoin ( $ secondStore , $ matching ) { $ dstore = new DataStore ; $ firstKeys = array_keys ( $ matching ) ; $ secondKeys = array_values ( $ matching ) ; $ firstMaps = $ this -> _mapKeyIndex ( $ this -> rows , $ firstKeys ) ; $ secondMaps = $ this -> _mapKeyIndex ( $ secondStore -> all ( ) , $ secondKeys ) ; $ secondNullRow = array ( ) ; foreach ( $ secondStore -> first ( ) as $ k => $ v ) { $ secondNullRow [ $ k ] = null ; } foreach ( $ firstMaps as $ key => $ indices ) { foreach ( $ indices as $ i ) { if ( isset ( $ secondMaps [ $ key ] ) ) { foreach ( $ secondMaps [ $ key ] as $ j ) { $ dstore -> push ( array_merge ( $ this -> rows [ $ i ] , $ secondStore -> get ( $ j ) ) ) ; } } else { $ dstore -> push ( array_merge ( $ this -> rows [ $ i ] , $ secondNullRow ) ) ; } } } $ columnMeta = array_merge ( $ this -> metaData [ "columns" ] , $ secondStore -> meta ( ) [ "columns" ] ) ; $ dstore -> meta ( array ( "columns" => $ columnMeta ) ) ; return $ dstore ; } | Left join with another datastore on matching keys |
706 | public function columnMeta ( $ settings ) { foreach ( $ settings as $ cName => $ cMeta ) { if ( isset ( $ this -> metaData [ "columns" ] ) && $ this -> metaData [ "columns" ] [ $ cName ] ) { $ this -> metaData [ "columns" ] [ $ cName ] = array_merge ( $ this -> metaData [ "columns" ] [ $ cName ] , $ cMeta ) ; } } return $ this ; } | Add extra column meta to existing |
707 | public function offsetSet ( $ index , $ row ) { if ( is_null ( $ index ) ) { $ this -> rows [ ] = $ row ; } else { $ this -> rows [ $ index ] = $ row ; } } | Implement offsetSet for ArrayAccess interface |
708 | public function offsetGet ( $ index ) { return isset ( $ this -> rows [ $ index ] ) ? $ this -> rows [ $ index ] : null ; } | Implement offsetGet for ArrayAccess interface |
709 | public function publishAssetFolder ( $ fullLocalPath , $ version = "" ) { $ fullLocalPath = Utility :: standardizePathSeparator ( $ fullLocalPath ) ; $ fullLocalPath = Utility :: getSymbolicPath ( $ fullLocalPath ) ; $ assets = Utility :: get ( $ this -> report -> getSettings ( ) , "assets" ) ; $ document_root = Utility :: getDocumentRoot ( ) ; $ assetUrl = "" ; if ( ! $ assets ) { $ assetUrl = str_replace ( $ document_root , "" , $ fullLocalPath ) ; if ( $ assetUrl == $ fullLocalPath ) { $ script_folder = Utility :: standardizePathSeparator ( realpath ( dirname ( $ _SERVER [ "SCRIPT_FILENAME" ] ) ) ) ; $ asset_path = $ script_folder . "/koolreport_assets" ; $ asset_url = Utility :: str_replace_first ( $ document_root , "" , $ script_folder ) . "/koolreport_assets" ; if ( ! is_dir ( $ asset_path ) ) { mkdir ( $ asset_path , 0755 ) ; } $ assets = array ( "path" => $ asset_path , "url" => $ asset_url , ) ; $ assetUrl = "" ; } } if ( $ assets ) { $ targetAssetPath = Utility :: get ( $ assets , "path" ) ; $ targetAssetUrl = Utility :: get ( $ assets , "url" ) ; if ( ! $ targetAssetPath ) { throw new \ Exception ( "Could not find path to report's assets folder" ) ; } $ reportClassFolder = Utility :: standardizePathSeparator ( dirname ( Utility :: getClassPath ( $ this -> report ) ) ) ; if ( strpos ( $ targetAssetPath , "/" ) !== 0 && is_dir ( $ reportClassFolder . "/" . $ targetAssetPath ) ) { $ targetAssetPath = Utility :: standardizePathSeparator ( realpath ( $ reportClassFolder . "/" . $ targetAssetPath ) ) ; } else if ( is_dir ( $ targetAssetPath ) ) { $ targetAssetPath = Utility :: standardizePathSeparator ( realpath ( $ targetAssetPath ) ) ; } else { throw new \ Exception ( "Report's assets folder not existed" ) ; } $ objectFolderName = str_replace ( dirname ( $ fullLocalPath ) . "/" , "" , $ fullLocalPath ) ; $ objectHashFolderName = crc32 ( "koolreport" . $ fullLocalPath . @ filemtime ( $ fullLocalPath ) . $ this -> report -> version ( ) . $ version ) ; $ objectHashFolderName = ( $ objectHashFolderName < 0 ) ? abs ( $ objectHashFolderName ) . "0" : "$objectHashFolderName" ; $ objectTargetPath = $ targetAssetPath . "/" . $ objectHashFolderName ; if ( ! is_dir ( $ objectTargetPath ) ) { Utility :: recurse_copy ( $ fullLocalPath , $ objectTargetPath ) ; } else { } if ( $ targetAssetUrl ) { $ assetUrl = $ targetAssetUrl . "/" . $ objectHashFolderName ; } else { $ assetUrl = str_replace ( $ document_root , "" , $ objectTargetPath ) ; } } return $ assetUrl ; } | Copy private asset folder to public place and return public asset url |
710 | protected function addScriptFile ( $ src , $ options = array ( ) , $ at = "begin" ) { $ options [ "type" ] = Utility :: get ( $ options , "type" , "text/javascript" ) ; $ options [ "src" ] = $ src ; $ this -> tags [ md5 ( $ src ) ] = array ( "at" => $ at , "tag" => "script" , "options" => $ options , "content" => "" , ) ; return $ this ; } | Add script file to report |
711 | protected function addScript ( $ script , $ options = array ( ) , $ at = 'begin' ) { $ options [ "type" ] = Utility :: get ( $ options , "type" , "text/javascript" ) ; $ this -> tags [ md5 ( $ script ) ] = array ( "at" => $ at , "tag" => "script" , "options" => $ options , "content" => $ script , ) ; return $ this ; } | Add a custom script to the report |
712 | public function addStyle ( $ style , $ options = array ( ) ) { $ options [ "type" ] = Utility :: get ( $ options , "type" , "text/css" ) ; $ this -> tags [ md5 ( $ style ) ] = array ( "at" => 'begin' , "tag" => "style" , "options" => $ options , "content" => $ style , ) ; return $ this ; } | Adding a css style to report |
713 | public function addCssFile ( $ href , $ options = array ( ) ) { $ options [ "type" ] = Utility :: get ( $ options , "type" , "text/css" ) ; $ options [ "rel" ] = Utility :: get ( $ options , "rel" , "stylesheet" ) ; $ options [ "href" ] = $ href ; $ this -> tags [ md5 ( $ href ) ] = array ( "at" => 'begin' , "tag" => "link" , "options" => $ options , "content" => "" , ) ; return $ this ; } | Adding a css file to the report |
714 | public function addLinkTag ( $ options ) { $ unique = "u" ; foreach ( $ options as $ key => $ value ) { $ unique .= "[$key=$value]" ; } $ this -> tags [ md5 ( $ unique ) ] = array ( "at" => 'begin' , "tag" => "link" , "options" => $ options , "content" => "" , ) ; return $ this ; } | Add a link tag to the page |
715 | public function renderTag ( $ tag ) { $ str = "<" . $ tag [ "tag" ] ; foreach ( $ tag [ "options" ] as $ key => $ value ) { $ str .= " $key='$value'" ; } $ str .= ">" . $ tag [ "content" ] . "</" . $ tag [ "tag" ] . ">" ; return $ str ; } | Render a tag |
716 | public function process ( & $ content ) { $ begin = "" ; $ end = "" ; foreach ( $ this -> tags as $ tag ) { if ( $ tag [ "at" ] == "begin" ) { $ begin .= $ this -> renderTag ( $ tag ) ; } else { $ end .= $ this -> renderTag ( $ tag ) ; } } if ( $ begin !== '' ) { $ count = 0 ; $ content = preg_replace ( '/(<body\b[^>]*>)/is' , '$1<###begin###>' , $ content , 1 , $ count ) ; if ( $ count ) { $ content = str_replace ( '<###begin###>' , $ begin , $ content ) ; } else { $ content = $ begin . $ content ; } } if ( $ end !== '' ) { $ count = 0 ; $ content = preg_replace ( '/(<\\/body\s*>)/is' , '<###end###>$1' , $ content , 1 , $ count ) ; if ( $ count ) { $ content = str_replace ( '<###end###>' , $ end , $ content ) ; } else { $ content = $ content . $ end ; } } } | Take content of report and adds resource to content |
717 | public function pipe ( $ node ) { array_push ( $ this -> destinations , $ node ) ; $ node -> source ( $ this ) ; return $ node ; } | Add a new node that this node will send data to |
718 | public function previous ( $ index = 0 ) { if ( count ( $ this -> sources ) > 0 ) { return Utility :: get ( $ this -> sources , $ index ) ; } return null ; } | Get the previous source that send data to this node |
719 | public function next ( $ data ) { if ( $ this -> destinations != null ) { foreach ( $ this -> destinations as $ node ) { $ node -> input ( $ data , $ this ) ; } } } | Send data row to the next destinations |
720 | public function startInput ( $ source ) { $ this -> streamingSource = $ source ; $ this -> is_ended = false ; $ this -> onInputStart ( ) ; foreach ( $ this -> destinations as $ node ) { $ node -> startInput ( $ this ) ; } } | Receive signal from source node that this node will be about to receive data |
721 | public function endInput ( $ source ) { $ this -> streamingSource = $ source ; $ sourceAllEnded = true ; foreach ( $ this -> sources as $ src ) { $ sourceAllEnded &= $ src -> isEnded ( ) ; } if ( $ sourceAllEnded ) { $ this -> is_ended = true ; $ this -> onInputEnd ( ) ; foreach ( $ this -> destinations as $ node ) { $ node -> endInput ( $ this ) ; } } } | The source will call this method to tell that it finishes sending data |
722 | protected function sendMeta ( $ metaData ) { foreach ( $ this -> destinations as $ node ) { $ node -> receiveMeta ( $ metaData , $ this ) ; } } | Sending meta data to next nodes |
723 | public function receiveMeta ( $ metaData , $ source ) { $ this -> streamingSource = $ source ; $ this -> metaData = $ metaData ; $ metaData = $ this -> onMetaReceived ( $ metaData ) ; $ this -> sendMeta ( $ metaData ) ; } | Recieving meta data from the source |
724 | public function requestDataSending ( ) { if ( ! $ this -> isEnded ( ) ) { foreach ( $ this -> sources as $ source ) { $ source -> requestDataSending ( ) ; } } return $ this ; } | Request source nodes to send data . |
725 | public static function js ( ) { $ jsPath = dirname ( __FILE__ ) . "/clients/core/KoolReport.js" ; if ( is_file ( $ jsPath ) ) { return "<script type='text/javascript'>" . preg_replace ( '/\s+/S' , " " , file_get_contents ( $ jsPath ) ) . "</script>" ; } else { throw new \ Exception ( "Could not find KoolReport.js" ) ; } } | Return the javascript of KoolReport |
726 | public function registerEvent ( $ name , $ methodName , $ prepend = false ) { if ( ! isset ( $ this -> events [ $ name ] ) ) { $ this -> events [ $ name ] = array ( ) ; } if ( ! in_array ( $ methodName , $ this -> events [ $ name ] ) ) { if ( $ prepend ) { array_unshift ( $ this -> events [ $ name ] , $ methodName ) ; } else { array_push ( $ this -> events [ $ name ] , $ methodName ) ; } } return $ this ; } | Register callback function to be called on certain events |
727 | public function fireEvent ( $ name , $ params = null ) { $ handleList = Utility :: get ( $ this -> events , $ name , null ) ; $ result = true ; if ( $ handleList ) { foreach ( $ handleList as $ methodName ) { if ( gettype ( $ methodName ) == "string" ) { $ return = $ this -> $ methodName ( $ params ) ; } else { $ return = $ methodName ( $ params ) ; } $ result &= ( $ return !== null ) ? $ return : true ; } } if ( method_exists ( $ this , $ name ) ) { $ return = $ this -> $ name ( $ params ) ; $ result &= ( $ return !== null ) ? $ return : true ; } return $ result ; } | Fire an event with parameters in array form |
728 | protected function getServiceConstructs ( ) { $ serviceConstructs = array ( ) ; $ public_methods = get_class_methods ( $ this ) ; foreach ( $ public_methods as $ method ) { if ( strpos ( $ method , "__construct" ) === 0 && strlen ( $ method ) > 11 ) { array_push ( $ serviceConstructs , $ method ) ; } } return $ serviceConstructs ; } | Return list of contruction methods of services |
729 | protected function src ( $ name = null ) { $ dataSources = Utility :: get ( $ this -> reportSettings , "dataSources" , array ( ) ) ; if ( count ( $ dataSources ) == 0 ) { throw new \ Exception ( "There is no source available, please add at least one in the settings()" ) ; return false ; } if ( ! $ name ) { $ name = Utility :: get ( array_keys ( $ dataSources ) , 0 ) ; } $ dataSourceSetting = Utility :: get ( $ dataSources , $ name ) ; if ( ! $ dataSourceSetting ) { throw new \ Exception ( "Datasource not found '$name'" ) ; return false ; } $ dataSourceClass = Utility :: get ( $ dataSourceSetting , "class" , '\koolreport\datasources\PdoDataSource' ) ; $ dataSourceClass = str_replace ( "/" , "\\" , $ dataSourceClass ) ; $ dataSource = new $ dataSourceClass ( $ dataSourceSetting , $ this ) ; array_push ( $ this -> dataSources , $ dataSource ) ; return $ dataSource ; } | Get a new source |
730 | public function dataStore ( $ name ) { if ( gettype ( $ name ) == "string" ) { if ( ! isset ( $ this -> dataStores [ $ name ] ) ) { $ this -> dataStores [ $ name ] = new DataStore ; } return $ this -> dataStores [ $ name ] ; } else { return $ name ; } } | Get the data store with a name if not found create a new one |
731 | public function run ( ) { if ( $ this -> fireEvent ( "OnBeforeRun" ) ) { if ( $ this -> dataSources != null ) { foreach ( $ this -> dataSources as $ dataSource ) { if ( ! $ dataSource -> isEnded ( ) ) { $ dataSource -> start ( ) ; } } } } $ this -> fireEvent ( "OnRunEnd" ) ; return $ this ; } | Run the report |
732 | public function debug ( ) { $ oldActiveReport = ( isset ( $ GLOBALS [ "__ACTIVE_KOOLREPORT__" ] ) ) ? $ GLOBALS [ "__ACTIVE_KOOLREPORT__" ] : null ; $ GLOBALS [ "__ACTIVE_KOOLREPORT__" ] = $ this ; include dirname ( __FILE__ ) . "/debug.view.php" ; if ( $ oldActiveReport === null ) { unset ( $ GLOBALS [ "__ACTIVE_KOOLREPORT__" ] ) ; } else { $ GLOBALS [ "__ACTIVE_KOOLREPORT__" ] = $ oldActiveReport ; } } | Return debug view |
733 | public function innerView ( $ view , $ params = null , $ return = false ) { $ currentDir = dirname ( Utility :: getClassPath ( $ this ) ) ; ob_start ( ) ; if ( $ params ) { foreach ( $ params as $ key => $ value ) { $ $ key = $ value ; } } include $ currentDir . "/" . $ view . ".view.php" ; $ content = ob_get_clean ( ) ; if ( $ return ) { return $ content ; } else { echo $ content ; } } | Render inner view |
734 | protected function onInit ( ) { $ this -> filePath = Utility :: get ( $ this -> params , "filePath" ) ; $ this -> fieldSeparator = Utility :: get ( $ this -> params , "fieldSeparator" , "," ) ; $ this -> charset = Utility :: get ( $ this -> params , "charset" ) ; $ this -> precision = Utility :: get ( $ this -> params , "precision" , 100 ) ; $ this -> firstRowData = Utility :: get ( $ this -> params , "firstRowData" , false ) ; } | Init the datasource |
735 | public static function create ( $ format , $ value = null ) { if ( 0 < func_num_args ( ) ) { $ format = vsprintf ( $ format , array_slice ( func_get_args ( ) , 1 ) ) ; } return new static ( $ format ) ; } | Creates a new exception using a format and values . |
736 | public static function toComponents ( Version $ version ) { return array ( Parser :: MAJOR => $ version -> getMajor ( ) , Parser :: MINOR => $ version -> getMinor ( ) , Parser :: PATCH => $ version -> getPatch ( ) , Parser :: PRE_RELEASE => $ version -> getPreRelease ( ) , Parser :: BUILD => $ version -> getBuild ( ) ) ; } | Returns the components of a Version instance . |
737 | public static function toString ( Version $ version ) { return sprintf ( '%d.%d.%d%s%s' , $ version -> getMajor ( ) , $ version -> getMinor ( ) , $ version -> getPatch ( ) , $ version -> getPreRelease ( ) ? '-' . join ( '.' , $ version -> getPreRelease ( ) ) : '' , $ version -> getBuild ( ) ? '+' . join ( '.' , $ version -> getBuild ( ) ) : '' ) ; } | Returns the string representation of a Version instance . |
738 | public static function compareTo ( Version $ left , Version $ right ) { switch ( true ) { case ( $ left -> getMajor ( ) < $ right -> getMajor ( ) ) : return self :: LESS_THAN ; case ( $ left -> getMajor ( ) > $ right -> getMajor ( ) ) : return self :: GREATER_THAN ; case ( $ left -> getMinor ( ) > $ right -> getMinor ( ) ) : return self :: GREATER_THAN ; case ( $ left -> getMinor ( ) < $ right -> getMinor ( ) ) : return self :: LESS_THAN ; case ( $ left -> getPatch ( ) > $ right -> getPatch ( ) ) : return self :: GREATER_THAN ; case ( $ left -> getPatch ( ) < $ right -> getPatch ( ) ) : return self :: LESS_THAN ; } return self :: compareIdentifiers ( $ left -> getPreRelease ( ) , $ right -> getPreRelease ( ) ) ; } | Compares one version with another . |
739 | public static function isEqualTo ( Version $ left , Version $ right ) { return ( self :: EQUAL_TO === self :: compareTo ( $ left , $ right ) ) ; } | Checks if the left version is equal to the right . |
740 | public static function isGreaterThan ( Version $ left , Version $ right ) { return ( self :: GREATER_THAN === self :: compareTo ( $ left , $ right ) ) ; } | Checks if the left version is greater than the right . |
741 | public static function isLessThan ( Version $ left , Version $ right ) { return ( self :: LESS_THAN === self :: compareTo ( $ left , $ right ) ) ; } | Checks if the left version is less than the right . |
742 | public static function compareIdentifiers ( array $ left , array $ right ) { if ( $ left && empty ( $ right ) ) { return self :: LESS_THAN ; } elseif ( empty ( $ left ) && $ right ) { return self :: GREATER_THAN ; } $ l = $ left ; $ r = $ right ; $ x = self :: GREATER_THAN ; $ y = self :: LESS_THAN ; if ( count ( $ l ) < count ( $ r ) ) { $ l = $ right ; $ r = $ left ; $ x = self :: LESS_THAN ; $ y = self :: GREATER_THAN ; } foreach ( array_keys ( $ l ) as $ i ) { if ( ! isset ( $ r [ $ i ] ) ) { return $ x ; } if ( $ l [ $ i ] === $ r [ $ i ] ) { continue ; } if ( true === ( $ li = ( false != preg_match ( '/^\d+$/' , $ l [ $ i ] ) ) ) ) { $ l [ $ i ] = intval ( $ l [ $ i ] ) ; } if ( true === ( $ ri = ( false != preg_match ( '/^\d+$/' , $ r [ $ i ] ) ) ) ) { $ r [ $ i ] = intval ( $ r [ $ i ] ) ; } if ( $ li && $ ri ) { return ( $ l [ $ i ] > $ r [ $ i ] ) ? $ x : $ y ; } elseif ( ! $ li && $ ri ) { return $ x ; } elseif ( $ li && ! $ ri ) { return $ y ; } $ result = strcmp ( $ l [ $ i ] , $ r [ $ i ] ) ; if ( $ result > 0 ) { return $ x ; } elseif ( $ result < 0 ) { return $ y ; } } return self :: EQUAL_TO ; } | Compares the identifier components of the left and right versions . |
743 | public function findRecent ( Version $ version , $ major = false , $ pre = false ) { $ current = null ; $ major = $ major ? $ version -> getMajor ( ) : null ; foreach ( $ this -> updates as $ update ) { if ( $ major && ( $ major !== $ update -> getVersion ( ) -> getMajor ( ) ) ) { continue ; } if ( ( false === $ pre ) && ! $ update -> getVersion ( ) -> isStable ( ) ) { continue ; } $ test = $ current ? $ current -> getVersion ( ) : $ version ; if ( false === $ update -> isNewer ( $ test ) ) { continue ; } $ current = $ update ; } return $ current ; } | Finds the most recent update and returns it . |
744 | public function copyTo ( $ file ) { if ( null === $ this -> file ) { throw LogicException :: create ( 'The update file has not been downloaded.' ) ; } $ mode = 0755 ; if ( file_exists ( $ file ) ) { $ mode = fileperms ( $ file ) & 511 ; } if ( false === @ copy ( $ this -> file , $ file ) ) { throw FileException :: lastError ( ) ; } if ( false === @ chmod ( $ file , $ mode ) ) { throw FileException :: lastError ( ) ; } $ key = $ file . '.pubkey' ; if ( file_exists ( $ this -> file . '.pubkey' ) ) { if ( false === @ copy ( $ this -> file . '.pubkey' , $ key ) ) { throw FileException :: lastError ( ) ; } } elseif ( file_exists ( $ key ) ) { if ( false === @ unlink ( $ key ) ) { throw FileException :: lastError ( ) ; } } } | Copies the update file to the destination . |
745 | public function deleteFile ( ) { if ( $ this -> file ) { if ( file_exists ( $ this -> file ) ) { if ( false === @ unlink ( $ this -> file ) ) { throw FileException :: lastError ( ) ; } } if ( file_exists ( $ this -> file . '.pubkey' ) ) { if ( false === @ unlink ( $ this -> file . '.pubkey' ) ) { throw FileException :: lastError ( ) ; } } $ dir = dirname ( $ this -> file ) ; if ( file_exists ( $ dir ) ) { if ( false === @ rmdir ( $ dir ) ) { throw FileException :: lastError ( ) ; } } $ this -> file = null ; } } | Cleans up by deleting the temporary update file . |
746 | public function getFile ( ) { if ( null === $ this -> file ) { unlink ( $ this -> file = tempnam ( sys_get_temp_dir ( ) , 'upd' ) ) ; mkdir ( $ this -> file ) ; $ this -> file .= DIRECTORY_SEPARATOR . $ this -> name ; $ in = new SplFileObject ( $ this -> url , 'rb' , false ) ; $ out = new SplFileObject ( $ this -> file , 'wb' , false ) ; while ( false === $ in -> eof ( ) ) { $ out -> fwrite ( $ in -> fgets ( ) ) ; } unset ( $ in , $ out ) ; if ( $ this -> publicKey ) { $ in = new SplFileObject ( $ this -> publicKey , 'r' , false ) ; $ out = new SplFileObject ( $ this -> file . '.pubkey' , 'w' , false ) ; while ( false === $ in -> eof ( ) ) { $ out -> fwrite ( $ in -> fgets ( ) ) ; } unset ( $ in , $ out ) ; } if ( $ this -> sha1 !== ( $ sha1 = sha1_file ( $ this -> file ) ) ) { $ this -> deleteFile ( ) ; throw FileException :: create ( 'Mismatch of the SHA1 checksum (%s) of the downloaded file (%s).' , $ this -> sha1 , $ sha1 ) ; } try { new Phar ( $ this -> file ) ; } catch ( UnexpectedValueException $ exception ) { $ this -> deleteFile ( ) ; throw $ exception ; } } return $ this -> file ; } | Downloads the update file to a temporary location . |
747 | public function update ( $ version , $ major = false , $ pre = false ) { if ( false === ( $ version instanceof Version ) ) { $ version = Parser :: toVersion ( $ version ) ; } if ( null !== ( $ update = $ this -> manifest -> findRecent ( $ version , $ major , $ pre ) ) ) { $ update -> getFile ( ) ; $ update -> copyTo ( $ this -> getRunningFile ( ) ) ; return true ; } return false ; } | Updates the running Phar if any is available . |
748 | public function callMethod ( $ class , $ method , array $ args = array ( ) ) { $ method = $ this -> findMethod ( $ class , $ method ) ; $ method -> setAccessible ( true ) ; return $ method -> invokeArgs ( is_object ( $ class ) ? $ class : null , $ args ) ; } | Calls a class or object method . |
749 | public function copyPath ( $ from , $ to , $ replace = true , $ purge = true ) { if ( false === file_exists ( $ from ) ) { throw FileSystemException :: invalidPath ( $ from ) ; } if ( is_dir ( $ from ) ) { if ( false === file_exists ( $ to ) ) { if ( false === @ mkdir ( $ to ) ) { throw FileSystemException :: lastError ( $ to , "The directory \"$to\" could not be created: " ) ; } } if ( false === ( $ dh = @ opendir ( $ from ) ) ) { throw FileSystemException :: lastError ( $ to , "The directory \"$from\" could not be opened: " ) ; } while ( false !== ( $ item = readdir ( $ dh ) ) ) { if ( ( '.' === $ item ) || ( '..' === $ item ) ) { continue ; } $ this -> copyPath ( $ from . DIRECTORY_SEPARATOR . $ item , $ to . DIRECTORY_SEPARATOR . $ item , $ replace , false ) ; } closedir ( $ dh ) ; } elseif ( false === ( file_exists ( $ to ) && ( false === $ replace ) ) ) { if ( false === @ copy ( $ from , $ to ) ) { throw FileSystemException :: lastError ( $ to ) ; } } if ( $ purge ) { $ this -> purgePaths [ ] = $ to ; } } | Recursively copies a file or directory tree to another location . |
750 | public function createDir ( $ name = null ) { unlink ( $ dir = $ this -> createFile ( ) ) ; if ( false === mkdir ( $ dir ) ) { throw FileSystemException :: lastError ( $ dir ) ; } if ( null !== $ name ) { $ dir .= DIRECTORY_SEPARATOR . $ name ; if ( false === mkdir ( $ dir ) ) { throw FileSystemException :: lastError ( $ dir ) ; } } return $ dir ; } | Creates a temporary directory path that will be automatically purged at the end of the test . |
751 | public function createFile ( $ name = null ) { if ( null === $ name ) { if ( false === ( $ file = tempnam ( sys_get_temp_dir ( ) , 'tst' ) ) ) { throw FileSystemException :: lastError ( $ name ) ; } $ this -> purgePaths [ ] = $ file ; } else { if ( false === touch ( $ file = $ this -> createDir ( ) . DIRECTORY_SEPARATOR . $ name ) ) { throw FileSystemException :: lastError ( $ file ) ; } } return $ file ; } | Creates a temporary file path that will be automatically purged at the end of the test . |
752 | public function findMethod ( $ class , $ name ) { $ reflection = new ReflectionClass ( $ class ) ; while ( false === $ reflection -> hasMethod ( $ name ) ) { if ( false === ( $ reflection = $ reflection -> getParentClass ( ) ) ) { throw new ReflectionException ( sprintf ( 'The method "%s" does not exist in the class "%s".' , $ name , is_object ( $ class ) ? get_class ( $ class ) : $ class ) ) ; } } return $ reflection -> getMethod ( $ name ) ; } | Finds a class method and returns the ReflectionMethod instance . |
753 | public function findProperty ( $ class , $ name ) { $ reflection = new ReflectionClass ( $ class ) ; while ( false === $ reflection -> hasProperty ( $ name ) ) { if ( false === ( $ reflection = $ reflection -> getParentClass ( ) ) ) { throw new ReflectionException ( sprintf ( 'The property "%s" does not exist in the class "%s".' , $ name , is_object ( $ class ) ? get_class ( $ class ) : $ class ) ) ; } } return $ reflection -> getProperty ( $ name ) ; } | Finds a class property and returns the ReflectionProperty instance . |
754 | public function getPropertyValue ( $ class , $ name ) { $ property = $ this -> findProperty ( $ class , $ name ) ; $ property -> setAccessible ( true ) ; return $ property -> getValue ( is_object ( $ class ) ? $ class : null ) ; } | Returns the value of the property . |
755 | public function purgePath ( $ path ) { if ( false === file_exists ( $ path ) ) { throw FileSystemException :: invalidPath ( $ path ) ; } if ( is_dir ( $ path ) ) { if ( false === ( $ dh = @ opendir ( $ path ) ) ) { throw FileSystemException :: lastError ( $ path ) ; } while ( false !== ( $ item = readdir ( $ dh ) ) ) { if ( ( '.' === $ item ) || ( '..' === $ item ) ) { continue ; } $ this -> purgePath ( $ path . DIRECTORY_SEPARATOR . $ item ) ; } closedir ( $ dh ) ; if ( false === @ rmdir ( $ path ) ) { throw FileSystemException :: lastError ( $ path ) ; } } else { if ( false === @ unlink ( $ path ) ) { throw FileSystemException :: lastError ( $ path ) ; } } } | Recursively deletes a file or directory tree . |
756 | protected function tearDown ( ) { foreach ( $ this -> purgePaths as $ path ) { if ( file_exists ( $ path ) ) { $ this -> purgePath ( $ path ) ; } } } | Purges the created paths and reverts changes made by Runkit . |
757 | public function getVersion ( ) { return new Version ( $ this -> major , $ this -> minor , $ this -> patch , $ this -> preRelease , $ this -> build ) ; } | Returns a readonly Version instance . |
758 | public function importComponents ( array $ components ) { if ( isset ( $ components [ Parser :: BUILD ] ) ) { $ this -> build = $ components [ Parser :: BUILD ] ; } else { $ this -> build = array ( ) ; } if ( isset ( $ components [ Parser :: MAJOR ] ) ) { $ this -> major = $ components [ Parser :: MAJOR ] ; } else { $ this -> major = 0 ; } if ( isset ( $ components [ Parser :: MINOR ] ) ) { $ this -> minor = $ components [ Parser :: MINOR ] ; } else { $ this -> minor = 0 ; } if ( isset ( $ components [ Parser :: PATCH ] ) ) { $ this -> patch = $ components [ Parser :: PATCH ] ; } else { $ this -> patch = 0 ; } if ( isset ( $ components [ Parser :: PRE_RELEASE ] ) ) { $ this -> preRelease = $ components [ Parser :: PRE_RELEASE ] ; } else { $ this -> preRelease = array ( ) ; } return $ this ; } | Imports the version components . |
759 | public function importVersion ( $ version ) { return $ this -> setMajor ( $ version -> getMajor ( ) ) -> setMinor ( $ version -> getMinor ( ) ) -> setPatch ( $ version -> getPatch ( ) ) -> setPreRelease ( $ version -> getPreRelease ( ) ) -> setBuild ( $ version -> getBuild ( ) ) ; } | Imports an existing Version instance . |
760 | public function incrementMajor ( $ amount = 1 ) { $ this -> major += $ amount ; $ this -> minor = 0 ; $ this -> patch = 0 ; return $ this ; } | Increments the major version number and resets the minor and patch version numbers to zero . |
761 | public function setBuild ( array $ identifiers ) { foreach ( $ identifiers as $ identifier ) { if ( ! Validator :: isIdentifier ( $ identifier ) ) { throw new InvalidIdentifierException ( $ identifier ) ; } } $ this -> build = $ identifiers ; return $ this ; } | Sets the build metadata identifiers . |
762 | public function setMajor ( $ number ) { if ( ! Validator :: isNumber ( $ number ) ) { throw new InvalidNumberException ( $ number ) ; } $ this -> major = intval ( $ number ) ; return $ this ; } | Sets the major version number . |
763 | public function setMinor ( $ number ) { if ( ! Validator :: isNumber ( $ number ) ) { throw new InvalidNumberException ( $ number ) ; } $ this -> minor = intval ( $ number ) ; return $ this ; } | Sets the minor version number . |
764 | public function setPatch ( $ number ) { if ( ! Validator :: isNumber ( $ number ) ) { throw new InvalidNumberException ( $ number ) ; } $ this -> patch = intval ( $ number ) ; return $ this ; } | Sets the patch version number . |
765 | public function setPreRelease ( array $ identifiers ) { foreach ( $ identifiers as $ identifier ) { if ( ! Validator :: isIdentifier ( $ identifier ) ) { throw new InvalidIdentifierException ( $ identifier ) ; } } $ this -> preRelease = $ identifiers ; return $ this ; } | Sets the pre - release version identifiers . |
766 | public static function toComponents ( $ version ) { if ( ! Validator :: isVersion ( $ version ) ) { throw new InvalidStringRepresentationException ( $ version ) ; } if ( false !== strpos ( $ version , '+' ) ) { list ( $ version , $ build ) = explode ( '+' , $ version ) ; $ build = explode ( '.' , $ build ) ; } if ( false !== strpos ( $ version , '-' ) ) { list ( $ version , $ pre ) = explode ( '-' , $ version ) ; $ pre = explode ( '.' , $ pre ) ; } list ( $ major , $ minor , $ patch ) = explode ( '.' , $ version ) ; return array ( self :: MAJOR => intval ( $ major ) , self :: MINOR => intval ( $ minor ) , self :: PATCH => intval ( $ patch ) , self :: PRE_RELEASE => isset ( $ pre ) ? $ pre : array ( ) , self :: BUILD => isset ( $ build ) ? $ build : array ( ) , ) ; } | Returns the components of the string representation . |
767 | public static function toVersion ( $ version ) { $ components = self :: toComponents ( $ version ) ; return new Version ( $ components [ 'major' ] , $ components [ 'minor' ] , $ components [ 'patch' ] , $ components [ 'pre' ] , $ components [ 'build' ] ) ; } | Returns a Version instance for the string representation . |
768 | public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { $ response = ( new ResponseFactory ) -> createResponse ( ) ; $ analyzer = CorsAnalyzer :: instance ( $ this -> buildSettings ( $ request , $ response ) ) ; if ( $ this -> logger ) { $ analyzer -> setLogger ( $ this -> logger ) ; } $ cors = $ analyzer -> analyze ( $ request ) ; switch ( $ cors -> getRequestType ( ) ) { case CorsAnalysisResultInterface :: ERR_ORIGIN_NOT_ALLOWED : $ response = $ response -> withStatus ( 401 ) ; return $ this -> processError ( $ request , $ response , [ "message" => "CORS request origin is not allowed." , ] ) ; case CorsAnalysisResultInterface :: ERR_METHOD_NOT_SUPPORTED : $ response = $ response -> withStatus ( 401 ) ; return $ this -> processError ( $ request , $ response , [ "message" => "CORS requested method is not supported." , ] ) ; case CorsAnalysisResultInterface :: ERR_HEADERS_NOT_SUPPORTED : $ response = $ response -> withStatus ( 401 ) ; return $ this -> processError ( $ request , $ response , [ "message" => "CORS requested header is not allowed." , ] ) ; case CorsAnalysisResultInterface :: TYPE_PRE_FLIGHT_REQUEST : $ cors_headers = $ cors -> getResponseHeaders ( ) ; foreach ( $ cors_headers as $ header => $ value ) { if ( false === is_array ( $ value ) ) { $ value = ( string ) $ value ; } $ response = $ response -> withHeader ( $ header , $ value ) ; } return $ response -> withStatus ( 200 ) ; case CorsAnalysisResultInterface :: TYPE_REQUEST_OUT_OF_CORS_SCOPE : return $ handler -> handle ( $ request ) ; default : $ response = $ handler -> handle ( $ request ) ; $ cors_headers = $ cors -> getResponseHeaders ( ) ; foreach ( $ cors_headers as $ header => $ value ) { if ( false === is_array ( $ value ) ) { $ value = ( string ) $ value ; } $ response = $ response -> withHeader ( $ header , $ value ) ; } return $ response ; } } | Execute as PSR - 15 middleware . |
769 | private function buildSettings ( ServerRequestInterface $ request , ResponseInterface $ response ) : CorsSettings { $ settings = new CorsSettings ; $ origin = array_fill_keys ( ( array ) $ this -> options [ "origin" ] , true ) ; $ settings -> setRequestAllowedOrigins ( $ origin ) ; if ( is_callable ( $ this -> options [ "methods" ] ) ) { $ methods = ( array ) $ this -> options [ "methods" ] ( $ request , $ response ) ; } else { $ methods = $ this -> options [ "methods" ] ; } $ methods = array_fill_keys ( $ methods , true ) ; $ settings -> setRequestAllowedMethods ( $ methods ) ; $ headers = array_fill_keys ( $ this -> options [ "headers.allow" ] , true ) ; $ headers = array_change_key_case ( $ headers , CASE_LOWER ) ; $ settings -> setRequestAllowedHeaders ( $ headers ) ; $ headers = array_fill_keys ( $ this -> options [ "headers.expose" ] , true ) ; $ settings -> setResponseExposedHeaders ( $ headers ) ; $ settings -> setRequestCredentialsSupported ( $ this -> options [ "credentials" ] ) ; if ( is_string ( $ this -> options [ "origin.server" ] ) ) { $ settings -> setServerOrigin ( $ this -> options [ "origin.server" ] ) ; } $ settings -> setPreFlightCacheMaxAge ( $ this -> options [ "cache" ] ) ; return $ settings ; } | Build a CORS settings object . |
770 | private function methods ( $ methods ) : void { if ( is_callable ( $ methods ) ) { if ( $ methods instanceof Closure ) { $ this -> options [ "methods" ] = $ methods -> bindTo ( $ this ) ; } else { $ this -> options [ "methods" ] = $ methods ; } } else { $ this -> options [ "methods" ] = ( array ) $ methods ; } } | Set request methods to be allowed . |
771 | private function setUserCurrency ( $ currency , $ request ) { $ currency = strtoupper ( $ currency ) ; currency ( ) -> setUserCurrency ( $ currency ) ; $ request -> getSession ( ) -> put ( [ 'currency' => $ currency ] ) ; return $ currency ; } | Set the user currency . |
772 | private function updateFromOpenExchangeRates ( $ defaultCurrency , $ api ) { $ this -> info ( 'Updating currency exchange rates from OpenExchangeRates.org...' ) ; $ content = json_decode ( $ this -> request ( "http://openexchangerates.org/api/latest.json?base={$defaultCurrency}&app_id={$api}&show_alternative=1" ) ) ; if ( isset ( $ content -> error ) ) { $ this -> error ( $ content -> description ) ; return ; } $ timestamp = ( new DateTime ( ) ) -> setTimestamp ( $ content -> timestamp ) ; foreach ( $ content -> rates as $ code => $ value ) { $ this -> currency -> getDriver ( ) -> update ( $ code , [ 'exchange_rate' => $ value , 'updated_at' => $ timestamp , ] ) ; } $ this -> currency -> clearCache ( ) ; $ this -> info ( 'Update!' ) ; } | Fetch rates from the API |
773 | private function updateFromGoogle ( $ defaultCurrency ) { $ this -> info ( 'Updating currency exchange rates from finance.google.com...' ) ; foreach ( $ this -> currency -> getDriver ( ) -> all ( ) as $ code => $ value ) { if ( $ code === $ defaultCurrency ) { continue ; } $ response = $ this -> request ( 'http://finance.google.com/finance/converter?a=1&from=' . $ defaultCurrency . '&to=' . $ code ) ; if ( Str :: contains ( $ response , 'bld>' ) ) { $ data = explode ( 'bld>' , $ response ) ; $ rate = explode ( $ code , $ data [ 1 ] ) [ 0 ] ; $ this -> currency -> getDriver ( ) -> update ( $ code , [ 'exchange_rate' => $ rate , ] ) ; } else { $ this -> warn ( 'Can\'t update rate for ' . $ code ) ; continue ; } } } | Fetch rates from Google Finance |
774 | public function registerResources ( ) { if ( $ this -> isLumen ( ) === false ) { $ this -> publishes ( [ __DIR__ . '/../config/currency.php' => config_path ( 'currency.php' ) , ] , 'config' ) ; $ this -> mergeConfigFrom ( __DIR__ . '/../config/currency.php' , 'currency' ) ; } $ this -> publishes ( [ __DIR__ . '/../database/migrations' => base_path ( '/database/migrations' ) , ] , 'migrations' ) ; } | Register currency resources . |
775 | protected function update ( $ currency ) { if ( ( $ data = $ this -> getCurrency ( $ currency ) ) === null ) { return $ this -> error ( "Currency \"{$currency}\" not found" ) ; } $ this -> output -> write ( "Updating {$currency} currency..." ) ; if ( is_string ( $ result = $ this -> storage -> update ( $ currency , $ data ) ) ) { $ this -> output -> writeln ( '<error>' . ( $ result ? : 'Failed' ) . '</error>' ) ; } else { $ this -> output -> writeln ( "<info>success</info>" ) ; } } | Update currency in storage . |
776 | protected function delete ( $ currency ) { $ this -> output -> write ( "Deleting {$currency} currency..." ) ; if ( is_string ( $ result = $ this -> storage -> delete ( $ currency ) ) ) { $ this -> output -> writeln ( '<error>' . ( $ result ? : 'Failed' ) . '</error>' ) ; } else { $ this -> output -> writeln ( "<info>success</info>" ) ; } } | Delete currency from storage . |
777 | protected function getCurrencyArgument ( ) { $ value = preg_replace ( '/\s+/' , '' , $ this -> argument ( 'currency' ) ) ; if ( $ value === 'all' ) { return array_keys ( $ this -> currencies ) ; } return explode ( ',' , $ value ) ; } | Get currency argument . |
778 | protected function getActionArgument ( $ validActions = [ ] ) { $ action = strtolower ( $ this -> argument ( 'action' ) ) ; if ( in_array ( $ action , $ validActions ) === false ) { throw new \ RuntimeException ( "The \"{$action}\" option does not exist." ) ; } return $ action ; } | Get action argument . |
779 | public function format ( $ value , $ code = null , $ include_symbol = true ) { $ code = $ code ? : $ this -> config ( 'default' ) ; $ value = preg_replace ( '/[\s\',!]/' , '' , $ value ) ; if ( $ formatter = $ this -> getFormatter ( ) ) { return $ formatter -> format ( $ value , $ code ) ; } $ format = $ this -> getCurrencyProp ( $ code , 'format' ) ; $ valRegex = '/([0-9].*|)[0-9]/' ; preg_match_all ( '/[\s\',.!]/' , $ format , $ separators ) ; if ( $ thousand = array_get ( $ separators , '0.0' , null ) ) { if ( $ thousand == '!' ) { $ thousand = '' ; } } $ decimal = array_get ( $ separators , '0.1' , null ) ; preg_match ( $ valRegex , $ format , $ valFormat ) ; $ valFormat = array_get ( $ valFormat , 0 , 0 ) ; $ decimals = $ decimal ? strlen ( substr ( strrchr ( $ valFormat , $ decimal ) , 1 ) ) : 0 ; if ( $ negative = $ value < 0 ? '-' : '' ) { $ value = $ value * - 1 ; } $ value = number_format ( $ value , $ decimals , $ decimal , $ thousand ) ; if ( $ include_symbol ) { $ value = preg_replace ( $ valRegex , $ value , $ format ) ; } return $ negative . $ value ; } | Format the value into the desired currency . |
780 | public function isActive ( $ code ) { return $ code && ( bool ) Arr :: get ( $ this -> getCurrency ( $ code ) , 'active' , false ) ; } | Determine if the provided currency is active . |
781 | public function getCurrency ( $ code = null ) { $ code = $ code ? : $ this -> getUserCurrency ( ) ; return Arr :: get ( $ this -> getCurrencies ( ) , strtoupper ( $ code ) ) ; } | Return the current currency if the one supplied is not valid . |
782 | public function getCurrencies ( ) { if ( $ this -> currencies_cache === null ) { if ( config ( 'app.debug' , false ) === true ) { $ this -> currencies_cache = $ this -> getDriver ( ) -> all ( ) ; } else { $ this -> currencies_cache = $ this -> cache -> rememberForever ( 'torann.currency' , function ( ) { return $ this -> getDriver ( ) -> all ( ) ; } ) ; } } return $ this -> currencies_cache ; } | Return all currencies . |
783 | public function getDriver ( ) { if ( $ this -> driver === null ) { $ config = $ this -> config ( 'drivers.' . $ this -> config ( 'driver' ) , [ ] ) ; $ driver = Arr :: pull ( $ config , 'class' ) ; $ this -> driver = new $ driver ( $ config ) ; } return $ this -> driver ; } | Get storage driver . |
784 | public function getFormatter ( ) { if ( $ this -> formatter === null && $ this -> config ( 'formatter' ) !== null ) { $ config = $ this -> config ( 'formatters.' . $ this -> config ( 'formatter' ) , [ ] ) ; $ class = Arr :: pull ( $ config , 'class' ) ; $ this -> formatter = new $ class ( array_filter ( $ config ) ) ; } return $ this -> formatter ; } | Get formatter driver . |
785 | protected function getCurrencyProp ( $ code , $ key , $ default = null ) { return Arr :: get ( $ this -> getCurrency ( $ code ) , $ key , $ default ) ; } | Get the given property value from provided currency . |
786 | private function validateEmail ( $ email ) { if ( ! filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { throw MakeUserException :: invalidEmail ( $ email ) ; } if ( app ( config ( 'auth.providers.users.model' ) ) -> where ( 'email' , $ email ) -> exists ( ) ) { throw MakeUserException :: emailExists ( $ email ) ; } } | Determine if the given email address already exists . |
787 | protected function putln ( $ prefix , $ message ) { switch ( $ prefix ) { case '!' : $ prefix = "<error>$prefix</error>" ; break ; case '*' : $ prefix = "<info>$prefix</info>" ; break ; case '?' : $ prefix = "<comment>$prefix</comment>" ; break ; case '-' : case '+' : $ prefix = " <comment>$prefix</comment>" ; break ; case '>' : $ prefix = " <comment>$prefix</comment>" ; break ; } $ this -> verboseln ( "$prefix $message" ) ; } | Outputs a message with a colored prefix . |
788 | protected function verbose ( $ message , $ newline = false , $ type = 0 ) { if ( $ this -> isVerbose ( ) ) { $ this -> output -> write ( $ message , $ newline , $ type ) ; } } | Writes the message only when verbosity is set to VERBOSITY_VERBOSE . |
789 | public function getDefaultPath ( ) { if ( false === file_exists ( self :: FILE_NAME ) ) { if ( false === file_exists ( self :: FILE_NAME . '.dist' ) ) { throw new RuntimeException ( sprintf ( 'The configuration file could not be found.' ) ) ; } return realpath ( self :: FILE_NAME . '.dist' ) ; } return realpath ( self :: FILE_NAME ) ; } | Returns the file path to the default configuration file . |
790 | public function loadFile ( $ file = null ) { if ( null === $ file ) { $ file = $ this -> getDefaultPath ( ) ; } $ json = $ this -> json -> decodeFile ( $ file ) ; if ( isset ( $ json -> import ) ) { if ( ! Path :: isAbsolute ( $ json -> import ) ) { $ json -> import = Path :: join ( array ( dirname ( $ file ) , $ json -> import ) ) ; } $ json = ( object ) array_merge ( ( array ) $ this -> json -> decodeFile ( $ json -> import ) , ( array ) $ json ) ; } $ this -> json -> validate ( $ this -> json -> decodeFile ( BOX_SCHEMA_FILE ) , $ json ) ; return new Configuration ( $ file , $ json ) ; } | Loads the configuration file and returns it . |
791 | protected function getConfig ( InputInterface $ input ) { $ helper = $ this -> getHelper ( 'config' ) ; return $ helper -> loadFile ( $ input -> getOption ( 'configuration' ) ) ; } | Returns the configuration settings . |
792 | private function contents ( OutputInterface $ output , Traversable $ list , $ indent , $ base , Phar $ phar , $ root ) { foreach ( $ list as $ item ) { $ item = $ phar [ str_replace ( $ root , '' , $ item -> getPathname ( ) ) ] ; if ( false !== $ indent ) { $ output -> write ( str_repeat ( ' ' , $ indent ) ) ; $ path = $ item -> getFilename ( ) ; if ( $ item -> isDir ( ) ) { $ path .= '/' ; } } else { $ path = str_replace ( $ base , '' , $ item -> getPathname ( ) ) ; } if ( $ item -> isDir ( ) ) { $ output -> writeln ( "<info>$path</info>" ) ; } else { $ compression = '' ; foreach ( self :: $ fileAlgorithms as $ code => $ name ) { if ( $ item -> isCompressed ( $ code ) ) { $ compression = " <fg=cyan>[$name]</fg=cyan>" ; } } $ output -> writeln ( $ path . $ compression ) ; } if ( $ item -> isDir ( ) ) { $ this -> contents ( $ output , new DirectoryIterator ( $ item -> getPathname ( ) ) , ( false === $ indent ) ? $ indent : $ indent + 2 , $ base , $ phar , $ root ) ; } } } | Renders the contents of an iterator . |
793 | private function render ( OutputInterface $ output , array $ attributes ) { $ out = false ; foreach ( $ attributes as $ name => $ value ) { if ( $ out ) { $ output -> writeln ( '' ) ; } $ output -> write ( "<comment>$name:</comment>" ) ; if ( is_array ( $ value ) ) { $ output -> writeln ( '' ) ; foreach ( $ value as $ v ) { $ output -> writeln ( " - $v" ) ; } } else { $ output -> writeln ( " $value" ) ; } $ out = true ; } } | Renders the list of attributes . |
794 | public function getBasePath ( ) { if ( isset ( $ this -> raw -> { 'base-path' } ) ) { if ( false === is_dir ( $ this -> raw -> { 'base-path' } ) ) { throw new InvalidArgumentException ( sprintf ( 'The base path "%s" is not a directory or does not exist.' , $ this -> raw -> { 'base-path' } ) ) ; } return realpath ( $ this -> raw -> { 'base-path' } ) ; } return realpath ( dirname ( $ this -> file ) ) ; } | Returns the base path . |
795 | public function getBinaryDirectories ( ) { if ( isset ( $ this -> raw -> { 'directories-bin' } ) ) { $ directories = ( array ) $ this -> raw -> { 'directories-bin' } ; $ base = $ this -> getBasePath ( ) ; array_walk ( $ directories , function ( & $ directory ) use ( $ base ) { $ directory = $ base . DIRECTORY_SEPARATOR . Path :: canonical ( $ directory ) ; } ) ; return $ directories ; } return array ( ) ; } | Returns the list of relative directory paths for binary files . |
796 | public function getBinaryDirectoriesIterator ( ) { if ( array ( ) !== ( $ directories = $ this -> getBinaryDirectories ( ) ) ) { return Finder :: create ( ) -> files ( ) -> filter ( $ this -> getBlacklistFilter ( ) ) -> ignoreVCS ( true ) -> in ( $ directories ) ; } return null ; } | Returns the iterator for the binary directory paths . |
797 | public function getBinaryFiles ( ) { if ( isset ( $ this -> raw -> { 'files-bin' } ) ) { $ base = $ this -> getBasePath ( ) ; $ files = array ( ) ; foreach ( ( array ) $ this -> raw -> { 'files-bin' } as $ file ) { $ files [ ] = new SplFileInfo ( $ base . DIRECTORY_SEPARATOR . Path :: canonical ( $ file ) ) ; } return $ files ; } return array ( ) ; } | Returns the list of relative paths for binary files . |
798 | public function getBlacklist ( ) { if ( isset ( $ this -> raw -> blacklist ) ) { $ blacklist = ( array ) $ this -> raw -> blacklist ; array_walk ( $ blacklist , function ( & $ file ) { $ file = Path :: canonical ( $ file ) ; } ) ; return $ blacklist ; } return array ( ) ; } | Returns the list of blacklisted relative file paths . |
799 | public function getBlacklistFilter ( ) { $ blacklist = $ this -> getBlacklist ( ) ; $ base = '/^' . preg_quote ( $ this -> getBasePath ( ) . DIRECTORY_SEPARATOR , '/' ) . '/' ; return function ( SplFileInfo $ file ) use ( $ base , $ blacklist ) { $ path = Path :: canonical ( preg_replace ( $ base , '' , $ file -> getPathname ( ) ) ) ; if ( in_array ( $ path , $ blacklist ) ) { return false ; } return null ; } ; } | Returns a filter callable for the configured blacklist . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.