idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
44,300 | public function all ( $ account , $ repo , array $ params = array ( ) ) { $ states = array ( 'OPEN' , 'MERGED' , 'DECLINED' ) ; $ params = array_merge ( array ( 'state' => 'OPEN' ) , $ params ) ; if ( ! is_array ( $ params [ 'state' ] ) ) { $ params [ 'state' ] = array ( $ params [ 'state' ] ) ; } array_walk ( $ params [ 'state' ] , function ( $ state ) use ( $ states ) { if ( ! in_array ( $ state , $ states ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown `state` %s' , $ state ) ) ; } } ) ; return $ this -> getClient ( ) -> setApiVersion ( '2.0' ) -> get ( sprintf ( 'repositories/%s/%s/pullrequests' , $ account , $ repo ) , $ params ) ; } | Get a list of pull requests |
44,301 | public function create ( $ account , $ repo , $ params = array ( ) ) { $ defaults = array ( 'title' => 'New pull request' , 'source' => array ( 'branch' => array ( 'name' => 'develop' ) ) ) ; if ( 'array' !== gettype ( $ params ) ) { if ( empty ( $ params ) ) { throw new \ InvalidArgumentException ( 'Invalid JSON provided.' ) ; } $ params = $ this -> decodeJSON ( $ params ) ; } $ params = array_merge ( $ defaults , $ params ) ; if ( empty ( $ params [ 'title' ] ) ) { throw new \ InvalidArgumentException ( 'Pull request\'s title must be specified.' ) ; } if ( empty ( $ params [ 'source' ] [ 'branch' ] [ 'name' ] ) ) { throw new \ InvalidArgumentException ( 'Pull request\'s source branch name must be specified.' ) ; } return $ this -> getClient ( ) -> setApiVersion ( '2.0' ) -> post ( sprintf ( 'repositories/%s/%s/pullrequests' , $ account , $ repo ) , json_encode ( $ params ) , array ( 'Content-Type' => 'application/json' ) ) ; } | Create a new pull request |
44,302 | public function approve ( $ account , $ repo , $ id ) { return $ this -> getClient ( ) -> setApiVersion ( '2.0' ) -> post ( sprintf ( 'repositories/%s/%s/pullrequests/%d/approve' , $ account , $ repo , $ id ) ) ; } | Approve a pull request |
44,303 | public function activity ( $ account , $ repo , $ id = 0 ) { $ endpoint = sprintf ( 'repositories/%s/%s/pullrequests/' , $ account , $ repo ) ; if ( $ id === 0 ) { $ endpoint .= 'activity' ; } else { $ endpoint .= $ id . '/activity' ; } return $ this -> getClient ( ) -> setApiVersion ( '2.0' ) -> get ( $ endpoint ) ; } | Get the log of all of a repository s pull request activity |
44,304 | public function accept ( $ account , $ repo , $ id , $ params = array ( ) ) { return $ this -> getClient ( ) -> setApiVersion ( '2.0' ) -> post ( sprintf ( 'repositories/%s/%s/pullrequests/%d/merge' , $ account , $ repo , $ id ) , json_encode ( $ params ) , array ( 'Content-Type' => 'application/json' ) ) ; } | Accept and merge a pull request |
44,305 | public function decline ( $ account , $ repo , $ id , $ params = array ( ) ) { if ( false === array_key_exists ( 'message' , $ params ) ) { $ params [ 'message' ] = '' ; } return $ this -> getClient ( ) -> setApiVersion ( '2.0' ) -> post ( sprintf ( 'repositories/%s/%s/pullrequests/%d/decline' , $ account , $ repo , $ id ) , json_encode ( $ params ) , array ( 'Content-Type' => 'application/json' ) ) ; } | Decline a pull request |
44,306 | private function pingSocket ( ) { $ type = "\x08" ; $ code = "\x00" ; $ checksum = "\x00\x00" ; $ identifier = "\x00\x00" ; $ seq_number = "\x00\x00" ; $ package = $ type . $ code . $ checksum . $ identifier . $ seq_number . $ this -> data ; $ checksum = $ this -> calculateChecksum ( $ package ) ; $ package = $ type . $ code . $ checksum . $ identifier . $ seq_number . $ this -> data ; if ( $ socket = socket_create ( AF_INET , SOCK_RAW , 1 ) ) { socket_set_option ( $ socket , SOL_SOCKET , SO_RCVTIMEO , array ( 'sec' => 10 , 'usec' => 0 , ) ) ; @ socket_connect ( $ socket , $ this -> host , null ) ; $ start = microtime ( true ) ; @ socket_send ( $ socket , $ package , strlen ( $ package ) , 0 ) ; if ( socket_read ( $ socket , 255 ) !== false ) { $ latency = microtime ( true ) - $ start ; $ latency = round ( $ latency * 1000 ) ; } else { $ latency = false ; } } else { $ latency = false ; } socket_close ( $ socket ) ; return $ latency ; } | The socket method uses raw network packet data to try sending an ICMP ping packet to a server then measures the response time . Using this method requires the script to be run with root privileges though so this method only works reliably on Windows systems and on Linux servers where the script is not being run as a web user . |
44,307 | private function calculateChecksum ( $ data ) { if ( strlen ( $ data ) % 2 ) { $ data .= "\x00" ; } $ bit = unpack ( 'n*' , $ data ) ; $ sum = array_sum ( $ bit ) ; while ( $ sum >> 16 ) { $ sum = ( $ sum >> 16 ) + ( $ sum & 0xffff ) ; } return pack ( 'n*' , ~ $ sum ) ; } | Calculate a checksum . |
44,308 | public static function removeDir ( $ dir ) { if ( is_dir ( $ dir ) ) { $ objects = scandir ( $ dir ) ; foreach ( $ objects as $ object ) { if ( '.' != $ object && '..' != $ object ) { if ( 'dir' == filetype ( $ dir . DS . $ object ) ) { static :: removeDir ( $ dir . DS . $ object ) ; } else { if ( ! unlink ( $ dir . DS . $ object ) ) { throw new ErrorException ( 'The following file could not be deleted: ' . $ dir . DS . $ object ) ; } } } } if ( ! rmdir ( $ dir ) ) { throw new ErrorException ( "The following directory could not be deleted: {$dir}" ) ; } } } | Recursively remove a directory and all of it s contents |
44,309 | public static function isSerialized ( $ value , & $ result = null ) { if ( ! is_string ( $ value ) ) { return false ; } if ( 'b:0;' === $ value ) { $ result = false ; return true ; } $ length = strlen ( $ value ) ; $ end = '' ; if ( isset ( $ value [ 0 ] ) ) { switch ( $ value [ 0 ] ) { case 's' : if ( '"' !== $ value [ $ length - 2 ] ) { return false ; } break ; case 'b' : case 'i' : case 'd' : $ end .= ';' ; case 'a' : case 'O' : $ end .= '}' ; if ( ':' !== $ value [ 1 ] ) { return false ; } switch ( $ value [ 2 ] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : break ; default : return false ; } case 'N' : $ end .= ';' ; if ( $ value [ $ length - 1 ] !== $ end [ 0 ] ) { return false ; } break ; default : return false ; } } if ( ( $ result = @ unserialize ( $ value ) ) === false ) { $ result = null ; return false ; } return true ; } | Check to see if a string is unserializable |
44,310 | protected function checkCache ( $ originalFile , $ cacheFile ) { if ( ! $ ret = parent :: checkCache ( $ originalFile , $ cacheFile ) ) { return false ; } if ( Utils :: isSerialized ( $ ret , $ ret ) ) { foreach ( $ ret [ 'files' ] as $ file => $ lastModified ) { if ( filemtime ( $ file ) > $ lastModified ) { return false ; } } $ ret = serialize ( $ ret ) ; } return $ ret ; } | Checks to see if cache exists and is the latest if it does return it It also checks to see if this is LESS cache and makes sure all imported files are the latest |
44,311 | protected function fixRelativePaths ( $ content , $ originalFile ) { $ cssParserSettings = CssSettings :: create ( ) -> withMultibyteSupport ( false ) ; $ cssParser = new CssParser ( $ content , $ cssParserSettings ) ; $ cssDocument = $ cssParser -> parse ( ) ; $ cssBlocks = $ cssDocument -> getAllValues ( ) ; $ this -> fixUrls ( $ cssBlocks , $ originalFile ) ; return $ cssDocument -> render ( ) ; } | Use CssParser to go through and convert all relative paths to absolute |
44,312 | protected function fixUrls ( $ cssBlocks , $ originalFile ) { foreach ( $ cssBlocks as $ cssBlock ) { if ( $ cssBlock instanceof Import ) { $ this -> fixUrls ( $ cssBlock -> atRuleArgs ( ) , $ originalFile ) ; } else { if ( ! $ cssBlock instanceof URL ) { continue ; } $ originalUrl = $ cssBlock -> getURL ( ) -> getString ( ) ; $ url = $ this -> relativeToAbsolute ( $ originalUrl , $ originalFile ) ; $ cssBlock -> getURL ( ) -> setString ( $ url ) ; } } } | Recursively go through the CSS Blocks and update relative links to absolute |
44,313 | public function doFilter ( $ file , $ arguments , $ typeOptions ) { $ Imagine = new Imagine ( ) ; $ image = $ Imagine -> open ( $ file ) ; $ colour = $ image -> palette ( ) -> color ( '#' . $ arguments [ 'colorize' ] ) ; $ image -> effects ( ) -> colorize ( $ colour ) ; $ image -> save ( $ file ) ; } | Colorize an image |
44,314 | public static function unRegister ( $ extensions ) { foreach ( ( array ) $ extensions as $ extension ) { foreach ( static :: $ _registry as & $ registered ) { $ key = array_search ( $ extension , $ registered [ 'extensions' ] , true ) ; if ( false !== $ key ) { unset ( $ registered [ 'extensions' ] [ $ key ] ) ; } if ( empty ( $ registered [ 'extensions' ] ) ) { unset ( $ registered ) ; } } } } | Un - Register one or more extensions |
44,315 | public static function getClass ( Request $ Request ) { foreach ( static :: $ _registry as $ registered ) { if ( in_array ( $ Request -> ext , $ registered [ 'extensions' ] ) ) { return $ registered [ 'resolve' ] ( $ Request ) ; } } throw new ErrorException ( "The following extension is not handled: {$Request->ext}" ) ; } | Return the AssetClass based on the file extension in the Request Class |
44,316 | public static function getSupportedExtensions ( $ extension ) { foreach ( static :: $ _registry as $ registered ) { if ( in_array ( $ extension , ( array ) $ registered [ 'extensions' ] ) ) { return $ registered [ 'extensions' ] ; } } throw new ErrorException ( "The following extension is not handled: {$extension}" ) ; } | Get Supported Extensions |
44,317 | public function init ( ) { $ content = array ( ) ; foreach ( $ this -> request -> files as $ file ) { $ cacheFile = $ this -> generateCacheFile ( $ file ) ; if ( ! $ fileContent = $ this -> checkCache ( $ file , $ cacheFile ) ) { $ this -> setupFile ( $ file , $ cacheFile ) ; $ fileContent = $ this -> getFileContent ( $ file , $ cacheFile ) ; } $ content [ ] = $ this -> afterGetFileContent ( $ fileContent ) ; } $ this -> content = implode ( "\n" , $ content ) ; } | Process all files in the request and set the content |
44,318 | public function cleanUpAfterError ( ) { foreach ( $ this -> request -> files as $ file ) { $ cacheFile = $ this -> generateCacheFile ( $ file ) ; unlink ( $ cacheFile ) ; } } | If an exception is handled this function will fire and clean up any files that have been cached as they have not properly compiled . |
44,319 | protected function setupFile ( $ originalFile , $ cacheFile ) { if ( ! file_exists ( $ originalFile ) ) { throw new NotFoundException ( 'File does not exist: ' . str_replace ( $ this -> request -> webroot , '' , $ originalFile ) ) ; } copy ( $ originalFile , $ cacheFile ) ; } | Checks to see if the file exists and then copies it to the cache folder for further manipulation |
44,320 | protected function getFileContent ( $ originalFile , $ cacheFile ) { $ this -> beforeFilter ( $ originalFile , $ cacheFile ) ; foreach ( $ this -> filters as $ filterName => $ Filter ) { $ arguments = isset ( $ this -> request -> params [ $ filterName ] ) ? $ this -> request -> params [ $ filterName ] : array ( ) ; if ( ! is_array ( $ arguments ) ) { $ arguments = array ( $ filterName => $ arguments ) ; } if ( strpos ( $ originalFile , '.min.' ) !== FALSE ) { $ arguments [ 'minify' ] = false ; } $ Filter -> doFilter ( $ cacheFile , $ arguments , $ this -> options ) ; } $ this -> afterFilter ( $ originalFile , $ cacheFile ) ; $ this -> lastModifiedDate = time ( ) ; return file_get_contents ( $ cacheFile ) ; } | Grab a files content but check to make sure it exists first |
44,321 | protected function generateCacheFile ( $ file ) { $ cacheSalt = serialize ( array ( $ this -> request -> options , MUNEE_USING_URL_REWRITE , MUNEE_DISPATCHER_FILE ) ) ; $ params = serialize ( $ this -> request -> params ) ; $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; $ fileHash = md5 ( $ file ) ; $ optionsHash = md5 ( $ params . $ cacheSalt ) ; $ cacheDir = $ this -> cacheDir . DS . substr ( $ fileHash , 0 , 2 ) ; Utils :: createDir ( $ cacheDir ) ; return $ cacheDir . DS . substr ( $ fileHash , 2 ) . '-' . $ optionsHash . '.' . $ ext ; } | Generate File Name Hash based on filename request params and request options |
44,322 | public function setRawParam ( $ key , $ value = null ) { if ( is_array ( $ key ) ) { $ this -> rawParams = $ key ; } else { $ this -> rawParams [ $ key ] = $ value ; } return $ this ; } | Sets either an individual _rawParams key - or overwrites the whole array . |
44,323 | public function parseParams ( $ allowedParams ) { $ this -> allowedParams = $ allowedParams ; $ this -> setDefaultParams ( ) ; foreach ( $ this -> rawParams as $ checkParam => $ value ) { if ( ! $ paramOptions = $ this -> getParamOptions ( $ checkParam ) ) { continue ; } $ param = $ paramOptions [ 'param' ] ; $ options = $ paramOptions [ 'options' ] ; $ paramValue = $ this -> getParamValue ( $ param , $ options , $ value ) ; if ( isset ( $ this -> params [ $ param ] ) && is_array ( $ this -> params [ $ param ] ) ) { $ this -> params [ $ param ] = array_merge ( $ this -> params [ $ param ] , $ paramValue ) ; } else { $ this -> params [ $ param ] = $ paramValue ; } } } | Parse query string parameter arguments based on mapped allowed params |
44,324 | protected function setDefaultParams ( ) { foreach ( $ this -> allowedParams as $ param => $ options ) { $ this -> params [ $ param ] = null ; if ( ! empty ( $ options [ 'arguments' ] ) ) { $ this -> params [ $ param ] = array ( ) ; foreach ( $ options [ 'arguments' ] as $ arg => $ opts ) { if ( ! empty ( $ opts [ 'default' ] ) ) { $ cast = ! empty ( $ opts [ 'cast' ] ) ? $ opts [ 'cast' ] : 'string' ; $ this -> params [ $ param ] [ $ arg ] = $ this -> castValue ( $ cast , $ opts [ 'default' ] ) ; } } } elseif ( ! empty ( $ options [ 'default' ] ) ) { $ cast = ! empty ( $ options [ 'cast' ] ) ? $ options [ 'cast' ] : 'string' ; $ this -> params [ $ param ] = $ this -> castValue ( $ cast , $ options [ 'default' ] ) ; } } } | Setup the default values for the allowed parameters |
44,325 | protected function getParamOptions ( $ checkParam ) { if ( isset ( $ this -> allowedParams [ $ checkParam ] ) ) { return array ( 'param' => $ checkParam , 'options' => $ this -> allowedParams [ $ checkParam ] ) ; } else { foreach ( $ this -> allowedParams as $ param => $ options ) { if ( ! empty ( $ options [ 'alias' ] ) && in_array ( $ checkParam , ( array ) $ options [ 'alias' ] ) ) { return compact ( 'param' , 'options' ) ; } } } return false ; } | Grabs the params options taking into account any aliases |
44,326 | protected function getParamValue ( $ param , $ paramOptions , $ value ) { if ( ! empty ( $ paramOptions [ 'arguments' ] ) ) { $ ret = array ( ) ; foreach ( $ paramOptions [ 'arguments' ] as $ arg => $ opts ) { $ p = $ arg ; if ( ! empty ( $ opts [ 'alias' ] ) ) { $ alias = implode ( '|' , ( array ) $ opts [ 'alias' ] ) ; $ p .= "|\\b{$alias}" ; } $ regex = "(\\b{$p})\\[(.*?)\\]" ; if ( preg_match ( "%{$regex}%" , $ value , $ match ) ) { $ ret [ $ arg ] = $ this -> getParamValue ( $ arg , $ opts , $ match [ 2 ] ) ; } } return $ ret ; } else { if ( ! empty ( $ paramOptions [ 'regex' ] ) ) { if ( ! preg_match ( "%^(?:{$paramOptions['regex']})$%" , $ value ) ) { throw new ErrorException ( "'{$value}' is not a valid value for: {$param}" ) ; } } $ cast = ! empty ( $ paramOptions [ 'cast' ] ) ? $ paramOptions [ 'cast' ] : 'string' ; return $ this -> castValue ( $ cast , $ value ) ; } } | Grabs a value from a param by running it through supplied regex |
44,327 | protected function castValue ( $ cast , $ value ) { switch ( $ cast ) { case 'integer' ; $ value = ( integer ) $ value ; break ; case 'boolean' ; $ value = in_array ( $ value , array ( 'true' , 't' , 'yes' , 'y' ) ) ; break ; case 'string' : default : $ value = ( string ) $ value ; } return $ value ; } | Helper function to cast values |
44,328 | public static function run ( Request $ Request , $ options = array ( ) ) { try { $ options = array_merge ( self :: $ defaultOptions , $ options ) ; if ( isset ( $ options [ 'headerController' ] ) && $ options [ 'headerController' ] instanceof Asset \ HeaderSetter ) { $ headerController = $ options [ 'headerController' ] ; } else { $ headerController = new Asset \ HeaderSetter ; } $ Request -> init ( ) ; $ AssetType = Asset \ Registry :: getClass ( $ Request ) ; $ AssetType -> init ( ) ; $ Response = new Response ( $ AssetType ) ; $ Response -> setHeaderController ( $ headerController ) ; if ( $ options [ 'setHeaders' ] ) { $ Response -> setHeaders ( $ options [ 'maxAge' ] ) ; } return $ Response -> notModified ? null : $ Response -> render ( ) ; } catch ( Asset \ NotFoundException $ e ) { if ( isset ( $ headerController ) && $ headerController instanceof Asset \ HeaderSetter ) { $ headerController -> statusCode ( 'HTTP/1.0' , 404 , 'Not Found' ) ; $ headerController -> headerField ( 'Status' , '404 Not Found' ) ; } return 'Not Found Error: ' . static :: getErrors ( $ e ) ; } catch ( Asset \ Type \ CompilationException $ e ) { if ( isset ( $ AssetType ) && $ AssetType instanceof Asset \ Type ) { $ AssetType -> cleanUpAfterError ( ) ; } return 'Compilation Error: ' . static :: getErrors ( $ e ) ; } catch ( ErrorException $ e ) { return 'Error: ' . static :: getErrors ( $ e ) ; } } | 1 ) Initialise the Request 2 ) Grab the AssetType based on the request and initialise it 3 ) Instantiate the Response class set the headers and then return the content |
44,329 | protected static function getErrors ( \ Exception $ e ) { $ errors = $ e -> getMessage ( ) ; while ( $ e = $ e -> getPrevious ( ) ) { $ errors .= "<br>" . $ e -> getMessage ( ) ; } return $ errors ; } | Grabs all of the Exception messages in a chain |
44,330 | protected function setupFile ( $ originalFile , $ cacheFile ) { if ( count ( $ this -> filters ) > 0 ) { $ this -> checkNumberOfAllowedFilters ( $ cacheFile ) ; if ( $ this -> options [ 'checkReferrer' ] ) { $ this -> checkReferrer ( ) ; } } if ( ! file_exists ( $ originalFile ) ) { if ( $ this -> placeholder && file_exists ( $ this -> placeholder ) ) { $ originalFile = $ this -> placeholder ; } } parent :: setupFile ( $ originalFile , $ cacheFile ) ; } | Overwrite the _setupFile function so placeholder images can be shown instead of broken images |
44,331 | public function getHeaders ( ) { switch ( $ this -> request -> ext ) { case 'jpg' : case 'jpeg' : $ this -> response -> headerController -> headerField ( 'Content-Type' , 'image/jpeg' ) ; break ; case 'png' : $ this -> response -> headerController -> headerField ( 'Content-Type' , 'image/png' ) ; break ; case 'gif' : $ this -> response -> headerController -> headerField ( 'Content-Type' , 'image/gif' ) ; break ; } } | Set additional headers just for an Image |
44,332 | protected function checkReferrer ( ) { if ( ! isset ( $ _SERVER [ 'HTTP_REFERER' ] ) ) { throw new ErrorException ( 'Direct image manipulation is not allowed.' ) ; } $ referrer = preg_replace ( '%^https?://%' , '' , $ _SERVER [ 'HTTP_REFERER' ] ) ; if ( ! preg_match ( "%^{$_SERVER['SERVER_NAME']}%" , $ referrer ) ) { throw new ErrorException ( 'Referrer does not match the correct domain.' ) ; } } | Check to make sure the referrer domain is the same as the domain where the image exists . |
44,333 | protected function checkNumberOfAllowedFilters ( $ cacheFile ) { $ pathInfo = pathinfo ( $ cacheFile ) ; $ fileNameHash = preg_replace ( '%-.*$%' , '' , $ pathInfo [ 'filename' ] ) ; $ cachedImages = glob ( $ pathInfo [ 'dirname' ] . DS . $ fileNameHash . '*' ) ; if ( ! is_array ( $ cachedImages ) ) { $ cachedImages = array ( ) ; } foreach ( $ cachedImages as $ k => $ image ) { if ( filemtime ( $ image ) < time ( ) - $ this -> options [ 'allowedFiltersTimeLimit' ] ) { unset ( $ cachedImages [ $ k ] ) ; } } if ( count ( $ cachedImages ) >= $ this -> options [ 'numberOfAllowedFilters' ] ) { throw new ErrorException ( 'You cannot create anymore resizes/manipulations at this time.' ) ; } } | Check number of allowed resizes within a set time limit |
44,334 | protected function getImageByUrl ( $ url ) { $ cacheFolder = MUNEE_CACHE . DS . 'placeholders' ; Utils :: createDir ( $ cacheFolder ) ; $ requestOptions = serialize ( $ this -> request -> options ) ; $ originalFile = array_shift ( $ this -> request -> files ) ; $ fileName = $ cacheFolder . DS . md5 ( $ url ) . '-' . md5 ( $ requestOptions . $ originalFile ) ; if ( ! file_exists ( $ fileName ) ) { file_put_contents ( $ fileName , file_get_contents ( $ url ) ) ; } return $ fileName ; } | Grabs an image by URL from another server |
44,335 | public function doFilter ( $ file , $ arguments , $ typeOptions ) { if ( ! $ arguments [ 'grayscale' ] ) { return ; } $ Imagine = new Imagine ( ) ; $ image = $ Imagine -> open ( $ file ) ; $ image -> effects ( ) -> grayscale ( ) ; $ image -> save ( $ file ) ; } | Turn an image Grayscale |
44,336 | public function setHeaderController ( $ headerController ) { if ( ! $ headerController instanceof Asset \ HeaderSetter ) { throw new ErrorException ( 'Header controller must be an instance of Asset\HeaderSetter.' ) ; } $ this -> headerController = $ headerController ; return $ this ; } | Set controller for setting headers . |
44,337 | public function setHeaders ( $ maxAge ) { $ lastModifiedDate = $ this -> assetType -> getLastModifiedDate ( ) ; $ eTag = md5 ( $ lastModifiedDate . $ this -> assetType -> getContent ( ) ) ; $ checkModifiedSince = isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ? $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] : false ; $ checkETag = isset ( $ _SERVER [ 'HTTP_IF_NONE_MATCH' ] ) ? $ _SERVER [ 'HTTP_IF_NONE_MATCH' ] : false ; if ( ( $ checkModifiedSince && strtotime ( $ checkModifiedSince ) == $ lastModifiedDate ) || $ checkETag == $ eTag ) { $ this -> headerController -> statusCode ( 'HTTP/1.1' , 304 , 'Not Modified' ) ; $ this -> notModified = true ; } else { $ this -> headerController -> headerField ( 'Cache-Control' , 'max-age=' . $ maxAge . ', must-revalidate' ) ; $ this -> headerController -> headerField ( 'Last-Modified' , gmdate ( 'D, d M Y H:i:s' , $ lastModifiedDate ) . ' GMT' ) ; $ this -> headerController -> headerField ( 'ETag' , $ eTag ) ; $ this -> assetType -> getHeaders ( ) ; } return $ this ; } | Set Headers for Response |
44,338 | public function render ( ) { $ content = $ this -> assetType -> getContent ( ) ; if ( @ ini_get ( 'zlib.output_compression' ) ) { $ ret = $ content ; } else if ( ! $ ret = ob_gzhandler ( $ content , PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END ) ) { $ ret = $ content ; } return $ ret ; } | Returns the Asset Types content . It will try and use Gzip to compress the content and save bandwidth |
44,339 | public static function create ( $ value , int $ scale = null ) : Decimal { if ( \ is_int ( $ value ) ) { return self :: fromInteger ( $ value ) ; } elseif ( \ is_float ( $ value ) ) { return self :: fromFloat ( $ value , $ scale ) ; } elseif ( \ is_string ( $ value ) ) { return self :: fromString ( $ value , $ scale ) ; } elseif ( $ value instanceof Decimal ) { return self :: fromDecimal ( $ value , $ scale ) ; } else { throw new \ TypeError ( 'Expected (int, float, string, Decimal), but received ' . ( \ is_object ( $ value ) ? \ get_class ( $ value ) : \ gettype ( $ value ) ) ) ; } } | Decimal constructor . |
44,340 | public function add ( Decimal $ b , int $ scale = null ) : Decimal { self :: paramsValidation ( $ b , $ scale ) ; return self :: fromString ( \ bcadd ( $ this -> value , $ b -> value , \ max ( $ this -> scale , $ b -> scale ) ) , $ scale ) ; } | Adds two Decimal objects |
44,341 | public function sub ( Decimal $ b , int $ scale = null ) : Decimal { self :: paramsValidation ( $ b , $ scale ) ; return self :: fromString ( \ bcsub ( $ this -> value , $ b -> value , \ max ( $ this -> scale , $ b -> scale ) ) , $ scale ) ; } | Subtracts two BigNumber objects |
44,342 | public function mul ( Decimal $ b , int $ scale = null ) : Decimal { self :: paramsValidation ( $ b , $ scale ) ; if ( $ b -> isZero ( ) ) { return DecimalConstants :: Zero ( ) ; } return self :: fromString ( \ bcmul ( $ this -> value , $ b -> value , $ this -> scale + $ b -> scale ) , $ scale ) ; } | Multiplies two BigNumber objects |
44,343 | public function sqrt ( int $ scale = null ) : Decimal { if ( $ this -> isNegative ( ) ) { throw new \ DomainException ( "Decimal can't handle square roots of negative numbers (it's only for real numbers)." ) ; } elseif ( $ this -> isZero ( ) ) { return DecimalConstants :: Zero ( ) ; } $ sqrt_scale = ( $ scale !== null ? $ scale : $ this -> scale ) ; return self :: fromString ( \ bcsqrt ( $ this -> value , $ sqrt_scale + 1 ) , $ sqrt_scale ) ; } | Returns the square root of this object |
44,344 | public function log10 ( int $ scale = null ) : Decimal { if ( $ this -> isNegative ( ) ) { throw new \ DomainException ( "Decimal can't handle logarithms of negative numbers (it's only for real numbers)." ) ; } elseif ( $ this -> isZero ( ) ) { throw new \ DomainException ( "Decimal can't represent infinite numbers." ) ; } return self :: fromString ( self :: innerLog10 ( $ this -> value , $ this -> scale , $ scale !== null ? $ scale + 1 : $ this -> scale + 1 ) , $ scale ) ; } | Returns the object s logarithm in base 10 |
44,345 | public function additiveInverse ( ) : Decimal { if ( $ this -> isZero ( ) ) { return $ this ; } elseif ( $ this -> isNegative ( ) ) { $ value = \ substr ( $ this -> value , 1 ) ; } else { $ value = '-' . $ this -> value ; } return new static ( $ value , $ this -> scale ) ; } | Returns the element s additive inverse . |
44,346 | public function mod ( Decimal $ d , int $ scale = null ) : Decimal { $ div = $ this -> div ( $ d , 1 ) -> floor ( ) ; return $ this -> sub ( $ div -> mul ( $ d ) , $ scale ) ; } | Calculate modulo with a decimal |
44,347 | public function sin ( int $ scale = null ) : Decimal { $ x = $ this -> mod ( DecimalConstants :: PI ( ) -> mul ( Decimal :: fromString ( "2" ) ) ) ; $ scale = ( null === $ scale ) ? 32 : $ scale ; return self :: factorialSerie ( $ x , DecimalConstants :: zero ( ) , function ( $ i ) { return ( $ i % 2 === 1 ) ? ( ( $ i % 4 === 1 ) ? DecimalConstants :: one ( ) : DecimalConstants :: negativeOne ( ) ) : DecimalConstants :: zero ( ) ; } , $ scale ) ; } | Calculates the sine of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI ; |
44,348 | public function cosec ( int $ scale = null ) : Decimal { $ sin = $ this -> sin ( $ scale + 2 ) ; if ( $ sin -> isZero ( ) ) { throw new \ DomainException ( "The cosecant of this 'angle' is undefined." ) ; } return DecimalConstants :: one ( ) -> div ( $ sin ) -> round ( $ scale ) ; } | Calculates the cosecant of this with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI ; |
44,349 | public function sec ( int $ scale = null ) : Decimal { $ cos = $ this -> cos ( $ scale + 2 ) ; if ( $ cos -> isZero ( ) ) { throw new \ DomainException ( "The secant of this 'angle' is undefined." ) ; } return DecimalConstants :: one ( ) -> div ( $ cos ) -> round ( $ scale ) ; } | Calculates the secant of this with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI ; |
44,350 | public function arccot ( int $ scale = null ) : Decimal { $ scale = ( $ scale === null ) ? 32 : $ scale ; $ piOverTwo = DecimalConstants :: pi ( ) -> div ( Decimal :: fromInteger ( 2 ) , $ scale + 2 ) ; if ( $ this -> round ( $ scale ) -> isZero ( ) ) { return $ piOverTwo -> round ( $ scale ) ; } $ piOverFour = DecimalConstants :: pi ( ) -> div ( Decimal :: fromInteger ( 4 ) , $ scale + 2 ) ; if ( $ this -> round ( $ scale ) -> equals ( DecimalConstants :: one ( ) ) ) { return $ piOverFour -> round ( $ scale ) ; } if ( $ this -> round ( $ scale ) -> equals ( DecimalConstants :: negativeOne ( ) ) ) { return DecimalConstants :: negativeOne ( ) -> mul ( $ piOverFour , $ scale + 2 ) -> round ( $ scale ) ; } return $ piOverTwo -> sub ( self :: simplePowerSerie ( $ this , DecimalConstants :: zero ( ) , $ scale + 2 ) ) -> round ( $ scale ) ; } | Calculates the arccotangente of this with the highest possible accuracy |
44,351 | public function arcsec ( int $ scale = null ) : Decimal { if ( $ this -> comp ( DecimalConstants :: one ( ) , $ scale + 2 ) === - 1 && $ this -> comp ( DecimalConstants :: negativeOne ( ) , $ scale + 2 ) === 1 ) { throw new \ DomainException ( "The arcsecant of this number is undefined." ) ; } $ piOverTwo = DecimalConstants :: pi ( ) -> div ( Decimal :: fromInteger ( 2 ) , $ scale + 2 ) -> round ( $ scale ) ; if ( $ this -> round ( $ scale ) -> equals ( DecimalConstants :: one ( ) ) ) { return DecimalConstants :: zero ( ) ; } if ( $ this -> round ( $ scale ) -> equals ( DecimalConstants :: negativeOne ( ) ) ) { return DecimalConstants :: pi ( ) -> round ( $ scale ) ; } $ scale = ( $ scale === null ) ? 32 : $ scale ; return $ piOverTwo -> sub ( self :: powerSerie ( DecimalConstants :: one ( ) -> div ( $ this , $ scale + 2 ) , DecimalConstants :: zero ( ) , $ scale + 2 ) ) -> round ( $ scale ) ; } | Calculates the arcsecant of this with the highest possible accuracy |
44,352 | private static function factorialSerie ( Decimal $ x , Decimal $ firstTerm , callable $ generalTerm , int $ scale ) : Decimal { $ approx = $ firstTerm ; $ change = DecimalConstants :: One ( ) ; $ faculty = DecimalConstants :: One ( ) ; $ xPowerN = DecimalConstants :: One ( ) ; for ( $ i = 1 ; ! $ change -> floor ( $ scale + 1 ) -> isZero ( ) ; $ i ++ ) { $ xPowerN = $ xPowerN -> mul ( $ x ) ; $ faculty = $ faculty -> mul ( Decimal :: fromInteger ( $ i ) ) ; $ multiplier = $ generalTerm ( $ i ) ; if ( ! $ multiplier -> isZero ( ) ) { $ change = $ multiplier -> mul ( $ xPowerN , $ scale + 2 ) -> div ( $ faculty , $ scale + 2 ) ; $ approx = $ approx -> add ( $ change , $ scale + 2 ) ; } } return $ approx -> round ( $ scale ) ; } | Internal method used to compute sin cos and exp |
44,353 | private static function powerSerie ( Decimal $ x , Decimal $ firstTerm , int $ scale ) : Decimal { $ approx = $ firstTerm ; $ change = DecimalConstants :: One ( ) ; $ xPowerN = DecimalConstants :: One ( ) ; $ factorN = DecimalConstants :: One ( ) ; $ numerator = DecimalConstants :: one ( ) ; $ denominator = DecimalConstants :: one ( ) ; for ( $ i = 1 ; ! $ change -> floor ( $ scale + 2 ) -> isZero ( ) ; $ i ++ ) { $ xPowerN = $ xPowerN -> mul ( $ x ) ; if ( $ i % 2 === 0 ) { $ factorN = DecimalConstants :: zero ( ) ; } elseif ( $ i === 1 ) { $ factorN = DecimalConstants :: one ( ) ; } else { $ incrementNum = Decimal :: fromInteger ( $ i - 2 ) ; $ numerator = $ numerator -> mul ( $ incrementNum , $ scale + 2 ) ; $ incrementDen = Decimal :: fromInteger ( $ i - 1 ) ; $ increment = Decimal :: fromInteger ( $ i ) ; $ denominator = $ denominator -> div ( $ incrementNum , $ scale + 2 ) -> mul ( $ incrementDen , $ scale + 2 ) -> mul ( $ increment , $ scale + 2 ) ; $ factorN = $ numerator -> div ( $ denominator , $ scale + 2 ) ; } if ( ! $ factorN -> isZero ( ) ) { $ change = $ factorN -> mul ( $ xPowerN , $ scale + 2 ) ; $ approx = $ approx -> add ( $ change , $ scale + 2 ) ; } } return $ approx -> round ( $ scale ) ; } | Internal method used to compute arcsine and arcosine |
44,354 | private static function simplePowerSerie ( Decimal $ x , Decimal $ firstTerm , int $ scale ) : Decimal { $ approx = $ firstTerm ; $ change = DecimalConstants :: One ( ) ; $ xPowerN = DecimalConstants :: One ( ) ; $ sign = DecimalConstants :: One ( ) ; for ( $ i = 1 ; ! $ change -> floor ( $ scale + 2 ) -> isZero ( ) ; $ i ++ ) { $ xPowerN = $ xPowerN -> mul ( $ x ) ; if ( $ i % 2 === 0 ) { $ factorN = DecimalConstants :: zero ( ) ; } else { if ( $ i % 4 === 1 ) { $ factorN = DecimalConstants :: one ( ) -> div ( Decimal :: fromInteger ( $ i ) , $ scale + 2 ) ; } else { $ factorN = DecimalConstants :: negativeOne ( ) -> div ( Decimal :: fromInteger ( $ i ) , $ scale + 2 ) ; } } if ( ! $ factorN -> isZero ( ) ) { $ change = $ factorN -> mul ( $ xPowerN , $ scale + 2 ) ; $ approx = $ approx -> add ( $ change , $ scale + 2 ) ; } } return $ approx -> round ( $ scale ) ; } | Internal method used to compute arctan and arccotan |
44,355 | public function tan ( int $ scale = null ) : Decimal { $ cos = $ this -> cos ( $ scale + 2 ) ; if ( $ cos -> isZero ( ) ) { throw new \ DomainException ( "The tangent of this 'angle' is undefined." ) ; } return $ this -> sin ( $ scale + 2 ) -> div ( $ cos ) -> round ( $ scale ) ; } | Calculates the tangent of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI ; |
44,356 | public function cotan ( int $ scale = null ) : Decimal { $ sin = $ this -> sin ( $ scale + 2 ) ; if ( $ sin -> isZero ( ) ) { throw new \ DomainException ( "The cotangent of this 'angle' is undefined." ) ; } return $ this -> cos ( $ scale + 2 ) -> div ( $ sin ) -> round ( $ scale ) ; } | Calculates the cotangent of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI ; |
44,357 | public function hasSameSign ( Decimal $ b ) : bool { return $ this -> isPositive ( ) && $ b -> isPositive ( ) || $ this -> isNegative ( ) && $ b -> isNegative ( ) ; } | Indicates if the passed parameter has the same sign as the method s bound object . |
44,358 | private static function computeSquareIndex ( string $ exponent_remaining , int $ actual_index , int $ exp_scale , int $ inner_scale ) : array { $ actual_rt = \ bcpow ( '0.5' , ( string ) $ actual_index , $ exp_scale ) ; $ r = \ bcsub ( $ exponent_remaining , $ actual_rt , $ inner_scale ) ; while ( \ bccomp ( $ r , '0' , $ exp_scale ) === - 1 ) { ++ $ actual_index ; $ actual_rt = \ bcmul ( '0.5' , $ actual_rt , $ inner_scale ) ; $ r = \ bcsub ( $ exponent_remaining , $ actual_rt , $ inner_scale ) ; } return [ $ actual_index , $ r ] ; } | Auxiliar method . It helps us to decompose the exponent into many summands . |
44,359 | protected static function paramsValidation ( $ value , int $ scale = null ) { if ( null === $ value ) { throw new \ InvalidArgumentException ( '$value must be a non null number' ) ; } if ( null !== $ scale && $ scale < 0 ) { throw new \ InvalidArgumentException ( '$scale must be a positive integer' ) ; } } | Validates basic constructor s arguments |
44,360 | public static function pi ( ) : Decimal { if ( null === self :: $ PI ) { self :: $ PI = Decimal :: fromString ( "3.14159265358979323846264338327950" ) ; } return self :: $ PI ; } | Returns the Pi number . |
44,361 | public static function eulerMascheroni ( ) : Decimal { if ( null === self :: $ EulerMascheroni ) { self :: $ EulerMascheroni = Decimal :: fromString ( "0.57721566490153286060651209008240" ) ; } return self :: $ EulerMascheroni ; } | Returns the Euler - Mascheroni constant . |
44,362 | public static function goldenRatio ( ) : Decimal { if ( null === self :: $ GoldenRatio ) { self :: $ GoldenRatio = Decimal :: fromString ( "1.61803398874989484820458683436564" ) ; } return self :: $ GoldenRatio ; } | Returns the Golden Ration also named Phi . |
44,363 | public static function silverRatio ( ) : Decimal { if ( null === self :: $ SilverRatio ) { self :: $ SilverRatio = Decimal :: fromString ( "2.41421356237309504880168872420970" ) ; } return self :: $ SilverRatio ; } | Returns the Silver Ratio . |
44,364 | public function afterCompile ( ClassType $ class ) : void { $ method = $ class -> getMethod ( 'initialize' ) ; $ method -> addBody ( sprintf ( '%s::bind($this->getService(?));' , ReCaptchaBinding :: class ) , [ $ this -> prefix ( 'provider' ) ] ) ; $ method -> addBody ( sprintf ( '%s::bind($this->getService(?));' , InvisibleReCaptchaBinding :: class ) , [ $ this -> prefix ( 'provider' ) ] ) ; } | Decorate initialize method |
44,365 | public function dispatchAsyncListenersOnly ( $ eventName , Event $ event = null ) { try { $ this -> asyncListener -> syncMode ( $ eventName ) ; parent :: dispatch ( $ eventName , $ event ) ; } finally { $ this -> asyncListener -> resetSyncMode ( ) ; } } | This method dispatches only those listeners that were marked as async . |
44,366 | protected function createTag ( string $ name , $ value , bool $ prefixed = true ) : OpenGraphTag { return new OpenGraphTag ( $ name , $ value , $ prefixed ) ; } | Creates and returns a new open graph tag object . |
44,367 | public function has ( string $ name ) : bool { foreach ( $ this -> tags as $ tag ) { if ( $ tag -> name == $ name ) { return true ; } } return false ; } | True if at least one tag with the given name exists . It s possible that a tag has multiple values . |
44,368 | public function forget ( string $ name ) : self { foreach ( $ this -> tags as $ key => $ tag ) { if ( $ tag -> name == $ name ) { unset ( $ this -> tags [ $ key ] ) ; } } return $ this ; } | Remove all tags with the given name |
44,369 | public function tag ( string $ name , $ value , bool $ prefixed = true ) : self { $ value = $ this -> convertDate ( $ value ) ; $ this -> tags [ ] = $ this -> createTag ( $ name , $ value , $ prefixed ) ; return $ this ; } | Adds a custom tag to the list of tags |
44,370 | public function attributesstring ( string $ tagName , array $ attributes = [ ] , array $ valid = [ ] , bool $ prefixed = true ) : self { foreach ( $ attributes as $ name => $ value ) { if ( $ this -> validate and sizeof ( $ valid ) > 0 ) { if ( ! in_array ( $ name , $ valid ) ) { throw new Exception ( "Open Graph: Invalid attribute '{$name}' (unknown type)" ) ; } } $ value = $ this -> convertDate ( $ value ) ; $ this -> tags [ ] = $ this -> createTag ( $ tagName . ':' . $ name , $ value , $ prefixed ) ; } return $ this ; } | Adds attribute tags to the list of tags |
44,371 | public function title ( string $ title ) : self { $ title = trim ( $ title ) ; if ( $ this -> validate and ! $ title ) { throw new Exception ( "Open Graph: Invalid title (empty)" ) ; } $ this -> forget ( 'title' ) ; $ this -> tags [ ] = $ this -> createTag ( 'title' , strip_tags ( $ title ) ) ; return $ this ; } | Adds a title tag |
44,372 | public function type ( string $ type ) : self { $ types = [ 'music.song' , 'music.album' , 'music.playlist' , 'music.radio_station' , 'video.movie' , 'video.episode' , 'video.tv_show' , 'video.other' , 'article' , 'book' , 'profile' , 'website' , ] ; if ( $ this -> validate and ! in_array ( $ type , $ types ) ) { throw new Exception ( "Open Graph: Invalid type '{$type}' (unknown type)" ) ; } $ this -> forget ( 'type' ) ; $ this -> tags [ ] = $ this -> createTag ( 'type' , $ type ) ; return $ this ; } | Adds a type tag . |
44,373 | public function image ( string $ imageFile , array $ attributes = null ) : self { if ( $ this -> validate and ! $ imageFile ) { throw new Exception ( "Open Graph: Invalid image URL (empty)" ) ; } if ( strpos ( $ imageFile , '://' ) === false and function_exists ( 'asset' ) ) { $ imageFile = asset ( $ imageFile ) ; } if ( $ this -> validate and ! filter_var ( $ imageFile , FILTER_VALIDATE_URL ) ) { throw new Exception ( "Open Graph: Invalid image URL '{$imageFile}'" ) ; } $ this -> tags [ ] = $ this -> createTag ( 'image' , $ imageFile ) ; if ( $ attributes ) { $ valid = [ 'secure_url' , 'type' , 'width' , 'height' , ] ; $ this -> attributes ( 'image' , $ attributes , $ valid ) ; } return $ this ; } | Adds an image tag . If the URL is relative it s converted to an absolute one . |
44,374 | public function description ( string $ description , int $ maxLength = 250 ) : self { $ description = trim ( strip_tags ( $ description ) ) ; $ description = preg_replace ( "/\r|\n/" , '' , $ description ) ; $ length = mb_strlen ( $ description ) ; $ description = mb_substr ( $ description , 0 , $ maxLength ) ; if ( mb_strlen ( $ description ) < $ length ) { $ description .= '...' ; } $ this -> forget ( 'description' ) ; $ this -> tags [ ] = $ this -> createTag ( 'description' , $ description ) ; return $ this ; } | Adds a description tag |
44,375 | public function url ( string $ url = null ) : self { if ( ! $ url ) { $ url = null ; $ httpHost = getenv ( 'APP_URL' ) ; if ( $ httpHost === false ) { $ url = 'http' ; if ( isset ( $ _SERVER [ 'HTTPS' ] ) ) { $ url .= 's' ; } $ url .= '://' ; $ httpHost = isset ( $ _SERVER [ 'HTTP_HOST' ] ) ? $ _SERVER [ 'HTTP_HOST' ] : 'localhost/' ; } $ requestUri = isset ( $ _SERVER [ 'REQUEST_URI' ] ) ? $ _SERVER [ 'REQUEST_URI' ] : '' ; $ safeRequestURI = htmlentities ( strip_tags ( urldecode ( $ requestUri ) ) ) ; $ url .= "{$httpHost}{$safeRequestURI}" ; } if ( $ this -> validate and ! filter_var ( $ url , FILTER_VALIDATE_URL ) ) { throw new Exception ( "Open Graph: Invalid URL '{$url}'" ) ; } $ this -> forget ( 'url' ) ; $ this -> tags [ ] = $ this -> createTag ( 'url' , $ url ) ; return $ this ; } | Adds a URL tag |
44,376 | public function locale ( string $ locale ) : self { if ( $ this -> validate and ! $ locale ) { throw new Exception ( "Open Graph: Invalid locale (none set)" ) ; } $ this -> forget ( 'locale' ) ; $ this -> tags [ ] = $ this -> createTag ( 'locale' , $ locale ) ; return $ this ; } | Adds a locale tag |
44,377 | public function siteName ( string $ siteName ) : self { if ( $ this -> validate and ! $ siteName ) { throw new Exception ( "Open Graph: Invalid site_name (empty)" ) ; } $ this -> forget ( 'site_name' ) ; $ this -> tags [ ] = $ this -> createTag ( 'site_name' , $ siteName ) ; return $ this ; } | Adds a site_name tag |
44,378 | public function determiner ( string $ determiner = '' ) : self { $ enum = [ 'a' , 'an' , 'the' , 'auto' , '' ] ; if ( $ this -> validate and ! in_array ( $ determiner , $ enum ) ) { throw new Exception ( "Open Graph: Invalid determiner '{$determiner}' (unkown value)" ) ; } $ this -> tags [ ] = $ this -> createTag ( 'determiner' , $ determiner ) ; return $ this ; } | Adds a determiner tag . |
44,379 | public function audio ( string $ audioFile , array $ attributes = null ) : self { if ( $ this -> validate and ! $ audioFile ) { throw new Exception ( "Open Graph: Invalid audio URL (empty)" ) ; } if ( strpos ( $ audioFile , '://' ) === false and function_exists ( 'asset' ) ) { $ audioFile = asset ( $ audioFile ) ; } if ( $ this -> validate and ! filter_var ( $ audioFile , FILTER_VALIDATE_URL ) ) { throw new Exception ( "Open Graph: Invalid audio URL '{$audioFile}'" ) ; } $ this -> tags [ ] = $ this -> createTag ( 'audio' , $ audioFile ) ; if ( $ attributes ) { $ valid = [ 'secure_url' , 'type' , ] ; $ tag = $ this -> lastTag ( 'type' ) ; $ specialValid = [ ] ; if ( $ tag and $ tag -> name == 'music.song' ) { $ specialValid = [ 'duration' , 'album' , 'album:disc' , 'album:track' , 'musician' , ] ; } if ( $ tag and $ tag -> name == 'music.album' ) { $ specialValid = [ 'song' , 'song:disc' , 'song:track' , 'musician' , 'release_date' , ] ; } if ( $ tag and $ tag -> name == 'music.playlist' ) { $ specialValid = [ 'song' , 'song:disc' , 'song:track' , 'creator' , ] ; } if ( $ tag and $ tag -> name == 'music.radio_station' ) { $ specialValid = [ 'creator' , ] ; } $ valid = array_merge ( $ valid , $ specialValid ) ; $ this -> attributes ( 'audio' , $ attributes , $ valid ) ; } return $ this ; } | Adds an audio tag . If the URL is relative its converted to an absolute one . |
44,380 | public function video ( string $ videoFile , array $ attributes = null ) : self { if ( $ this -> validate and ! $ videoFile ) { throw new Exception ( "Open Graph: Invalid video URL (empty)" ) ; } if ( strpos ( $ videoFile , '://' ) === false and function_exists ( 'asset' ) ) { $ videoFile = asset ( $ videoFile ) ; } if ( $ this -> validate and ! filter_var ( $ videoFile , FILTER_VALIDATE_URL ) ) { throw new Exception ( "Open Graph: Invalid video URL '{$videoFile}'" ) ; } $ this -> tags [ ] = $ this -> createTag ( 'video' , $ videoFile ) ; if ( $ attributes ) { $ valid = [ 'secure_url' , 'type' , 'width' , 'height' , ] ; $ tag = $ this -> lastTag ( 'type' ) ; if ( $ tag and starts_with ( $ tag -> value , 'video.' ) ) { $ specialValid = [ 'actor' , 'role' , 'director' , 'writer' , 'duration' , 'release_date' , 'tag' , ] ; if ( $ tag -> value == 'video.episode' ) { $ specialValid [ ] = 'video:series' ; } $ valid = array_merge ( $ valid , $ specialValid ) ; } $ this -> attributes ( 'video' , $ attributes , $ valid ) ; } return $ this ; } | Adds a video tag If the URL is relative its converted to an absolute one . |
44,381 | public function book ( array $ attributes = [ ] ) : self { $ tag = $ this -> lastTag ( 'type' ) ; if ( ! $ tag or $ tag -> value != 'book' ) { throw new Exception ( "Open Graph: Type has to be 'book' to add book attributes" ) ; } $ valid = [ 'author' , 'isbn' , 'release_date' , 'tag' , ] ; $ this -> unprefixedAttributes ( 'book' , $ attributes ) ; return $ this ; } | Adds book attributes |
44,382 | public function renderTags ( ) : string { $ output = '' ; $ vars = [ '{{name}}' , '{{value}}' ] ; foreach ( $ this -> tags as $ tag ) { $ name = $ tag -> name ; if ( $ tag -> prefixed ) { $ name = self :: NAME_PREFIX . $ name ; } $ output .= str_replace ( $ vars , [ $ name , $ tag -> value ] , $ this -> template ) ; } return $ output ; } | Returns the Open Graph tags rendered as HTML |
44,383 | public function lastTag ( string $ name ) { $ lastTag = null ; foreach ( $ this -> tags as $ tag ) { if ( $ tag -> name == $ name ) { $ lastTag = $ tag ; } } return $ lastTag ; } | Returns the last tag in the lists of tags with matching name |
44,384 | protected function setAttribute ( string $ name , $ value ) : void { switch ( $ name ) { case 'name' : case 'value' : $ value = ( string ) $ value ; break ; case 'prefixed' : $ value = ( boolean ) $ value ; break ; } $ this -> $ name = $ value ; } | Sets an object attribute to a value . |
44,385 | public static function find ( $ id , $ columns = array ( '*' ) ) { $ key = ( new static ) -> getKeyName ( ) ; if ( ctype_print ( $ id ) ) { $ idFinal = ( property_exists ( static :: class , 'uuidOptimization' ) && static :: $ uuidOptimization ) ? self :: toOptimized ( $ id ) : hex2bin ( $ id ) ; return static :: where ( $ key , '=' , $ idFinal ) -> first ( $ columns ) ; } else { return parent :: where ( $ key , '=' , $ id ) -> first ( $ columns ) ; } } | Modified find static function to accept both string and binary versions of uuid |
44,386 | public static function findOrFail ( $ id , $ columns = array ( '*' ) ) { $ key = ( new static ) -> getKeyName ( ) ; if ( ctype_print ( $ id ) ) { $ idFinal = ( property_exists ( static :: class , 'uuidOptimization' ) && static :: $ uuidOptimization ) ? self :: toOptimized ( $ id ) : hex2bin ( $ id ) ; return static :: where ( $ key , '=' , $ idFinal ) -> firstOrFail ( $ columns ) ; } else { return parent :: where ( $ key , '=' , $ id ) -> firstOrFail ( $ columns ) ; } } | Modified findOrFail static function to accept both string and binary versions of uuid |
44,387 | protected function createPreOneTwentySeven ( $ params ) { $ newParams = [ 'name' => $ params [ 'username' ] , 'password' => $ params [ 'password' ] , ] ; if ( array_key_exists ( 'email' , $ params ) ) { $ newParams [ 'email' ] = $ params [ 'email' ] ; } $ tokenRequest = new SimpleRequest ( 'createaccount' , $ newParams ) ; $ result = $ this -> api -> postRequest ( $ tokenRequest ) ; if ( $ result [ 'createaccount' ] [ 'result' ] == 'NeedToken' ) { $ newParams [ 'token' ] = $ result [ 'createaccount' ] [ 'token' ] ; $ request = new SimpleRequest ( 'createaccount' , $ newParams ) ; $ result = $ this -> api -> postRequest ( $ request ) ; } return ( $ result [ 'createaccount' ] [ 'result' ] === 'Success' ) ; } | Create a user in the pre 1 . 27 manner . |
44,388 | protected function uploadByChunks ( $ params ) { $ fileHandle = $ params [ 'file' ] ; unset ( $ params [ 'file' ] ) ; $ chunksDone = 0 ; $ params [ 'offset' ] = 0 ; while ( true ) { $ params [ 'chunk' ] = fread ( $ fileHandle , $ this -> chunkSize ) ; $ contentDisposition = 'form-data; name="chunk"; filename="' . $ params [ 'filename' ] . '"' ; $ request = MultipartRequest :: factory ( ) -> setParams ( $ params ) -> setAction ( 'upload' ) -> setMultipartParams ( [ 'chunk' => [ 'headers' => [ 'Content-Disposition' => $ contentDisposition ] ] , ] ) ; $ response = $ this -> api -> postRequest ( $ request ) ; $ chunksDone ++ ; $ params [ 'offset' ] = ( $ chunksDone * $ this -> chunkSize ) ; if ( ! isset ( $ response [ 'upload' ] [ 'filekey' ] ) ) { throw new Exception ( 'Unable to get filekey for chunked upload' ) ; } $ params [ 'filekey' ] = $ response [ 'upload' ] [ 'filekey' ] ; if ( $ response [ 'upload' ] [ 'result' ] === 'Continue' ) { $ params [ 'offset' ] = $ response [ 'upload' ] [ 'offset' ] ; } else { unset ( $ params [ 'chunk' ] , $ params [ 'offset' ] ) ; return $ params ; } } } | Upload a file by chunks and get the parameters for the final upload call . |
44,389 | public function addCallback ( $ type , $ callback ) { if ( ! isset ( $ this -> callbacks [ $ type ] ) ) { $ this -> callbacks [ $ type ] = [ ] ; } $ this -> callbacks [ $ type ] [ ] = $ callback ; } | Register a callback that will be called for each page or category visited during the traversal . |
44,390 | protected function call ( $ type , $ params ) { if ( ! isset ( $ this -> callbacks [ $ type ] ) ) { return ; } foreach ( $ this -> callbacks [ $ type ] as $ callback ) { if ( is_callable ( $ callback ) ) { call_user_func_array ( $ callback , $ params ) ; } } } | Call all the registered callbacks of a particular type . |
44,391 | public function getNamespaceByCanonicalName ( $ canonicalName ) { $ result = $ this -> getNamespaceResult ( ) [ 'query' ] ; foreach ( $ result [ 'namespaces' ] as $ nsInfo ) { if ( ! empty ( $ nsInfo [ 'canonical' ] ) && $ nsInfo [ 'canonical' ] === $ canonicalName ) { return $ this -> createNamespaceFromQuery ( $ nsInfo , $ result [ 'namespacealiases' ] ) ; } } return null ; } | Find a namespace by its canonical name |
44,392 | public function getNamespaceByName ( $ name ) { $ result = $ this -> getNamespaceResult ( ) [ 'query' ] ; foreach ( $ result [ 'namespaces' ] as $ nsInfo ) { if ( ( ! empty ( $ nsInfo [ 'canonical' ] ) && $ nsInfo [ 'canonical' ] === $ name ) || $ nsInfo [ '*' ] === $ name ) { return $ this -> createNamespaceFromQuery ( $ nsInfo , $ result [ 'namespacealiases' ] ) ; } } foreach ( $ result [ 'namespacealiases' ] as $ alias ) { if ( $ alias [ '*' ] === $ name && ! empty ( $ result [ 'namespaces' ] [ $ alias [ 'id' ] ] ) ) { return $ this -> createNamespaceFromQuery ( $ result [ 'namespaces' ] [ $ alias [ 'id' ] ] , $ result [ 'namespacealiases' ] ) ; } } return null ; } | Find a namespace by its canonical name local name or namespace alias |
44,393 | public function getPageListFromPageTransclusions ( $ pageName , array $ extraParams = [ ] ) { $ params = array_merge ( $ extraParams , [ 'list' => 'embeddedin' , 'eititle' => $ pageName , ] ) ; return $ this -> runQuery ( $ params , 'eicontinue' , 'embeddedin' ) ; } | List pages that transclude a certain page . |
44,394 | public function getFromWhatLinksHere ( $ pageName , $ extraParams = [ ] ) { $ params = array_merge ( $ extraParams , [ 'prop' => 'info' , 'generator' => 'linkshere' , 'titles' => $ pageName , ] ) ; return $ this -> runQuery ( $ params , 'glhcontinue' , 'pages' ) ; } | Get all pages that link to the given page . |
44,395 | public function getLinksFromHere ( $ pageName , $ extraParams = [ ] ) { $ params = array_merge ( $ extraParams , [ 'prop' => 'info' , 'generator' => 'links' , 'titles' => $ pageName , ] ) ; return $ this -> runQuery ( $ params , 'gplcontinue' , 'pages' ) ; } | Get all pages that are linked to from the given page . |
44,396 | public function getRandom ( array $ extraParams = [ ] ) { $ params = array_merge ( $ extraParams , [ 'list' => 'random' ] ) ; return $ this -> runQuery ( $ params , null , 'random' , 'id' , false ) ; } | Get up to 10 random pages . |
44,397 | protected function runQuery ( $ params , $ contName , $ resName , $ pageIdName = 'pageid' , $ cont = true ) { $ pages = new Pages ( ) ; $ negativeId = - 1 ; do { if ( isset ( $ result [ 'continue' ] [ $ contName ] ) ) { $ params [ $ contName ] = $ result [ 'continue' ] [ $ contName ] ; } $ result = $ this -> api -> getRequest ( new SimpleRequest ( 'query' , $ params ) ) ; if ( ! array_key_exists ( 'query' , $ result ) ) { return $ pages ; } foreach ( $ result [ 'query' ] [ $ resName ] as $ member ) { if ( ! array_key_exists ( $ pageIdName , $ member ) ) { $ member [ $ pageIdName ] = $ negativeId ; $ negativeId = $ negativeId - 1 ; } $ pageTitle = new Title ( $ member [ 'title' ] , $ member [ 'ns' ] ) ; $ page = new Page ( new PageIdentifier ( $ pageTitle , $ member [ $ pageIdName ] ) ) ; $ pages -> addPage ( $ page ) ; } } while ( $ cont && isset ( $ result [ 'continue' ] ) ) ; return $ pages ; } | Run a query to completion . |
44,398 | public function afterExercise ( ExerciseCompleted $ event ) { if ( $ this -> skipCoverage ) { return ; } $ this -> reportService -> generateReport ( $ this -> coverage ) ; } | After Exercise hook |
44,399 | public function update ( $ class , array $ counts ) { if ( ! isset ( $ this -> coverage [ $ class ] ) ) { $ this -> coverage [ $ class ] = $ counts ; return ; } foreach ( $ counts as $ line => $ status ) { if ( ! isset ( $ this -> coverage [ $ class ] [ $ line ] ) || $ status > 0 ) { $ status = ! $ status ? - 1 : ( $ status > 1 ? 1 : $ status ) ; $ this -> coverage [ $ class ] [ $ line ] = $ status ; } } } | Update aggregated coverage |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.