idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
1,600
public static function get ( $ array , $ key = null , $ default = null , $ useDotSyntax = false ) { if ( empty ( $ array ) ) { return $ default ; } if ( is_null ( $ key ) ) { return $ array ; } if ( isset ( $ array [ $ key ] ) ) { return $ array [ $ key ] ; } if ( ! $ useDotSyntax ) { return $ default ; } $ keyParts = explode ( '.' , $ key ) ; if ( count ( $ keyParts ) == 1 ) { return isset ( $ array [ $ key ] ) ? $ array [ $ key ] : $ default ; } $ base = $ keyParts [ 0 ] ; unset ( $ keyParts [ 0 ] ) ; if ( ! isset ( $ array [ $ base ] ) ) { return $ default ; } $ key = implode ( '.' , $ keyParts ) ; $ array = $ array [ $ base ] ; return static :: get ( $ array , $ key , $ default , $ useDotSyntax ) ; }
Get an item from an array .
1,601
public static function filter ( array $ array , $ callback = null , $ default = [ ] , $ length = null ) { $ result = [ ] ; if ( is_callable ( $ callback ) ) { foreach ( $ array as $ key => $ value ) { if ( call_user_func ( $ callback , $ key , $ value ) ) { $ result [ $ key ] = $ value ; } } } else { reset ( $ array ) ; $ result = empty ( $ array ) ? null : $ array ; } return $ result ? array_slice ( $ result , 0 , $ length ) : EvalHelper :: evaluate ( $ default ) ; }
Filter array elements with a given callback function .
1,602
public static function merge ( array $ array1 , array $ array2 , $ deep = false ) { if ( ! $ deep ) { return array_merge ( $ array1 , $ array2 ) ; } $ merged = $ array1 ; foreach ( $ array2 as $ key => $ value ) { if ( is_array ( $ value ) && isset ( $ merged [ $ key ] ) && is_array ( $ merged [ $ key ] ) ) { $ merged [ $ key ] = static :: merge ( $ merged [ $ key ] , $ value , $ deep ) ; } else if ( is_numeric ( $ key ) ) { if ( ! in_array ( $ value , $ merged ) ) { $ merged [ ] = $ value ; } } else { $ merged [ $ key ] = $ value ; } } return $ merged ; }
Perform a merge on the given two arrays . Deep merge will merge the two arrays in full depth .
1,603
public static function toKeyIndex ( $ collection , $ key , $ useDotSyntax = false ) { $ keyIndexArray = [ ] ; foreach ( $ collection as $ item ) { $ itemArray = is_array ( $ item ) ? $ item : ( method_exists ( $ item , 'toArray' ) ? $ item -> toArray ( ) : [ ] ) ; $ keyValue = self :: get ( $ itemArray , $ key , null , $ useDotSyntax ) ; $ keyIndexArray [ $ keyValue ] = $ itemArray ; } return $ keyIndexArray ; }
Return the array and replace the default keys with the values of the array based on the given key .
1,604
public static function toKeyGroup ( $ collection , $ key , $ useDotSyntax = false ) { $ keyGroupArray = [ ] ; foreach ( $ collection as $ item ) { $ itemArray = is_array ( $ item ) ? $ item : ( method_exists ( $ item , 'toArray' ) ? $ item -> toArray ( ) : [ ] ) ; $ keyValue = self :: get ( $ itemArray , $ key , null , $ useDotSyntax ) ; $ keyGroupArray [ $ keyValue ] [ ] = $ itemArray ; } return $ keyGroupArray ; }
Group all array items by the given key .
1,605
public static function toKeyValue ( $ collection , $ key , $ value , $ useDotSyntax = false ) { $ keyValueArray = [ ] ; foreach ( $ collection as $ item ) { $ itemArray = is_array ( $ item ) ? $ item : ( method_exists ( $ item , 'toArray' ) ? $ item -> toArray ( ) : [ ] ) ; $ keyValue = self :: get ( $ itemArray , $ key , null , $ useDotSyntax ) ; $ keyValueArray [ $ keyValue ] = $ itemArray [ $ value ] ; } return $ keyValueArray ; }
Return the array in a key - value form based on the given parameters for key and value .
1,606
public static function sortByKey ( $ array , $ key , $ useDotSyntax = false ) { uasort ( $ array , function ( $ a , $ b ) use ( $ key , $ useDotSyntax ) { $ valueA = self :: get ( $ a , $ key , null , $ useDotSyntax ) ; $ valueB = self :: get ( $ b , $ key , null , $ useDotSyntax ) ; if ( $ valueA == $ valueB ) { return 0 ; } return ( $ valueA < $ valueB ) ? - 1 : 1 ; } ) ; return $ array ; }
Sort an array by a given value based on the given key .
1,607
public function run ( ManifestInterface $ manifest ) { $ builder = new ProcedureBuilder ( ) ; $ processor = $ manifest -> getProcessor ( ) ; if ( $ this -> dispatcher ) { $ processor -> setEventDispatcher ( $ this -> dispatcher ) ; } $ manifest -> configureProcedureBuilder ( $ builder ) ; $ manifest -> configureProcessor ( $ manifest -> getProcessor ( ) ) ; $ procedure = $ builder -> getProcedure ( ) ; $ processor -> addProcedure ( $ procedure ) -> process ( ) ; }
Configures and runs a manifest .
1,608
public static function create ( $ realPart , $ imaginaryPart = null ) { if ( is_string ( $ realPart ) ) { return self :: fromString ( $ realPart ) ; } if ( $ realPart instanceof ComplexType ) { return clone $ realPart ; } if ( is_null ( $ imaginaryPart ) ) { $ imaginaryPart = 0 ; } $ real = self :: convertType ( $ realPart ) ; $ imaginary = self :: convertType ( $ imaginaryPart ) ; if ( self :: getRequiredType ( ) == self :: TYPE_GMP ) { return new GMPComplexType ( $ real , $ imaginary ) ; } return new ComplexType ( $ real , $ imaginary ) ; }
Complex type factory
1,609
public static function fromPolar ( AbstractRationalType $ radius , AbstractRationalType $ theta ) { if ( self :: getRequiredType ( ) == self :: TYPE_GMP ) { return self :: fromGmpPolar ( $ radius , $ theta ) ; } return self :: fromNativePolar ( $ radius , $ theta ) ; }
Create complex type from polar co - ordinates
1,610
public static function fromNativePolar ( RationalType $ radius , RationalType $ theta ) { $ cos = RationalTypeFactory :: fromFloat ( cos ( $ theta ( ) ) ) ; $ sin = RationalTypeFactory :: fromFloat ( sin ( $ theta ( ) ) ) ; list ( $ realNumerator , $ realDenominator ) = self :: getRealPartsFromRadiusAndCos ( $ radius , $ cos ) ; list ( $ imaginaryNumerator , $ imaginaryDenominator ) = self :: getImaginaryPartsFromRadiusAndSin ( $ radius , $ sin ) ; $ realPart = RationalTypeFactory :: create ( $ realNumerator , $ realDenominator ) ; $ imaginaryPart = RationalTypeFactory :: create ( $ imaginaryNumerator , $ imaginaryDenominator ) ; return new ComplexType ( $ realPart , $ imaginaryPart ) ; }
Create complex type from polar co - ordinates - Native version
1,611
public static function fromGmpPolar ( GMPRationalType $ radius , GMPRationalType $ theta ) { $ cos = RationalTypeFactory :: fromFloat ( cos ( $ theta ( ) ) ) ; $ sin = RationalTypeFactory :: fromFloat ( sin ( $ theta ( ) ) ) ; $ rNum = TypeFactory :: create ( 'int' , gmp_strval ( gmp_mul ( $ radius -> numerator ( ) -> gmp ( ) , $ cos -> numerator ( ) -> gmp ( ) ) ) ) ; $ rDen = TypeFactory :: create ( 'int' , gmp_strval ( gmp_mul ( $ radius -> denominator ( ) -> gmp ( ) , $ cos -> denominator ( ) -> gmp ( ) ) ) ) ; $ iNum = TypeFactory :: create ( 'int' , gmp_strval ( gmp_mul ( $ radius -> numerator ( ) -> gmp ( ) , $ sin -> numerator ( ) -> gmp ( ) ) ) ) ; $ iDen = TypeFactory :: create ( 'int' , gmp_strval ( gmp_mul ( $ radius -> denominator ( ) -> gmp ( ) , $ sin -> denominator ( ) -> gmp ( ) ) ) ) ; return new GMPComplexType ( RationalTypeFactory :: create ( $ rNum , $ rDen ) , RationalTypeFactory :: create ( $ iNum , $ iDen ) ) ; }
Create complex type from polar co - ordinates - GMP version
1,612
protected static function convertType ( $ original ) { if ( $ original instanceof AbstractRationalType ) { return RationalTypeFactory :: create ( $ original -> numerator ( ) -> get ( ) , $ original -> denominator ( ) -> get ( ) ) ; } if ( is_numeric ( $ original ) ) { if ( is_int ( $ original ) ) { return RationalTypeFactory :: create ( $ original , 1 ) ; } return RationalTypeFactory :: fromFloat ( floatval ( $ original ) ) ; } if ( $ original instanceof FloatType ) { return RationalTypeFactory :: fromFloat ( $ original ( ) ) ; } if ( $ original instanceof IntType ) { return RationalTypeFactory :: create ( $ original , 1 ) ; } if ( is_string ( $ original ) ) { try { return RationalTypeFactory :: fromString ( $ original ) ; } catch ( \ InvalidArgumentException $ e ) { throw new InvalidTypeException ( "{$original} for Complex type construction" ) ; } } $ type = gettype ( $ original ) ; throw new InvalidTypeException ( "{$type} for Complex type construction" ) ; }
Convert to RationalType
1,613
public function listFiles ( $ depth = 0 , $ filter = null , $ asHandlers = false ) { return $ this -> listContents ( $ depth , $ filter , 'file' , $ asHandlers ) ; }
Lists all files in a directory
1,614
public function listDirs ( $ depth = 0 , $ filter = null , $ asHandlers = false ) { return $ this -> listContents ( $ depth , $ filter , 'dir' , $ asHandlers ) ; }
Lists all directories in a directory
1,615
public function listContents ( $ depth = 0 , $ filter = null , $ type = 'all' , $ asHandlers = false ) { $ pattern = $ this -> path . '/*' ; if ( is_array ( $ filter ) ) { $ filters = $ filter ; $ filter = new Filter ; foreach ( $ filters as $ f => $ type ) { if ( ! is_int ( $ f ) ) { $ f = $ type ; $ type = null ; } $ expected = true ; if ( strpos ( $ f , '!' ) === 0 ) { $ f = substr ( $ f , 1 ) ; $ expected = false ; } $ filter -> addFilter ( $ f , $ expected , $ type ) ; } } if ( $ filter instanceof \ Closure ) { $ callback = $ filter ; $ filter = new Filter ( ) ; $ callback ( $ filter ) ; } if ( ! $ filter ) { $ filter = new Filter ; } $ flags = GLOB_MARK ; if ( $ type === 'file' and ! pathinfo ( $ pattern , PATHINFO_EXTENSION ) ) { $ pattern .= '.*' ; } elseif ( $ type === 'dir' ) { $ flags = GLOB_MARK | GLOB_ONLYDIR ; } $ contents = glob ( $ pattern , $ flags ) ; $ contents = $ filter -> filter ( $ contents ) ; if ( $ depth and $ depth !== true ) { $ depth -- ; } $ formatted = array ( ) ; foreach ( $ contents as $ item ) { if ( $ filter -> isCorrectType ( 'dir' , $ item ) ) { $ _contents = array ( ) ; if ( ( $ depth === true or $ depth === 0 ) and ! $ asHandlers ) { $ dir = new Directory ( $ item ) ; $ _contents = $ dir -> listContents ( $ item , $ filter , $ depth , $ type ) ; } if ( $ asHandlers ) { $ formatted [ ] = new Directory ( $ item ) ; } else { $ formatted [ $ item ] = $ _contents ; } } elseif ( $ filter -> isCorrectType ( 'file' , $ item ) ) { if ( $ asHandlers ) { $ item = new File ( $ item ) ; } $ formatted [ ] = $ item ; } } return $ formatted ; }
Lists all files and directories in a directory
1,616
private function loadAssignments ( $ userId ) { if ( ! isset ( $ this -> _assignments [ $ userId ] ) ) { $ query = ( new Query ) -> select ( 'item_name' ) -> from ( $ this -> assignmentTable ) -> where ( [ 'user_id' => $ userId ] ) ; $ this -> _assignments [ $ userId ] = $ query -> column ( $ this -> db ) ; } }
Load data . If avaliable in memory get from memory If no get from cache . If no avaliable get from database .
1,617
public function route ( Application $ app , Request $ request ) { $ url = $ request -> getPathInfo ( ) ; $ method = $ request -> getMethod ( ) ; foreach ( $ this -> routes as $ route ) { if ( $ route -> getMethod ( ) == $ method ) { $ matches = $ route -> matches ( $ url ) ; if ( $ matches !== false ) { $ app [ 'emitter' ] -> emit ( self :: EVENT_MATCH , [ $ app , $ request , $ route ] ) ; return $ route -> run ( $ app , $ request , $ matches ) ; } } } $ app [ 'emitter' ] -> emit ( self :: EVENT_NO_MATCH , [ $ app , $ request ] ) ; return new Response ( "Page not found" , Response :: HTTP_NOT_FOUND ) ; }
Routes the request and returns a Response .
1,618
public function getRoute ( $ name ) { if ( empty ( $ name ) ) { throw new \ InvalidArgumentException ( "Route name not provided." ) ; } foreach ( $ this -> routes as $ route ) { if ( $ route -> getName ( ) === $ name ) { return $ route ; } } throw new \ Exception ( "Route \"$name\" not found." ) ; }
Returns a route by name .
1,619
public function checkAccess ( $ attributes , $ object = null , string $ message = 'Access Denied.' ) { $ this -> denyAccessUnlessGranted ( $ attributes , $ object , $ message ) ; }
Throws an exception unless the attributes are granted against the current authentication token and optionally supplied object .
1,620
public function seek ( $ offset , $ whence = SEEK_SET ) { if ( ! is_int ( $ offset ) && ! is_numeric ( $ offset ) ) { return false ; } $ offset = ( int ) $ offset ; if ( $ offset < 0 ) { return false ; } $ key = $ this -> iterator -> key ( ) ; if ( ! is_int ( $ key ) && ! is_numeric ( $ key ) ) { $ key = 0 ; $ this -> iterator -> rewind ( ) ; } if ( $ key >= $ offset ) { $ key = 0 ; $ this -> iterator -> rewind ( ) ; } while ( $ this -> iterator -> valid ( ) && $ key < $ offset ) { $ this -> iterator -> next ( ) ; ++ $ key ; } $ this -> position = $ key ; return true ; }
Seek the iterator .
1,621
public function request ( $ message_name , $ request_datum ) { $ io = new AvroStringIO ( ) ; $ encoder = new AvroIOBinaryEncoder ( $ io ) ; $ this -> write_handshake_request ( $ encoder ) ; $ this -> write_call_request ( $ message_name , $ request_datum , $ encoder ) ; $ call_request = $ io -> string ( ) ; if ( $ this -> local_protocol -> messages [ $ message_name ] -> is_one_way ( ) ) { $ this -> transceiver -> write_message ( $ call_request ) ; if ( ! $ this -> transceiver -> is_connected ( ) ) { $ handshake_response = $ this -> transceiver -> read_message ( ) ; $ io = new AvroStringIO ( $ handshake_response ) ; $ decoder = new AvroIOBinaryDecoder ( $ io ) ; $ this -> read_handshake_response ( $ decoder ) ; } return true ; } else { $ call_response = $ this -> transceiver -> transceive ( $ call_request ) ; $ io = new AvroStringIO ( $ call_response ) ; $ decoder = new AvroIOBinaryDecoder ( $ io ) ; $ call_response_exists = $ this -> read_handshake_response ( $ decoder ) ; if ( $ call_response_exists ) { $ call_response = $ this -> read_call_response ( $ message_name , $ decoder ) ; return $ call_response ; } else return $ this -> request ( $ message_name , $ request_datum ) ; } }
Writes a request message and reads a response or error message .
1,622
public function write_handshake_request ( AvroIOBinaryEncoder $ encoder ) { if ( $ this -> transceiver -> is_connected ( ) ) return ; $ remote_name = $ this -> transceiver -> remote_name ( ) ; $ local_hash = $ this -> local_protocol -> md5 ( ) ; $ remote_hash = ( ! isset ( $ this -> remote_hash [ $ remote_name ] ) ) ? null : $ this -> remote_hash [ $ remote_name ] ; if ( is_null ( $ remote_hash ) ) { $ remote_hash = $ local_hash ; $ this -> remote = $ this -> local_protocol ; } else { $ this -> remote = $ this -> remote_protocol [ $ remote_name ] ; } $ request_datum = array ( 'clientHash' => $ local_hash , 'serverHash' => $ remote_hash , 'meta' => null ) ; $ request_datum [ "clientProtocol" ] = ( $ this -> send_protocol ) ? $ this -> local_protocol -> __toString ( ) : null ; $ this -> handshake_requestor_writer -> write ( $ request_datum , $ encoder ) ; }
Write the handshake request .
1,623
public function read_handshake_response ( AvroIOBinaryDecoder $ decoder ) { if ( $ this -> transceiver -> is_connected ( ) ) return true ; $ established = false ; $ handshake_response = $ this -> handshake_requestor_reader -> read ( $ decoder ) ; $ match = $ handshake_response [ "match" ] ; switch ( $ match ) { case 'BOTH' : $ established = true ; $ this -> send_protocol = false ; break ; case 'CLIENT' : $ established = true ; $ this -> send_protocol = false ; $ this -> set_remote ( $ handshake_response ) ; break ; case 'NONE' : $ this -> send_protocol = true ; $ this -> set_remote ( $ handshake_response ) ; $ established = false ; break ; default : throw new AvroException ( "Bad handshake response match: $match" ) ; } if ( $ established ) $ this -> transceiver -> set_remote ( $ this -> remote ) ; return $ established ; }
Reads and processes the handshake response message .
1,624
public function process_handshake ( AvroIOBinaryDecoder $ decoder , AvroIOBinaryEncoder $ encoder , Transceiver $ transceiver ) { if ( $ transceiver -> is_connected ( ) ) return $ transceiver -> get_remote ( ) ; $ handshake_request = $ this -> handshake_responder_reader -> read ( $ decoder ) ; $ client_hash = $ handshake_request [ "clientHash" ] ; $ client_protocol = $ handshake_request [ "clientProtocol" ] ; $ remote_protocol = $ this -> get_protocol_cache ( $ client_hash ) ; if ( is_null ( $ remote_protocol ) && ! is_null ( $ client_protocol ) ) { $ remote_protocol = AvroProtocol :: parse ( $ client_protocol ) ; $ this -> set_protocol_cache ( $ client_hash , $ remote_protocol ) ; } $ server_hash = $ handshake_request [ "serverHash" ] ; $ handshake_response = array ( ) ; if ( $ this -> local_hash == $ server_hash ) $ handshake_response [ 'match' ] = ( is_null ( $ remote_protocol ) ) ? 'NONE' : 'BOTH' ; else $ handshake_response [ 'match' ] = ( is_null ( $ remote_protocol ) ) ? 'NONE' : 'CLIENT' ; $ handshake_response [ "meta" ] = null ; if ( $ handshake_response [ 'match' ] != 'BOTH' ) { $ handshake_response [ "serverProtocol" ] = $ this -> local_protocol -> __toString ( ) ; $ handshake_response [ "serverHash" ] = $ this -> local_hash ; } else { $ handshake_response [ "serverProtocol" ] = null ; $ handshake_response [ "serverHash" ] = null ; } $ this -> handshake_responder_writer -> write ( $ handshake_response , $ encoder ) ; if ( $ handshake_response [ 'match' ] != 'NONE' ) $ transceiver -> set_remote ( $ remote_protocol ) ; return $ remote_protocol ; }
Processes an RPC handshake .
1,625
public static function fromRGB ( $ red , $ green , $ blue ) { if ( $ red < 0 || $ red > 255 || $ green < 0 || $ green > 255 || $ blue < 0 || $ blue > 255 ) { throw new InvalidArgumentException ( 'Values $red, $blue and $green can only be 0 to 255' ) ; } $ red /= 255 ; $ green /= 255 ; $ blue /= 255 ; $ min = min ( $ red , $ green , $ blue ) ; $ max = max ( $ red , $ green , $ blue ) ; $ delta = $ max - $ min ; $ hue = 0 ; $ saturation = 0 ; $ lightness = ( $ max + $ min ) / 2 ; if ( $ delta == 0 ) { return new self ( $ hue , $ saturation * 100 , $ lightness * 100 ) ; } else { $ saturation = $ delta / ( 1 - abs ( 2 * $ lightness - 1 ) ) ; $ hue = ( $ max == $ green ) ? 60 * ( ( $ blue - $ red ) / $ delta + 2 ) : $ hue ; $ hue = ( $ max == $ blue ) ? 60 * ( ( $ red - $ green ) / $ delta + 4 ) : $ hue ; if ( $ max == $ red ) { $ x = ( $ blue > $ green ) ? 360 : 0 ; $ hue = 60 * fmod ( ( ( $ green - $ blue ) / $ delta ) , 6 ) + $ x ; } return new self ( $ hue , $ saturation * 100 , $ lightness * 100 ) ; } }
Creates a Color instance based on the given RGB - formatted color .
1,626
public static function fromHEX ( $ hex ) { $ hex = preg_replace ( '/[^0-9A-Fa-f]/' , '' , $ hex ) ; $ rgb = [ ] ; if ( strlen ( $ hex ) == 6 ) { $ colorVal = hexdec ( $ hex ) ; $ rgb [ 'red' ] = 0xFF & ( $ colorVal >> 0x10 ) ; $ rgb [ 'green' ] = 0xFF & ( $ colorVal >> 0x8 ) ; $ rgb [ 'blue' ] = 0xFF & $ colorVal ; } elseif ( strlen ( $ hex ) == 3 ) { $ rgb [ 'red' ] = hexdec ( str_repeat ( substr ( $ hex , 0 , 1 ) , 2 ) ) ; $ rgb [ 'green' ] = hexdec ( str_repeat ( substr ( $ hex , 1 , 1 ) , 2 ) ) ; $ rgb [ 'blue' ] = hexdec ( str_repeat ( substr ( $ hex , 2 , 1 ) , 2 ) ) ; } else { throw new InvalidArgumentException ( 'Given color does not adhere to hexadecimal format' ) ; } return self :: fromRGB ( $ rgb [ 'red' ] , $ rgb [ 'green' ] , $ rgb [ 'blue' ] ) ; }
Creates a Color instance based on the given Hexadecimal - formatted color .
1,627
public static function fromHSV ( $ hue , $ saturation , $ value ) { if ( $ hue < 0 || $ hue > 360 || $ saturation < 0 || $ saturation > 100 || $ value < 0 || $ value > 100 ) { throw new InvalidArgumentException ( 'Value $hue can only be 0 to 360, $saturation and $value can only be 0 to 100' ) ; } $ hue /= 360 ; $ saturation /= 100 ; $ value /= 100 ; $ H = $ hue * 6 ; $ I = floor ( $ H ) ; $ F = $ H - $ I ; $ M = $ value * ( 1 - $ saturation ) ; $ N = $ value * ( 1 - $ saturation * $ F ) ; $ K = $ value * ( 1 - $ saturation * ( 1 - $ F ) ) ; switch ( $ I ) { case 0 : list ( $ red , $ green , $ blue ) = [ $ value , $ K , $ M ] ; break ; case 1 : list ( $ red , $ green , $ blue ) = [ $ N , $ value , $ M ] ; break ; case 2 : list ( $ red , $ green , $ blue ) = [ $ M , $ value , $ K ] ; break ; case 3 : list ( $ red , $ green , $ blue ) = [ $ M , $ N , $ value ] ; break ; case 4 : list ( $ red , $ green , $ blue ) = [ $ K , $ M , $ value ] ; break ; case 5 : case 6 : list ( $ red , $ green , $ blue ) = [ $ value , $ M , $ N ] ; break ; } $ red *= 255 ; $ green *= 255 ; $ blue *= 255 ; return self :: fromRGB ( $ red , $ green , $ blue ) ; }
Creates a Color instance based on the given HSV - formatted color .
1,628
public static function fromHSL ( $ hue , $ saturation , $ lightness ) { if ( $ hue < 0 || $ hue > 360 || $ saturation < 0 || $ saturation > 100 || $ lightness < 0 || $ lightness > 100 ) { throw new InvalidArgumentException ( 'Value $hue can only be 0 to 360, $saturation and $lightness can only be 0 to 100' ) ; } return new self ( $ hue , $ saturation , $ lightness ) ; }
Creates a Color instance based on the given HSL - formatted color .
1,629
public function lighten ( $ amount ) { if ( $ amount < 0 || $ amount > 100 ) { throw new InvalidArgumentException ( 'The given amount must be between 0 and 100' ) ; } $ amount /= 100 ; $ this -> lightness += ( 100 - $ this -> lightness ) * $ amount ; return $ this ; }
Alters the color by lightening it with the given percentage .
1,630
public function darken ( $ amount ) { if ( $ amount < 0 || $ amount > 100 ) { throw new InvalidArgumentException ( 'The given amount must be between 0 and 100' ) ; } $ amount /= 100 ; $ this -> lightness -= $ this -> lightness * $ amount ; return $ this ; }
Alters the color by darkening it with the given percentage .
1,631
public function saturate ( $ amount ) { if ( $ amount < 0 || $ amount > 100 ) { throw new InvalidArgumentException ( 'The given amount must be between 0 and 100' ) ; } $ amount /= 100 ; $ this -> saturation += ( 100 - $ this -> saturation ) * $ amount ; return $ this ; }
Alters the color by saturating it with the given percentage .
1,632
public function desaturate ( $ amount ) { if ( $ amount < 0 || $ amount > 100 ) { throw new InvalidArgumentException ( 'The given amount must be between 0 and 100' ) ; } $ amount /= 100 ; $ this -> saturation -= $ this -> saturation * $ amount ; return $ this ; }
Alters the color by desaturating it with the given percentage .
1,633
public function toHSL ( ) { return [ round ( $ this -> hue ) , round ( $ this -> saturation ) , round ( $ this -> lightness ) , ] ; }
Outputs the color using the HSL format .
1,634
public function toRGB ( ) { $ h = $ this -> hue ; $ s = $ this -> saturation / 100 ; $ l = $ this -> lightness / 100 ; $ r ; $ g ; $ b ; $ c = ( 1 - abs ( 2 * $ l - 1 ) ) * $ s ; $ x = $ c * ( 1 - abs ( fmod ( ( $ h / 60 ) , 2 ) - 1 ) ) ; $ m = $ l - ( $ c / 2 ) ; if ( $ h < 60 ) { list ( $ r , $ g , $ b ) = [ $ c , $ x , 0 ] ; } elseif ( $ h < 120 ) { list ( $ r , $ g , $ b ) = [ $ x , $ c , 0 ] ; } elseif ( $ h < 180 ) { list ( $ r , $ g , $ b ) = [ 0 , $ c , $ x ] ; } elseif ( $ h < 240 ) { list ( $ r , $ g , $ b ) = [ 0 , $ x , $ c ] ; } elseif ( $ h < 300 ) { list ( $ r , $ g , $ b ) = [ $ x , 0 , $ c ] ; } else { list ( $ r , $ g , $ b ) = [ $ c , 0 , $ x ] ; } $ r = ( $ r + $ m ) * 255 ; $ g = ( $ g + $ m ) * 255 ; $ b = ( $ b + $ m ) * 255 ; return [ round ( $ r ) , round ( $ g ) , round ( $ b ) , ] ; }
Outputs the color using the RGB format .
1,635
public function toHEX ( ) { list ( $ red , $ green , $ blue ) = $ this -> toRGB ( ) ; return strtoupper ( sprintf ( '#%02x%02x%02x' , $ red , $ green , $ blue ) ) ; }
Outputs the color using the HEX format .
1,636
public function toHSV ( ) { list ( $ red , $ green , $ blue ) = $ this -> toRGB ( ) ; $ red /= 255 ; $ green /= 255 ; $ blue /= 255 ; $ maxRGB = max ( $ red , $ green , $ blue ) ; $ minRGB = min ( $ red , $ green , $ blue ) ; $ chroma = $ maxRGB - $ minRGB ; $ value = 100 * $ maxRGB ; if ( $ chroma == 0 ) { return [ 0 , 0 , $ value ] ; } $ saturation = 100 * ( $ chroma / $ maxRGB ) ; if ( $ red == $ minRGB ) { $ h = 3 - ( ( $ green - $ blue ) / $ chroma ) ; } elseif ( $ blue == $ minRGB ) { $ h = 1 - ( ( $ red - $ green ) / $ chroma ) ; } else { $ h = 5 - ( ( $ blue - $ red ) / $ chroma ) ; } $ hue = 60 * $ h ; return [ round ( $ hue ) , round ( $ saturation ) , round ( $ value ) , ] ; }
Outputs the color using the HSV format .
1,637
public static function triplesToQuads ( array $ triples ) { $ quads = array ( ) ; foreach ( $ triples as $ t ) { $ quads [ ] = new Quad ( new IRI ( $ t [ 's' ] ) , new IRI ( $ t [ 'p' ] ) , ( $ t [ 'o_type' ] == 'uri' ) ? new IRI ( $ t [ 'o' ] ) : new TypedValue ( $ t [ 'o' ] , ( isset ( $ t [ 'o_datatype' ] ) && $ t [ 'o_datatype' ] != '' ) ? $ t [ 'o_datatype' ] : RdfConstants :: XSD_STRING ) ) ; } return $ quads ; }
Converts an array of ARC2 triples into an array of RDF quads in JsonLD library format .
1,638
public static function indexToQuads ( array $ index ) { $ quads = array ( ) ; foreach ( $ index as $ subject => $ predicates ) { foreach ( $ predicates as $ predicate => $ objects ) { foreach ( $ objects as $ object ) { $ quads [ ] = new Quad ( new IRI ( $ subject ) , new IRI ( $ predicate ) , ( $ object [ 'type' ] != 'literal' ) ? new IRI ( $ object [ 'value' ] ) : new TypedValue ( $ object [ 'value' ] , ( isset ( $ object [ 'datatype' ] ) && $ object [ 'datatype' ] != '' ) ? $ object [ 'datatype' ] : RdfConstants :: XSD_STRING ) ) ; } } } return $ quads ; }
Converts an ARC2 index into an array of RDF quads in JsonLD library format .
1,639
public static function quadsToTriples ( array $ quads ) { $ arcTriples = array ( ) ; foreach ( $ quads as $ q ) { $ arcTriples [ ] = array ( 's' => ( string ) $ q -> getSubject ( ) , 'p' => ( string ) $ q -> getProperty ( ) , 'o' => ( is_a ( $ q -> getObject ( ) , 'ML\JsonLD\TypedValue' ) ) ? $ q -> getObject ( ) -> getValue ( ) : ( string ) $ q -> getObject ( ) , 'o_type' => ( is_a ( $ q -> getObject ( ) , 'ML\JsonLD\TypedValue' ) ) ? 'literal' : ( ( $ q -> getObject ( ) -> getScheme ( ) == '_' ) ? 'bnode' : 'uri' ) ) ; } return $ arcTriples ; }
Converts an array of RDF quads in JsonLD library format into an array of ARC2 triples .
1,640
private function createCoreFunction ( Closure $ core ) : Closure { return function ( ServerRequestInterface $ request , ResponseInterface $ response , Route $ route ) use ( $ core ) { return call_user_func_array ( $ core , [ & $ request , & $ response , & $ route ] ) ; } ; }
Create the core function
1,641
public static function contains ( $ haystack , $ needle ) { if ( empty ( $ haystack ) || empty ( $ needle ) ) { return false ; } if ( ! is_array ( $ needle ) ) { return mb_strpos ( $ haystack , $ needle ) !== false ; } foreach ( ( array ) $ needle as $ str_needle ) { if ( ! empty ( $ str_needle ) && mb_strpos ( $ haystack , $ str_needle ) === false ) { return false ; } } return true ; }
Check if a given string contains a given substring .
1,642
public function add ( callable $ callback ) { $ reflection = new \ ReflectionFunction ( $ callback ) ; $ params = $ reflection -> getParameters ( ) ; if ( empty ( $ params ) ) { throw new \ InvalidArgumentException ( "Invalid exception callback: Has no arguments. Expected at least one." ) ; } $ class = $ params [ 0 ] -> getClass ( ) ; if ( $ class === null ) { throw new \ InvalidArgumentException ( "Invalid exception callback: The first argument must have a class type hint." ) ; } $ this -> callbacks [ $ class -> name ] = $ callback ; }
Adds an exception callback .
1,643
public function offsetExists ( $ key ) { return isset ( $ this -> data [ $ key ] ) || array_key_exists ( $ key , $ this -> data ) ; }
Determines whether a item exists .
1,644
public function getByPrimary ( $ value ) { foreach ( $ this -> data as $ entity ) { $ primaryPropertyName = $ entity :: getReflection ( ) -> getPrimaryProperty ( ) -> getName ( ) ; $ primaryValue = $ entity -> { $ primaryPropertyName } ; if ( $ primaryValue === $ value && $ primaryValue !== null ) { return $ entity ; } } return false ; }
Get entity by primary value
1,645
public function reset ( $ items = null ) { $ this -> items = [ ] ; if ( ( func_get_args ( ) > 0 ) && is_array ( $ items ) ) { $ this -> items = $ items ; } return $ this ; }
Resets the collection with the specified array content .
1,646
public function pull ( $ key ) { if ( $ this -> has ( $ key ) ) { $ pulled = $ this -> get ( $ key ) ; $ this -> remove ( $ key ) ; return $ pulled ; } return false ; }
Pull an item from the collection and remove it from the collection .
1,647
public function register ( ) { $ this -> app -> singleton ( 'fielder' , function ( $ app ) { $ fielder = new Fielder ( $ app ) ; $ fielder -> register ( $ this -> fields ) ; return $ fielder ; } ) ; $ this -> app -> alias ( 'fielder' , Fielder :: class ) ; }
Register fielder services .
1,648
public function dispatchAssets ( ) { $ this -> app [ 'asset.factory' ] -> add ( 'fielder-vendors' , [ 'path' => FIELDER_URI . 'public/js/vendors.js' , ] ) -> area ( 'admin' ) ; $ this -> app [ 'asset.factory' ] -> add ( 'fielder' , [ 'path' => FIELDER_URI . 'public/js/fielder.js' , 'dependences' => [ 'fielder-vendors' ] , ] ) -> area ( 'admin' ) ; $ this -> app [ 'asset.factory' ] -> add ( 'fielder-style' , [ 'path' => FIELDER_URI . 'public/css/fielder.css' , ] ) -> area ( 'admin' ) ; }
Dispatch fielder assets .
1,649
public function indexAction ( ) { $ service = $ this -> getLayoutService ( ) ; try { $ theme = $ service -> getTheme ( $ this -> params ( ) -> fromRoute ( 'theme' ) ) ; } catch ( RuntimeException $ e ) { $ this -> flashMessenger ( ) -> addMessage ( $ e -> getMessage ( ) ) ; return $ this -> redirect ( ) -> toRoute ( 'sc-admin/layout' ) -> setStatusCode ( 303 ) ; } $ event = $ this -> getRequest ( ) -> getPost ( 'suboperation' ) ; if ( ! empty ( $ event ) ) { $ events = $ this -> getEventManager ( ) ; $ params = $ this -> request -> getPost ( ) ; $ params [ 'theme' ] = $ theme -> getName ( ) ; $ results = $ events -> trigger ( $ event , $ this , $ params ) ; foreach ( $ results as $ result ) { if ( $ result instanceof Response ) { return $ result ; } } } $ view = new ViewModel ( [ 'controlSet' => $ service -> getControlSet ( ) , 'regions' => $ service -> getRegions ( $ theme -> getName ( ) ) , 'theme' => $ theme , ] ) ; $ flashMessenger = $ this -> flashMessenger ( ) ; if ( $ flashMessenger -> hasMessages ( ) ) { $ view -> messages = $ flashMessenger -> getMessages ( ) ; } return $ view ; }
Shows a layout .
1,650
private function importLine ( ) { $ import = false ; $ from = false ; while ( ! $ this -> eol ( ) ) { $ c = $ this -> peek ( ) ; $ tok = null ; $ m = null ; if ( $ c === '\\' ) { $ m = $ this -> get ( 2 ) ; } elseif ( $ this -> scan ( '/[,\\.;\\*]+/' ) ) { $ tok = 'OPERATOR' ; } elseif ( $ this -> scan ( "/[ \t]+/" ) ) { } elseif ( ( $ m = $ this -> scan ( '/import\\b|from\\b/' ) ) ) { if ( $ m === 'import' ) { $ import = true ; } elseif ( $ m === 'from' ) { $ from = true ; } else { assert ( 0 ) ; } $ tok = 'IDENT' ; } elseif ( $ this -> scan ( '/[_a-zA-Z]\w*/' ) ) { assert ( $ from || $ import ) ; if ( $ import ) { $ tok = 'USER_FUNCTION' ; $ this -> userDefs [ $ this -> match ( ) ] = 'TYPE' ; } else { $ tok = 'IDENT' ; } } else { break ; } $ this -> record ( ( $ m !== null ) ? $ m : $ this -> match ( ) , $ tok ) ; } }
mini - scanner to handle highlighting module names in import lines
1,651
public function check_markup ( $ text , $ format_id = null , $ langcode = '' , $ cache = FALSE ) { return check_markup ( $ text , $ format_id , $ langcode , $ cache ) ; }
Run all the enabled filters on a piece of text .
1,652
public function filter_dom_serialize_escape_cdata_element ( $ dom_document , $ dom_element , $ comment_start = '//' , $ comment_end = '' ) { return filter_dom_serialize_escape_cdata_element ( $ dom_document , $ dom_element , $ comment_start , $ comment_end ) ; }
Adds comments around the <!CDATA section in a dom element .
1,653
public static function dataTypeToEavColumn ( $ type ) { switch ( $ type ) { case Property :: DATA_TYPE_FLOAT : return 'value_float' ; break ; case Property :: DATA_TYPE_BOOLEAN : case Property :: DATA_TYPE_INTEGER : return 'value_integer' ; break ; case Property :: DATA_TYPE_TEXT : case Property :: DATA_TYPE_PACKED_JSON : case Property :: DATA_TYPE_INVARIANT_STRING : return 'value_text' ; break ; case Property :: DATA_TYPE_STRING : default : return 'value_string' ; break ; } }
Returns EAV column by property data type .
1,654
public function getInfo ( $ info_name ) { $ value = null ; if ( $ info_name == 'provider' ) $ value = $ this -> provider ; else if ( property_exists ( $ this -> profile , $ info_name ) ) $ value = $ this -> profile -> $ info_name ; return $ value ; }
Query the info for a specific value
1,655
public function success ( UserInterface $ user ) { $ repository = App :: make ( 'Ipunkt\SocialAuth\Repositories\SocialLoginRepository' ) ; $ login = $ repository -> create ( ) ; $ login -> setIdentifier ( $ this -> identifier ) ; $ login -> setProvider ( $ this -> provider ) ; $ login -> setUser ( $ user -> getAuthIdentifier ( ) ) ; $ success = $ repository -> save ( $ login ) ; if ( $ success ) Event :: fire ( 'social-auth.register' , [ 'user' => $ user , 'registerInfo' => $ this ] ) ; return $ success ; }
Notify the provider of the RegisterInfo that the user was now successfuly registered .
1,656
public function process ( EventInterface $ event ) { $ events = $ this -> getEventManager ( ) ; $ mapper = $ this -> getMapper ( ) ; $ optionsProvider = $ this -> getOptionsProvider ( ) ; $ translator = $ this -> getTranslator ( ) ; $ pane = $ event -> getParam ( 'pane' ) ; if ( ! $ optionsProvider -> hasIdentifier ( $ pane ) ) { return ; } $ ids = $ event -> getParam ( 'id' ) ; if ( empty ( $ ids ) ) { return ; } $ options = $ optionsProvider -> getOptions ( $ pane ) ; if ( $ options -> getRoot ( ) == 'site' ) { $ this -> error ( self :: DeleteFromSite ) ; return $ this -> redirect ( $ event ) ; } foreach ( $ ids as $ id ) { try { $ mapper -> beginTransaction ( ) ; $ tid = $ mapper -> getTransactionIdentifier ( ) ; $ events -> trigger ( __FUNCTION__ . '.delete.pre' , null , [ 'content' => $ id , 'tid' => $ tid , ] ) ; $ mapper -> delete ( $ id , $ tid ) ; $ mapper -> commit ( ) ; } catch ( UnavailableSourceException $ e ) { $ mapper -> rollBack ( ) ; $ this -> setValue ( $ id ) -> error ( self :: SourceNotFound ) ; } catch ( Exception $ e ) { if ( DEBUG_MODE ) { throw new DebugException ( $ translator -> translate ( 'Error: ' ) . $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } $ meta = $ mapper -> findMetaById ( $ id ) ; $ name = isset ( $ meta [ 'title' ] ) ? $ meta [ 'title' ] : $ id ; $ this -> setValue ( $ name ) -> error ( self :: UnexpectedError ) ; } } return $ this -> redirect ( $ event , 'sc-admin/file/delete' ) ; }
To permanently delete elements from the trash
1,657
public function addQueue ( $ queue ) { if ( ! in_array ( $ queue , $ this -> queuesWorkedOn ) ) { $ this -> queuesWorkedOn [ ] = $ queue ; } return $ this ; }
add a worked queue
1,658
public function get ( $ path , $ params = array ( ) , $ vars = array ( ) ) { $ request = $ this -> request ( ) ; $ request = $ this -> prepareRequest ( $ request ) ; $ response = $ request -> get ( $ this -> endpoint . $ path , $ params , $ vars ) ; return $ this -> handleResponse ( $ response ) ; }
Perform a GET request to the API .
1,659
public function post ( $ path , $ vars = array ( ) ) { $ request = $ this -> request ( ) ; $ request = $ this -> prepareRequest ( $ request ) ; $ response = $ request -> post ( $ this -> endpoint . $ path , $ vars ) ; return $ this -> handleResponse ( $ response ) ; }
Perform a POST request to the API .
1,660
public function delete ( $ path , $ params = array ( ) ) { $ request = $ this -> request ( ) ; $ request = $ this -> prepareRequest ( $ request ) ; $ response = $ request -> delete ( $ this -> endpoint . $ path , $ params ) ; return $ this -> handleResponse ( $ response ) ; }
Perform a DELETE request to the API .
1,661
protected function prepareRequest ( $ request ) { $ request -> header ( 'X-M2X-KEY' , $ this -> apiKey ) ; $ request -> header ( 'User-Agent' , $ this -> userAgent ) ; return $ request ; }
Sets the common headers for each request to the API .
1,662
protected function handleResponse ( HttpResponse $ response ) { $ this -> lastResponse = $ response ; if ( $ response -> success ( ) ) { return $ response ; } throw new M2XException ( $ response ) ; }
Checks the HttpResponse for errors and throws an exception if no errors are encountered the HttpResponse is returned .
1,663
public function sqlSearch ( $ params ) { $ this -> load ( $ params ) ; $ where = [ 'id' => sprintf ( 'id = "%s"' , $ this -> id ) , 'status' => sprintf ( 'status = "%s"' , $ this -> status ) , 'created_at' => sprintf ( 'created_at = "%s"' , $ this -> created_at ) , 'updated_at' => sprintf ( 'updated_at = "%s"' , $ this -> updated_at ) , 'username' => sprintf ( 'username like "%s%%"' , $ this -> username ) , 'auth_key' => sprintf ( 'auth_key like "%s%%"' , $ this -> auth_key ) , 'password_hash' => sprintf ( 'password_hash like "%s%%"' , $ this -> password_hash ) , 'password_reset_token' => sprintf ( 'password_reset_token like "%s%%"' , $ this -> password_reset_token ) , 'email' => sprintf ( 'email like "%s%%"' , $ this -> email ) , ] ; $ filtedParams = array_filter ( $ this -> attributes , function ( $ val ) { return $ val != '' ; } ) ; $ FiltedWhere = [ '1=1' ] ; foreach ( $ filtedParams as $ key => $ value ) { $ FiltedWhere [ ] = $ where [ $ key ] ; } $ querySql = sprintf ( ' SELECT %s FROM %s WHERE %s ' , '*' , $ this -> tableName ( ) , implode ( ' AND ' , $ FiltedWhere ) ) ; $ countSql = sprintf ( ' SELECT %s FROM %s WHERE %s ' , 'count(1)' , $ this -> tableName ( ) , implode ( ' AND ' , $ FiltedWhere ) ) ; $ sqlDataProvider = new SqlDataProvider ( [ 'sql' => $ querySql , 'totalCount' => Yii :: $ app -> db -> createCommand ( $ countSql ) -> queryScalar ( ) , 'key' => 'id' , 'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC ] , 'attributes' => array_keys ( $ this -> attributes ) , ] , 'pagination' => [ 'pageSize' => 10 , ] , ] ) ; return $ sqlDataProvider ; }
Creates data provider instance with search query and sql applied
1,664
public static function set ( $ error , $ key = null ) { if ( $ key ) { static :: $ error [ $ key ] [ ] = $ error ; } else { static :: $ error [ ] = $ error ; } }
Set specific error .
1,665
public function db_add_field ( $ table , $ field , $ spec , $ keys_new = array ( ) ) { db_add_field ( $ table , $ field , $ spec , $ keys_new ) ; }
Adds a new field to a table .
1,666
public function db_query_range ( $ query , $ from , $ count , array $ args = array ( ) , array $ options = array ( ) ) { return db_query_range ( $ query , $ from , $ count , $ args , $ options ) ; }
Executes a query against the active database restricted to a range .
1,667
protected function localizeCollection ( array $ prefixes , RouteCollection $ collection ) { $ removeRoutes = array ( ) ; $ newRoutes = new RouteCollection ( ) ; foreach ( $ collection -> all ( ) as $ name => $ route ) { $ routeLocale = $ route -> getDefault ( self :: LOCALE_PARAM ) ; if ( $ routeLocale !== null ) { if ( ! isset ( $ prefixes [ $ routeLocale ] ) ) { throw new MissingRouteLocaleException ( sprintf ( 'Route `%s`: No prefix found for locale "%s".' , $ name , $ routeLocale ) ) ; } $ route -> setPath ( '/' . $ prefixes [ $ routeLocale ] . $ route -> getPath ( ) ) ; continue ; } $ removeRoutes [ ] = $ name ; foreach ( $ prefixes as $ locale => $ prefix ) { $ localeRoute = clone $ route ; $ localeRoute -> setPath ( '/' . $ prefix . $ route -> getPath ( ) ) ; $ localeRoute -> setDefault ( self :: LOCALE_PARAM , $ locale ) ; $ newRoutes -> add ( $ this -> routeNameInflector -> inflect ( $ name , $ locale ) , $ localeRoute ) ; } } $ collection -> remove ( $ removeRoutes ) ; $ collection -> addCollection ( $ newRoutes ) ; }
Localize a route collection .
1,668
protected function localizeCollectionLocaleParameter ( $ prefix , RouteCollection $ collection ) { $ localizedPrefixes = array ( ) ; foreach ( $ collection -> all ( ) as $ name => $ route ) { $ locale = $ route -> getDefault ( self :: LOCALE_PARAM ) ; if ( $ locale === null ) { $ routePrefix = $ prefix ; } else { if ( ! isset ( $ localizedPrefixes [ $ locale ] ) ) { $ localizedPrefixes [ $ locale ] = preg_replace ( static :: LOCALE_REGEX , $ locale , $ prefix ) ; } $ routePrefix = $ localizedPrefixes [ $ locale ] ; } $ route -> setPath ( '/' . $ routePrefix . $ route -> getPath ( ) ) ; } }
Localize the prefix _locale of all routes .
1,669
public function actionFillIndex ( ) { try { $ this -> client -> ping ( ) ; } catch ( NoNodesAvailableException $ e ) { $ this -> stderr ( $ e -> getMessage ( ) . ', maybe you first need to configure and run elasticsearch' . PHP_EOL ) ; return ; } foreach ( $ this -> applicables as $ indexName => $ model ) { if ( true === $ this -> client -> indices ( ) -> exists ( [ 'index' => $ indexName ] ) ) { $ this -> client -> indices ( ) -> delete ( [ 'index' => $ indexName ] ) ; } $ config = self :: prepareIndexConfig ( ) ; $ config [ 'index' ] = $ indexName ; $ response = $ this -> client -> indices ( ) -> create ( $ config ) ; if ( true === isset ( $ response [ 'acknowledged' ] ) && $ response [ 'acknowledged' ] == 1 ) { foreach ( self :: $ storage as $ className => $ id ) { $ indexData = self :: prepareIndexData ( $ model , $ indexName , $ className , $ id ) ; if ( false === empty ( $ indexData [ 'body' ] ) ) { $ this -> client -> bulk ( $ indexData ) ; } } } } }
Creates and fills in indices
1,670
private static function prepareIndexConfig ( ) { foreach ( self :: $ storage as $ className => $ id ) { $ key = IndexHelper :: storageClassToType ( $ className ) ; $ config = self :: prepareMapping ( $ className ) ; if ( false === empty ( $ config ) ) { self :: $ indexConfig [ 'body' ] [ 'mappings' ] [ $ key ] = $ config ; } } return self :: $ indexConfig ; }
Prepares config for all applicable property storage
1,671
private static function prepareMapping ( $ className ) { $ mapping = [ ] ; foreach ( self :: $ languages as $ iso_639_2t ) { if ( true === isset ( self :: $ langToAnalyzer [ $ iso_639_2t ] ) ) { switch ( $ className ) { case StaticValues :: class : self :: $ staticMapping [ 'properties' ] [ Search :: STATIC_VALUES_FILED ] [ 'properties' ] [ 'slug_' . $ iso_639_2t ] = self :: $ slugMap ; self :: $ staticValueMap [ 'analyzer' ] = self :: $ langToAnalyzer [ $ iso_639_2t ] ; self :: $ staticMapping [ 'properties' ] [ Search :: STATIC_VALUES_FILED ] [ 'properties' ] [ 'value_' . $ iso_639_2t ] = self :: $ staticValueMap ; $ mapping = self :: $ staticMapping ; break ; case EAV :: class : self :: $ eavValueMap [ 'analyzer' ] = self :: $ langToAnalyzer [ $ iso_639_2t ] ; self :: $ eavMapping [ 'properties' ] [ Search :: EAV_FIELD ] [ 'properties' ] [ 'str_value_' . $ iso_639_2t ] = self :: $ staticValueMap ; self :: $ eavMapping [ 'properties' ] [ Search :: EAV_FIELD ] [ 'properties' ] [ 'txt_value_' . $ iso_639_2t ] = self :: $ staticValueMap ; $ mapping = self :: $ eavMapping ; break ; } } } return $ mapping ; }
Prepares language based index mappings according to languages defined in app config multilingual
1,672
public static function getBonusByRole ( string $ role ) : float { switch ( $ role ) { case Row :: GOALKEEPER : return GoalsNormalizer :: STANDARD_GOALKEEPER_MALUS ; case Row :: DEFENDER : return GoalsNormalizer :: FORMAT_2017_DEFENDER_GOAL_BONUS ; case Row :: MIDFIELDER : return GoalsNormalizer :: FORMAT_2017_MIDFIELDER_GOAL_BONUS ; case Row :: PLAYMAKER : return GoalsNormalizer :: FORMAT_2017_PLAYMAKER_GOAL_BONUS ; case Row :: FORWARD : default : return GoalsNormalizer :: FORMAT_2017_FORWARD_GOAL_BONUS ; } }
Returns the goal bonus given the role
1,673
public function execute ( ) { try { $ this -> filesystem -> mirror ( $ this -> demoDataPath , $ this -> outPath ) ; } catch ( IOException $ exception ) { $ items = [ "Error occurred while copying files:" , $ exception -> getMessage ( ) , "\n" ] ; $ message = implode ( " " , $ items ) ; echo $ message ; return 1 ; } return 0 ; }
Copies DemoData images from vendor directory of needed edition to the OXID eShop OUT directory .
1,674
public function format ( $ data , $ multiple = false ) { if ( $ multiple === true || $ data instanceof Collection ) { foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this -> runFormatters ( $ value ) ; } } else { $ data = $ this -> runFormatters ( $ data ) ; } return $ data ; }
Format the given data .
1,675
protected function runFormatters ( $ data ) { $ data = self :: formatAble ( $ data ) ; foreach ( $ this -> formatters as $ formatter ) { $ data = $ formatter -> format ( $ data ) ; } return $ data -> getObject ( ) ; }
Run the Formatters on the given data .
1,676
public function publishedPostsAction ( ) { $ this -> routeParam ( ) -> mapPageTo ( $ this -> queryService ) ; if ( $ tag = $ this -> params ( ) -> fromRoute ( 'tag' ) ) { $ collection = $ this -> queryService -> findPublishedPostsByTag ( $ tag ) ; } else { $ collection = $ this -> queryService -> findPublishedPosts ( ) ; } return $ this -> viewModelFactory ( ) -> createFor ( $ collection ) ; }
Published post entries retrieval
1,677
public function publishedPostAction ( ) { $ encryptedId = $ this -> params ( ) -> fromRoute ( 'id' ) ; if ( $ decryptedId = $ this -> cryptEngine -> decrypt ( $ encryptedId ) ) { $ post = $ this -> queryService -> findPublishedPostById ( $ decryptedId ) ; } if ( ! isset ( $ post ) ) { return $ this -> nullResponse ( ) ; } $ viewHelperManager = $ this -> getServiceLocator ( ) -> get ( 'ViewHelperManager' ) ; $ slugifier = $ viewHelperManager -> get ( 'slugify' ) ; $ permaLink = $ viewHelperManager -> get ( 'permaLinkPost' ) ; if ( $ slugifier ( $ post -> getTitle ( ) ) !== $ this -> params ( ) -> fromRoute ( 'title' ) ) { return $ this -> redirect ( ) -> toUrl ( $ permaLink ( $ post ) ) ; } return $ this -> viewModelFactory ( ) -> create ( array ( 'post' => $ post ) ) ; }
Published post entry retrieval
1,678
function buildPayload ( & $ payload ) { if ( is_array ( $ payload ) ) { $ payload = $ this -> array_map_deep ( $ payload , array ( $ this , 'buildPayloadItemInfo' ) ) ; } else { $ payload = $ this -> makePayloadBuilder ( $ payload ) ; $ this -> buildPayload ( $ payload ) ; } return $ payload ; }
Parse the payload to check for PayloadBuilder objects and make them .
1,679
function buildPayloadItemInfo ( $ key , $ item ) { if ( is_object ( $ item ) ) { $ key = ( $ this -> getPayloadBuilderKey ( $ item ) ) ? $ this -> getPayloadBuilderKey ( $ item ) : $ key ; $ item = $ this -> makePayloadBuilder ( $ item ) ; } return array ( 'key' => $ key , 'item' => $ item ) ; }
The array_map_deep callback for buildPayload . If the array part is an object it attempts to make payloadBuilder .
1,680
function makeQuery ( ) { $ query = array ( ) ; foreach ( $ this -> query as $ paramater ) { $ operator = ( $ paramater [ 1 ] != '=' ) ? $ paramater [ 1 ] : '' ; $ query [ $ paramater [ 0 ] . $ operator ] = $ paramater [ 2 ] ; } return $ query ; }
Return an array ready to be http encoded .
1,681
function makeResource ( ) { $ resource = $ this -> resource ; if ( $ this -> id ) $ resource .= '/' . $ this -> id ; return $ resource ; }
Return the resource url part .
1,682
public function record ( $ str , $ dummy1 = null , $ dummy2 = null ) { if ( $ dummy1 !== null || $ dummy2 !== null ) { throw new Exception ( 'Luminous\\Core\\Scanners\\StatefulScanner::record does not currently observe its second and third ' . 'parameters' ) ; } $ c = & $ this -> tokenTreeStack [ count ( $ this -> tokenTreeStack ) - 1 ] [ 'children' ] ; $ c [ ] = $ str ; }
Records a string as a child of the currently active token
1,683
public function main ( ) { $ this -> setup ( ) ; while ( ! $ this -> eos ( ) ) { $ p = $ this -> pos ( ) ; $ state = $ this -> stateName ( ) ; $ this -> loadTransitions ( ) ; list ( $ nextPatternData , $ nextPatternIndex , $ nextPatternMatches ) = $ this -> nextStartData ( ) ; list ( $ endIndex , $ endMatches ) = $ this -> nextEndData ( ) ; if ( ( $ nextPatternIndex <= $ endIndex || $ endIndex === - 1 ) && $ nextPatternIndex !== - 1 ) { if ( $ p < $ nextPatternIndex ) { $ this -> recordRange ( $ p , $ nextPatternIndex ) ; } $ newPos = $ nextPatternIndex ; $ this -> pos ( $ newPos ) ; $ tok = $ nextPatternData [ 0 ] ; if ( isset ( $ this -> overrides [ $ tok ] ) ) { $ ret = call_user_func ( $ this -> overrides [ $ tok ] , $ nextPatternMatches ) ; if ( $ ret === true ) { break ; } if ( $ this -> stateName ( ) === $ state && $ this -> pos ( ) <= $ newPos ) { throw new Exception ( 'Override failed to either advance the pointer or change the state' ) ; } } else { $ this -> posShift ( strlen ( $ nextPatternMatches [ 0 ] ) ) ; $ this -> pushState ( $ nextPatternData ) ; $ this -> record ( $ nextPatternMatches [ 0 ] ) ; if ( $ nextPatternData [ 2 ] === null ) { $ this -> popState ( ) ; } } } elseif ( $ endIndex !== - 1 ) { $ to = $ endIndex + strlen ( $ endMatches [ 0 ] ) ; $ this -> recordRange ( $ this -> pos ( ) , $ to ) ; $ this -> pos ( $ to ) ; $ this -> popState ( ) ; } else { $ this -> record ( $ this -> rest ( ) ) ; $ this -> terminate ( ) ; break ; } if ( $ this -> stateName ( ) === $ state && $ this -> pos ( ) <= $ p ) { throw new Exception ( 'Failed to advance pointer in state' . $ this -> stateName ( ) ) ; } } assert ( count ( $ this -> tokenTreeStack ) >= 1 ) ; while ( count ( $ this -> tokenTreeStack ) > 1 ) { $ this -> popState ( ) ; } return $ this -> tokenTreeStack [ 0 ] ; }
Generic main function which observes the transition table
1,684
protected function collapseTokenTree ( $ node ) { $ text = '' ; foreach ( $ node [ 'children' ] as $ c ) { if ( is_string ( $ c ) ) { $ text .= Utils :: escapeString ( $ c ) ; } else { $ text .= $ this -> collapseTokenTree ( $ c ) ; } } $ tokenName = $ node [ 'token_name' ] ; $ token = array ( $ node [ 'token_name' ] , $ text , true ) ; $ token_ = $ this -> ruleMapperFilter ( array ( $ token ) ) ; $ token = $ token_ [ 0 ] ; if ( isset ( $ this -> filters [ $ tokenName ] ) ) { foreach ( $ this -> filters [ $ tokenName ] as $ filter ) { $ token = call_user_func ( $ filter [ 1 ] , $ token ) ; } } list ( $ tokenName , $ text , ) = $ token ; return ( $ tokenName === null ) ? $ text : Utils :: tagBlock ( $ tokenName , $ text ) ; }
Recursive function to collapse the token tree into XML
1,685
public function createNewToken ( $ value , $ expire = 300 ) { $ this -> token = [ 'value' => sha1 ( rand ( 10000 , getrandmax ( ) ) . $ value ) , 'expire' => ( int ) $ expire , 'start' => time ( ) ] ; $ _SESSION [ 'pop_csrf' ] = serialize ( $ this -> token ) ; return $ this ; }
Set the token of the csrf form element
1,686
protected function assignMedia ( ) { if ( \ Sifo \ Domains :: getInstance ( ) -> getDevMode ( ) ) { $ packer = new \ Sifo \ JsPacker ( ) ; $ packer -> packMedia ( ) ; $ packer = new \ Sifo \ CssPacker ( ) ; $ packer -> packMedia ( ) ; } $ this -> assign ( 'media' , \ Sifo \ Config :: getInstance ( ) -> getConfig ( 'css' ) ) ; $ this -> assign ( 'css_groups' , $ this -> css_groups ) ; $ this -> assign ( 'js_groups' , $ this -> js_groups ) ; $ this -> assign ( 'static_rev' , $ this -> getStaticRevision ( ) ) ; $ this -> assign ( 'media_module' , $ this -> fetch ( 'shared/media_packer.tpl' ) ) ; }
Assign a variable to the tpl with the HTML code to load the JS and CSS files .
1,687
public function beforeDelete ( ) { if ( parent :: beforeDelete ( ) === false ) { return false ; } $ storage = PropertyStorageHelper :: storageById ( $ this -> storage_id ) ; return $ storage -> beforePropertyDelete ( $ this ) ; }
Perform beforeDelete events
1,688
public function beforeValidate ( ) { $ validation = parent :: beforeValidate ( ) ; return $ validation && PropertyStorageHelper :: storageById ( $ this -> storage_id ) -> beforePropertyValidate ( $ this ) ; }
Perform beforeValidate events
1,689
public static function castValueToDataType ( $ value , $ type ) { switch ( $ type ) { case Property :: DATA_TYPE_FLOAT : return empty ( $ value ) ? null : ( float ) $ value ; break ; case Property :: DATA_TYPE_BOOLEAN : return empty ( $ value ) ? null : ( bool ) $ value ; break ; case Property :: DATA_TYPE_INTEGER : return empty ( $ value ) ? null : ( int ) $ value ; break ; default : return $ value ; break ; } }
Casts value to data type
1,690
public static function validationCastFunction ( $ type ) { switch ( $ type ) { case Property :: DATA_TYPE_FLOAT : return 'floatval' ; break ; case Property :: DATA_TYPE_BOOLEAN : return 'boolval' ; break ; case Property :: DATA_TYPE_INTEGER : return 'intval' ; break ; case Property :: DATA_TYPE_STRING : case Property :: DATA_TYPE_TEXT : case self :: DATA_TYPE_INVARIANT_STRING : return 'strval' ; break ; default : return null ; } }
Returns name of function for filtering data casting
1,691
public static function findById ( $ id , $ throwException = true ) { $ e = $ throwException ? new ServerErrorHttpException ( "Property with id $id not found" ) : false ; return static :: loadModel ( $ id , false , true , 86400 , $ e , true ) ; }
A proxy method for LoadModel
1,692
public function isRequired ( ) { $ params = $ this -> params ; $ required = boolval ( ArrayHelper :: getValue ( $ params , Property :: PACKED_ADDITIONAL_RULES . '.required' , false ) ) ; return $ required ; }
check if property required
1,693
public function getTimezoneByIP ( $ ipAddress = '' ) { $ ipAddress = ( empty ( $ ipAddress ) ? $ this -> request -> server -> get ( 'REMOTE_ADDR' ) : $ ipAddress ) ; $ countryCode = $ this -> getCountryCode2ByIP ( $ ipAddress ) ; if ( ! function_exists ( 'geoip_time_zone_by_country_and_region' ) ) { throw new Exception ( 'geoip_time_zone_by_country_and_region() function is not available.' ) ; } return geoip_time_zone_by_country_and_region ( $ countryCode ) ; }
Get the corresponding timezone according to ip address .
1,694
public function getCountryCode2ByIP ( $ ipAddress = '' ) { $ ipAddress = ( empty ( $ ipAddress ) ? $ this -> request -> server -> get ( 'REMOTE_ADDR' ) : $ ipAddress ) ; if ( ! function_exists ( 'geoip_country_code_by_name' ) ) { throw new Exception ( 'geoip_country_code_by_name() function is not available.' ) ; } return geoip_country_code_by_name ( $ ipAddress ) ; }
Get the country ISO2A code by ip .
1,695
public function getCountryCode3ByIP ( $ ipAddress = '' ) { $ ipAddress = ( empty ( $ ipAddress ) ? $ this -> request -> server -> get ( 'REMOTE_ADDR' ) : $ ipAddress ) ; if ( ! function_exists ( 'geoip_country_code3_by_name' ) ) { throw new Exception ( 'geoip_country_code3_by_name() function is not available.' ) ; } return geoip_country_code3_by_name ( $ ipAddress ) ; }
Get the country ISO3A code by ip .
1,696
public function render ( $ depth = 0 , $ indent = null , $ inner = false ) { if ( ! $ this -> renderValue ) { $ this -> setAttribute ( 'value' , '' ) ; } return parent :: render ( $ depth , $ indent , $ inner ) ; }
Render the password element
1,697
protected function getAvailablePageWrapper ( $ url , $ page , $ rel = null ) { return sprintf ( $ this -> availablePageWrapper , $ url , $ page ) ; }
Get html tag for an available link .
1,698
protected function getPreviousButton ( ) { if ( $ this -> paginator -> currentPage ( ) <= 1 ) { return $ this -> getDisabledLink ( $ this -> previousButtonText ) ; } $ url = $ this -> paginator -> url ( $ this -> paginator -> currentPage ( ) - 1 ) ; return $ this -> getPrevNextPageLinkWrapper ( $ url , $ this -> previousButtonText , 'prev' ) ; }
Get html tag the previous page link .
1,699
protected function getNextButton ( ) { if ( ! $ this -> paginator -> hasMorePages ( ) ) { return $ this -> getDisabledLink ( $ this -> nextButtonText ) ; } $ url = $ this -> paginator -> url ( $ this -> paginator -> currentPage ( ) + 1 ) ; return $ this -> getPrevNextPageLinkWrapper ( $ url , $ this -> nextButtonText , 'next' ) ; }
Get html tag for the next page link .