idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
41,500 | protected function numberOfDays ( $ days , $ start , $ end ) { $ w = array ( date ( 'w' , $ start ) , date ( 'w' , $ end ) ) ; $ base = floor ( ( $ end - $ start ) / self :: SECONDS_IN_A_WEEK ) ; $ sum = 0 ; for ( $ day = 0 ; $ day < 7 ; ++ $ day ) { if ( $ days & pow ( 2 , $ day ) ) { $ sum += $ base + ( ( $ w [ 0 ] > $ w [ 1 ] ) ? $ w [ 0 ] <= $ day || $ day <= $ w [ 1 ] : $ w [ 0 ] <= $ day && $ day <= $ w [ 1 ] ) ; } } return $ sum ; } | Gets the number of days between a start and end date |
41,501 | protected function convertDayOrdinalToPositive ( $ dayNumber , $ weekday , $ timestamp ) { $ dayNumber = empty ( $ dayNumber ) ? 1 : $ dayNumber ; $ dayOrdinals = $ this -> dayOrdinals ; if ( $ dayNumber >= 1 ) { return $ dayOrdinals [ $ dayNumber ] ; } $ timestamp = ( is_object ( $ timestamp ) ) ? $ timestamp : \ DateTime :: createFromFormat ( self :: UNIX_FORMAT , $ timestamp ) ; $ start = strtotime ( 'first day of ' . $ timestamp -> format ( self :: DATE_TIME_FORMAT_PRETTY ) ) ; $ end = strtotime ( 'last day of ' . $ timestamp -> format ( self :: DATE_TIME_FORMAT_PRETTY ) ) ; $ weekdays = array_flip ( array_keys ( $ this -> weekdays ) ) ; $ numberOfDays = $ this -> numberOfDays ( pow ( 2 , $ weekdays [ $ weekday ] ) , $ start , $ end ) ; $ dayOrdinals = array_slice ( $ dayOrdinals , 0 , $ numberOfDays , true ) ; $ dayOrdinals = array_combine ( array_keys ( $ dayOrdinals ) , array_reverse ( array_values ( $ dayOrdinals ) ) ) ; return $ dayOrdinals [ $ dayNumber * - 1 ] ; } | Converts a negative day ordinal to its equivalent positive form |
41,502 | protected static function mb_str_replace ( $ search , $ replace , $ subject , $ encoding = null , & $ count = 0 ) { if ( is_array ( $ subject ) ) { foreach ( $ subject as $ key => $ value ) { $ subject [ $ key ] = self :: mb_str_replace ( $ search , $ replace , $ value , $ encoding , $ count ) ; } } else { $ searches = is_array ( $ search ) ? array_values ( $ search ) : [ $ search ] ; $ replacements = is_array ( $ replace ) ? array_values ( $ replace ) : [ $ replace ] ; $ replacements = array_pad ( $ replacements , count ( $ searches ) , '' ) ; foreach ( $ searches as $ key => $ search ) { if ( is_null ( $ encoding ) ) { $ encoding = mb_detect_encoding ( $ search , 'UTF-8' , true ) ; } $ replace = $ replacements [ $ key ] ; $ searchLen = mb_strlen ( $ search , $ encoding ) ; $ sb = [ ] ; while ( ( $ offset = mb_strpos ( $ subject , $ search , 0 , $ encoding ) ) !== false ) { $ sb [ ] = mb_substr ( $ subject , 0 , $ offset , $ encoding ) ; $ subject = mb_substr ( $ subject , $ offset + $ searchLen , null , $ encoding ) ; ++ $ count ; } $ sb [ ] = $ subject ; $ subject = implode ( $ replace , $ sb ) ; } } return $ subject ; } | Replace all occurrences of the search string with the replacement string . Multibyte safe . |
41,503 | protected function cleanData ( $ data ) { $ replacementChars = array ( "\xe2\x80\x98" => "'" , "\xe2\x80\x99" => "'" , "\xe2\x80\x9a" => "'" , "\xe2\x80\x9b" => "'" , "\xe2\x80\x9c" => '"' , "\xe2\x80\x9d" => '"' , "\xe2\x80\x9e" => '"' , "\xe2\x80\x9f" => '"' , "\xe2\x80\x93" => '-' , "\xe2\x80\x94" => '--' , "\xe2\x80\xa6" => '...' , "\xc2\xa0" => ' ' , ) ; $ cleanedData = strtr ( $ data , $ replacementChars ) ; $ charsToReplace = array_map ( function ( $ code ) { return $ this -> mb_chr ( $ code ) ; } , array ( 133 , 145 , 146 , 147 , 148 , 150 , 151 , 194 ) ) ; $ cleanedData = $ this -> mb_str_replace ( $ charsToReplace , $ replacementChars , $ cleanedData ) ; return $ cleanedData ; } | Replaces curly quotes and other special characters with their standard equivalents |
41,504 | public function parseExdates ( array $ event ) { if ( empty ( $ event [ 'EXDATE_array' ] ) ) { return array ( ) ; } else { $ exdates = $ event [ 'EXDATE_array' ] ; } $ output = array ( ) ; $ currentTimeZone = $ this -> defaultTimeZone ; foreach ( $ exdates as $ subArray ) { end ( $ subArray ) ; $ finalKey = key ( $ subArray ) ; foreach ( $ subArray as $ key => $ value ) { if ( $ key === 'TZID' ) { $ checkTimeZone = $ subArray [ $ key ] ; if ( $ this -> isValidIanaTimeZoneId ( $ checkTimeZone ) ) { $ currentTimeZone = $ checkTimeZone ; } elseif ( $ this -> isValidCldrTimeZoneId ( $ checkTimeZone ) ) { $ currentTimeZone = $ this -> isValidCldrTimeZoneId ( $ checkTimeZone , true ) ; } else { $ currentTimeZone = $ this -> defaultTimeZone ; } } elseif ( is_numeric ( $ key ) ) { $ icalDate = $ subArray [ $ key ] ; if ( substr ( $ icalDate , - 1 ) === 'Z' ) { $ currentTimeZone = self :: TIME_ZONE_UTC ; } $ output [ ] = new Carbon ( $ icalDate , $ currentTimeZone ) ; if ( $ key === $ finalKey ) { $ currentTimeZone = $ this -> defaultTimeZone ; } } } } return $ output ; } | Parses a list of excluded dates to be applied to an Event |
41,505 | public function isValidDate ( $ value ) { if ( ! $ value ) { return false ; } try { new \ DateTime ( $ value ) ; return true ; } catch ( \ Exception $ e ) { return false ; } } | Checks if a date string is a valid date |
41,506 | protected function fileOrUrl ( $ filename ) { $ options = array ( ) ; if ( ! empty ( $ this -> httpBasicAuth ) || ! empty ( $ this -> httpUserAgent ) ) { $ options [ 'http' ] = array ( ) ; $ options [ 'http' ] [ 'header' ] = array ( ) ; if ( ! empty ( $ this -> httpBasicAuth ) ) { $ username = $ this -> httpBasicAuth [ 'username' ] ; $ password = $ this -> httpBasicAuth [ 'password' ] ; $ basicAuth = base64_encode ( "{$username}:{$password}" ) ; array_push ( $ options [ 'http' ] [ 'header' ] , "Authorization: Basic {$basicAuth}" ) ; } if ( ! empty ( $ this -> httpUserAgent ) ) { array_push ( $ options [ 'http' ] [ 'header' ] , "User-Agent: {$this->httpUserAgent}" ) ; } } $ context = stream_context_create ( $ options ) ; if ( ( $ lines = file ( $ filename , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES , $ context ) ) === false ) { throw new \ Exception ( "The file path or URL '{$filename}' does not exist." ) ; } return $ lines ; } | Reads an entire file or URL into an array |
41,507 | protected function trimToRecurrenceCount ( array $ rrules , array $ recurrenceEvents ) { if ( isset ( $ rrules [ 'COUNT' ] ) ) { $ recurrenceCount = ( intval ( $ rrules [ 'COUNT' ] ) - 1 ) ; $ surplusCount = ( sizeof ( $ recurrenceEvents ) - $ recurrenceCount ) ; if ( $ surplusCount > 0 ) { $ recurrenceEvents = array_slice ( $ recurrenceEvents , 0 , $ recurrenceCount ) ; $ this -> eventCount -= $ surplusCount ; } } return $ recurrenceEvents ; } | Ensures the recurrence count is enforced against generated recurrence events . |
41,508 | protected function isExdateMatch ( $ exdate , array $ anEvent , $ recurringOffset ) { $ searchDate = $ anEvent [ 'DTSTART' ] ; if ( substr ( $ searchDate , - 1 ) === 'Z' ) { $ timeZone = self :: TIME_ZONE_UTC ; } else { if ( isset ( $ anEvent [ 'DTSTART_array' ] [ 0 ] [ 'TZID' ] ) ) { $ checkTimeZone = $ anEvent [ 'DTSTART_array' ] [ 0 ] [ 'TZID' ] ; if ( $ this -> isValidIanaTimeZoneId ( $ checkTimeZone ) ) { $ timeZone = $ checkTimeZone ; } elseif ( $ this -> isValidCldrTimeZoneId ( $ checkTimeZone ) ) { $ timeZone = $ this -> isValidCldrTimeZoneId ( $ checkTimeZone , true ) ; } else { $ timeZone = $ this -> defaultTimeZone ; } } else { $ timeZone = $ this -> defaultTimeZone ; } } $ a = new Carbon ( $ searchDate , $ timeZone ) ; $ b = $ exdate -> addSeconds ( $ recurringOffset ) ; return $ a -> eq ( $ b ) ; } | Checks if an excluded date matches a given date by reconciling time zones . |
41,509 | protected function filters ( Builder $ builder ) { return collect ( $ builder -> wheres ) -> map ( function ( $ value , $ key ) { return [ 'match_phrase' => [ $ key => $ value ] ] ; } ) -> values ( ) -> all ( ) ; } | Get the filter array for the query . |
41,510 | public function ignore ( ) { $ args = func_get_args ( ) ; foreach ( $ args as $ arg ) { if ( is_array ( $ arg ) ) { $ this -> ignores = array_merge ( $ this -> ignores , $ arg ) ; } else { $ this -> ignores [ ] = $ arg ; } } $ this -> ignores = array_unique ( $ this -> ignores ) ; return $ this ; } | Ignore bad HTTP requests |
41,511 | public static function create ( $ config ) { $ clientBuilder = ClientBuilder :: create ( ) ; if ( ! empty ( $ config [ 'handler' ] ) ) { $ clientBuilder -> setHandler ( $ config [ 'handler' ] ) ; } $ clientBuilder -> setHosts ( $ config [ "servers" ] ) ; $ clientBuilder = self :: configureLogging ( $ clientBuilder , $ config ) ; $ query = new Query ( $ clientBuilder -> build ( ) ) ; if ( array_key_exists ( "index" , $ config ) and $ config [ "index" ] != "" ) { $ query -> index ( $ config [ "index" ] ) ; } return $ query ; } | Create a native connection suitable for any non - laravel or non - lumen apps any composer based frameworks |
41,512 | function connection ( $ name ) { if ( $ this -> isLoaded ( $ name ) ) { $ this -> connection = $ this -> connections [ $ name ] ; return $ this -> newQuery ( $ name ) ; } if ( array_key_exists ( $ name , $ this -> config [ "connections" ] ) ) { $ config = $ this -> config [ "connections" ] [ $ name ] ; $ clientBuilder = ClientBuilder :: create ( ) ; $ clientBuilder -> setHosts ( $ config [ "servers" ] ) ; $ clientBuilder = self :: configureLogging ( $ clientBuilder , $ config ) ; if ( ! empty ( $ config [ 'handler' ] ) ) { $ clientBuilder -> setHandler ( $ config [ 'handler' ] ) ; } $ connection = $ clientBuilder -> build ( ) ; $ this -> connection = $ connection ; $ this -> connections [ $ name ] = $ connection ; return $ this -> newQuery ( $ name ) ; } $ this -> app -> abort ( 500 , "Invalid elasticsearch connection driver `" . $ name . "`" ) ; } | Create a connection for laravel or lumen frameworks |
41,513 | function newQuery ( $ connection ) { $ config = $ this -> config [ "connections" ] [ $ connection ] ; $ query = new Query ( $ this -> connections [ $ connection ] ) ; if ( array_key_exists ( "index" , $ config ) and $ config [ "index" ] != "" ) { $ query -> index ( $ config [ "index" ] ) ; } return $ query ; } | route the request to the query class |
41,514 | public static function url ( ) { $ server = $ _SERVER ; $ ssl = ( ! empty ( $ server [ 'HTTPS' ] ) && $ server [ 'HTTPS' ] == 'on' ) ; $ sp = strtolower ( $ server [ 'SERVER_PROTOCOL' ] ) ; $ protocol = substr ( $ sp , 0 , strpos ( $ sp , '/' ) ) . ( ( $ ssl ) ? 's' : '' ) ; $ port = $ server [ 'SERVER_PORT' ] ; $ port = ( ( ! $ ssl && $ port == '80' ) || ( $ ssl && $ port == '443' ) ) ? '' : ':' . $ port ; $ host = isset ( $ host ) ? $ host : $ server [ 'SERVER_NAME' ] . $ port ; $ host .= preg_replace ( "/\?.*/" , "" , $ server [ "REQUEST_URI" ] ) ; return $ protocol . '://' . $ host ; } | Get the request url |
41,515 | public static function get ( $ name , $ value = NULL ) { return isset ( $ _GET [ $ name ] ) ? $ _GET [ $ name ] : $ value ; } | Get value of query string parameter |
41,516 | protected function getOriginalAttribute ( $ name ) { $ method = "get" . ucfirst ( camel_case ( $ name ) ) . "Attribute" ; $ value = method_exists ( $ this , $ method ) ? $ this -> $ method ( $ this -> attributes [ $ name ] ) : $ this -> attributes [ $ name ] ; return $ this -> setAttributeType ( $ name , $ value ) ; } | Get original model attribute |
41,517 | protected function getAppendsAttribute ( $ name ) { $ method = "get" . ucfirst ( camel_case ( $ name ) ) . "Attribute" ; $ value = method_exists ( $ this , $ method ) ? $ this -> $ method ( NULL ) : NULL ; return $ this -> setAttributeType ( $ name , $ value ) ; } | Get Appends model attribute |
41,518 | protected function setAttributeType ( $ name , $ value ) { if ( array_key_exists ( $ name , $ this -> casts ) ) { if ( in_array ( $ this -> casts [ $ name ] , $ this -> castTypes ) ) { settype ( $ value , $ this -> casts [ $ name ] ) ; } } return $ value ; } | Set attributes casting |
41,519 | public function toArray ( ) { $ attributes = [ ] ; foreach ( $ this -> attributes as $ name => $ value ) { $ attributes [ $ name ] = $ this -> getOriginalAttribute ( $ name ) ; } foreach ( $ this -> appends as $ name ) { $ attributes [ $ name ] = $ this -> getAppendsAttribute ( $ name ) ; } return $ attributes ; } | Get model as array |
41,520 | protected function newQuery ( ) { $ query = app ( "es" ) -> setModel ( $ this ) ; $ query -> connection ( $ this -> getConnection ( ) ) ; if ( $ index = $ this -> getIndex ( ) ) { $ query -> index ( $ index ) ; } if ( $ type = $ this -> getType ( ) ) { $ query -> type ( $ type ) ; } return $ query ; } | Create a new model query |
41,521 | public static function find ( $ key ) { $ instance = new static ; $ model = $ instance -> newQuery ( ) -> id ( $ key ) -> take ( 1 ) -> first ( ) ; if ( $ model ) { $ model -> exists = true ; } return $ model ; } | Get model by key |
41,522 | function delete ( ) { if ( ! $ this -> exists ( ) ) { return false ; } $ this -> newQuery ( ) -> id ( $ this -> getID ( ) ) -> delete ( ) ; $ this -> exists = false ; return $ this ; } | Delete model record |
41,523 | public function save ( ) { $ fields = array_except ( $ this -> attributes , [ "_index" , "_type" , "_id" , "_score" ] ) ; if ( $ this -> exists ( ) ) { $ this -> newQuery ( ) -> id ( $ this -> getID ( ) ) -> update ( $ fields ) ; } else { if ( array_key_exists ( "_id" , $ this -> attributes ) ) { $ created = $ this -> newQuery ( ) -> id ( $ this -> attributes [ "_id" ] ) -> insert ( $ fields ) ; $ this -> _id = $ this -> attributes [ "_id" ] ; } else { $ created = $ this -> newQuery ( ) -> insert ( $ fields ) ; $ this -> _id = $ created -> _id ; } $ this -> setConnection ( $ this -> getConnection ( ) ) ; $ this -> setIndex ( $ created -> _index ) ; $ this -> _index = $ created -> _index ; $ this -> _type = $ this -> type ; $ this -> exists = true ; } return $ this ; } | Save data to model |
41,524 | public function fields ( $ fields = [ ] ) { $ searchable = [ ] ; foreach ( $ fields as $ field => $ weight ) { $ weight_suffix = $ weight > 1 ? "^$weight" : "" ; $ searchable [ ] = $ field . $ weight_suffix ; } $ this -> fields = $ searchable ; return $ this ; } | Set searchable fields |
41,525 | public function build ( ) { $ query_params = [ ] ; $ query_params [ "query" ] = $ this -> q ; if ( $ this -> boost > 1 ) { $ query_params [ "boost" ] = $ this -> boost ; } if ( count ( $ this -> fields ) ) { $ query_params [ "fields" ] = $ this -> fields ; } $ this -> query -> must [ ] = [ "query_string" => $ query_params ] ; } | Build the native query |
41,526 | function migrate ( $ original_index , $ new_index , $ scroll_id = null , $ errors = 0 , $ page = 1 ) { if ( $ page == 1 ) { $ pages = ( int ) ceil ( $ this -> es -> connection ( $ this -> connection ) -> index ( $ original_index ) -> count ( ) / $ this -> size ) ; $ this -> output -> progressStart ( $ pages ) ; $ documents = $ this -> es -> connection ( $ this -> connection ) -> index ( $ original_index ) -> type ( "" ) -> scroll ( $ this -> scroll ) -> take ( $ this -> size ) -> response ( ) ; } else { $ documents = $ this -> es -> connection ( $ this -> connection ) -> index ( $ original_index ) -> type ( "" ) -> scroll ( $ this -> scroll ) -> scrollID ( $ scroll_id ) -> response ( ) ; } if ( isset ( $ documents [ "hits" ] [ "hits" ] ) and count ( $ documents [ "hits" ] [ "hits" ] ) ) { $ data = $ documents [ "hits" ] [ "hits" ] ; $ params = [ ] ; foreach ( $ data as $ row ) { $ params [ "body" ] [ ] = [ 'index' => [ '_index' => $ new_index , '_type' => $ row [ "_type" ] , '_id' => $ row [ "_id" ] ] ] ; $ params [ "body" ] [ ] = $ row [ "_source" ] ; } $ response = $ this -> es -> connection ( $ this -> connection ) -> raw ( ) -> bulk ( $ params ) ; if ( isset ( $ response [ "errors" ] ) and $ response [ "errors" ] ) { if ( ! $ this -> option ( "hide-errors" ) ) { if ( $ this -> option ( "skip-errors" ) ) { $ this -> warn ( "\n" . json_encode ( $ response [ "items" ] ) ) ; } else { return $ this -> warn ( "\n" . json_encode ( $ response [ "items" ] ) ) ; } } $ errors ++ ; } $ this -> output -> progressAdvance ( ) ; } else { $ this -> output -> progressFinish ( ) ; $ total = $ this -> es -> connection ( $ this -> connection ) -> index ( $ original_index ) -> count ( ) ; if ( $ errors > 0 ) { return $ this -> warn ( "$total documents reindexed with $errors errors." ) ; } else { return $ this -> info ( "$total documents reindexed $errors errors." ) ; } } $ page ++ ; $ this -> migrate ( $ original_index , $ new_index , $ documents [ "_scroll_id" ] , $ errors , $ page ) ; } | Migrate data with Scroll queries & Bulk API |
41,527 | public function select ( ) { $ args = func_get_args ( ) ; foreach ( $ args as $ arg ) { if ( is_array ( $ arg ) ) { $ this -> _source = array_merge ( $ this -> _source , $ arg ) ; } else { $ this -> _source [ ] = $ arg ; } } return $ this ; } | Set the query fields to return |
41,528 | public function _id ( $ _id = false ) { $ this -> _id = $ _id ; $ this -> filter [ ] = [ "term" => [ "_id" => $ _id ] ] ; return $ this ; } | Filter by _id |
41,529 | public function where ( $ name , $ operator = "=" , $ value = NULL ) { if ( is_callback_function ( $ name ) ) { $ name ( $ this ) ; return $ this ; } if ( ! $ this -> isOperator ( $ operator ) ) { $ value = $ operator ; $ operator = "=" ; } if ( $ operator == "=" ) { if ( $ name == "_id" ) { return $ this -> _id ( $ value ) ; } $ this -> filter [ ] = [ "term" => [ $ name => $ value ] ] ; } if ( $ operator == ">" ) { $ this -> filter [ ] = [ "range" => [ $ name => [ "gt" => $ value ] ] ] ; } if ( $ operator == ">=" ) { $ this -> filter [ ] = [ "range" => [ $ name => [ "gte" => $ value ] ] ] ; } if ( $ operator == "<" ) { $ this -> filter [ ] = [ "range" => [ $ name => [ "lt" => $ value ] ] ] ; } if ( $ operator == "<=" ) { $ this -> filter [ ] = [ "range" => [ $ name => [ "lte" => $ value ] ] ] ; } if ( $ operator == "like" ) { $ this -> must [ ] = [ "match" => [ $ name => $ value ] ] ; } if ( $ operator == "exists" ) { $ this -> whereExists ( $ name , $ value ) ; } return $ this ; } | Set the query where clause |
41,530 | public function whereNot ( $ name , $ operator = "=" , $ value = NULL ) { if ( is_callback_function ( $ name ) ) { $ name ( $ this ) ; return $ this ; } if ( ! $ this -> isOperator ( $ operator ) ) { $ value = $ operator ; $ operator = "=" ; } if ( $ operator == "=" ) { $ this -> must_not [ ] = [ "term" => [ $ name => $ value ] ] ; } if ( $ operator == ">" ) { $ this -> must_not [ ] = [ "range" => [ $ name => [ "gt" => $ value ] ] ] ; } if ( $ operator == ">=" ) { $ this -> must_not [ ] = [ "range" => [ $ name => [ "gte" => $ value ] ] ] ; } if ( $ operator == "<" ) { $ this -> must_not [ ] = [ "range" => [ $ name => [ "lt" => $ value ] ] ] ; } if ( $ operator == "<=" ) { $ this -> must_not [ ] = [ "range" => [ $ name => [ "lte" => $ value ] ] ] ; } if ( $ operator == "like" ) { $ this -> must_not [ ] = [ "match" => [ $ name => $ value ] ] ; } if ( $ operator == "exists" ) { $ this -> whereExists ( $ name , ! $ value ) ; } return $ this ; } | Set the query inverse where clause |
41,531 | public function whereBetween ( $ name , $ first_value , $ last_value = null ) { if ( is_array ( $ first_value ) && count ( $ first_value ) == 2 ) { $ last_value = $ first_value [ 1 ] ; $ first_value = $ first_value [ 0 ] ; } $ this -> filter [ ] = [ "range" => [ $ name => [ "gte" => $ first_value , "lte" => $ last_value ] ] ] ; return $ this ; } | Set the query where between clause |
41,532 | public function whereNotBetween ( $ name , $ first_value , $ last_value = null ) { if ( is_array ( $ first_value ) && count ( $ first_value ) == 2 ) { $ last_value = $ first_value [ 1 ] ; $ first_value = $ first_value [ 0 ] ; } $ this -> must_not [ ] = [ "range" => [ $ name => [ "gte" => $ first_value , "lte" => $ last_value ] ] ] ; return $ this ; } | Set the query where not between clause |
41,533 | public function whereIn ( $ name , $ value = [ ] ) { if ( is_callback_function ( $ name ) ) { $ name ( $ this ) ; return $ this ; } $ this -> filter [ ] = [ "terms" => [ $ name => $ value ] ] ; return $ this ; } | Set the query where in clause |
41,534 | public function whereNotIn ( $ name , $ value = [ ] ) { if ( is_callback_function ( $ name ) ) { $ name ( $ this ) ; return $ this ; } $ this -> must_not [ ] = [ "terms" => [ $ name => $ value ] ] ; return $ this ; } | Set the query where not in clause |
41,535 | public function whereExists ( $ name , $ exists = true ) { if ( $ exists ) { $ this -> must [ ] = [ "exists" => [ "field" => $ name ] ] ; } else { $ this -> must_not [ ] = [ "exists" => [ "field" => $ name ] ] ; } return $ this ; } | Set the query where exists clause |
41,536 | public function distance ( $ name , $ value , $ distance ) { if ( is_callback_function ( $ name ) ) { $ name ( $ this ) ; return $ this ; } $ this -> filter [ ] = [ "geo_distance" => [ $ name => $ value , "distance" => $ distance , ] ] ; return $ this ; } | Add a condition to find documents which are some distance away from the given geo point . |
41,537 | public function search ( $ q = NULL , $ settings = NULL ) { if ( $ q ) { $ search = new Search ( $ this , $ q , $ settings ) ; if ( ! is_callback_function ( $ settings ) ) { $ search -> boost ( $ settings ? $ settings : 1 ) ; } $ search -> build ( ) ; } return $ this ; } | Search the entire document fields |
41,538 | protected function getBody ( ) { $ body = $ this -> body ; if ( count ( $ this -> _source ) ) { $ _source = array_key_exists ( "_source" , $ body ) ? $ body [ "_source" ] : [ ] ; $ body [ "_source" ] = array_unique ( array_merge ( $ _source , $ this -> _source ) ) ; } if ( count ( $ this -> must ) ) { $ body [ "query" ] [ "bool" ] [ "must" ] = $ this -> must ; } if ( count ( $ this -> must_not ) ) { $ body [ "query" ] [ "bool" ] [ "must_not" ] = $ this -> must_not ; } if ( count ( $ this -> filter ) ) { $ body [ "query" ] [ "bool" ] [ "filter" ] = $ this -> filter ; } if ( count ( $ this -> sort ) ) { $ sortFields = array_key_exists ( "sort" , $ body ) ? $ body [ "sort" ] : [ ] ; $ body [ "sort" ] = array_unique ( array_merge ( $ sortFields , $ this -> sort ) , SORT_REGULAR ) ; } $ this -> body = $ body ; return $ body ; } | Generate the query body |
41,539 | public function query ( ) { $ query = [ ] ; $ query [ "index" ] = $ this -> getIndex ( ) ; if ( $ this -> getType ( ) ) { $ query [ "type" ] = $ this -> getType ( ) ; } if ( $ this -> model && $ this -> useGlobalScopes ) { $ this -> model -> boot ( $ this ) ; } $ query [ "body" ] = $ this -> getBody ( ) ; $ query [ "from" ] = $ this -> getSkip ( ) ; $ query [ "size" ] = $ this -> getTake ( ) ; if ( count ( $ this -> ignores ) ) { $ query [ "client" ] = [ 'ignore' => $ this -> ignores ] ; } $ search_type = $ this -> getSearchType ( ) ; if ( $ search_type ) { $ query [ "search_type" ] = $ search_type ; } $ scroll = $ this -> getScroll ( ) ; if ( $ scroll ) { $ query [ "scroll" ] = $ scroll ; } return $ query ; } | Generate the query to be executed |
41,540 | public function clear ( $ scroll_id = NULL ) { $ scroll_id = ! is_null ( $ scroll_id ) ? $ scroll_id : $ this -> scroll_id ; return $ this -> connection -> clearScroll ( [ "scroll_id" => $ scroll_id , 'client' => [ 'ignore' => $ this -> ignores ] ] ) ; } | Clear scroll query id |
41,541 | public function get ( $ scroll_id = NULL ) { $ scroll_id = NULL ; $ result = $ this -> getResult ( $ scroll_id ) ; return $ this -> getAll ( $ result ) ; } | Get the collection of results |
41,542 | public function first ( $ scroll_id = NULL ) { $ this -> take ( 1 ) ; $ result = $ this -> getResult ( $ scroll_id ) ; return $ this -> getFirst ( $ result ) ; } | Get the first object of results |
41,543 | protected function getResult ( $ scroll_id ) { if ( is_null ( $ this -> cacheMinutes ) ) { $ result = $ this -> response ( $ scroll_id ) ; } else { $ result = app ( "cache" ) -> driver ( $ this -> cacheDriver ) -> get ( $ this -> getCacheKey ( ) ) ; if ( is_null ( $ result ) ) { $ result = $ this -> response ( $ scroll_id ) ; } } return $ result ; } | Get query result |
41,544 | public function response ( $ scroll_id = NULL ) { $ scroll_id = ! is_null ( $ scroll_id ) ? $ scroll_id : $ this -> scroll_id ; if ( $ scroll_id ) { $ result = $ this -> connection -> scroll ( [ "scroll" => $ this -> scroll , "scroll_id" => $ scroll_id ] ) ; } else { $ result = $ this -> connection -> search ( $ this -> query ( ) ) ; } if ( ! is_null ( $ this -> cacheMinutes ) ) { app ( "cache" ) -> driver ( $ this -> cacheDriver ) -> put ( $ this -> getCacheKey ( ) , $ result , $ this -> cacheMinutes ) ; } return $ result ; } | Get non cached results |
41,545 | public function count ( ) { $ query = $ this -> query ( ) ; unset ( $ query [ "size" ] , $ query [ "from" ] , $ query [ "body" ] [ "_source" ] , $ query [ "body" ] [ "sort" ] ) ; return $ this -> connection -> count ( $ query ) [ "count" ] ; } | Get the count of result |
41,546 | protected function getFirst ( $ result = [ ] ) { if ( array_key_exists ( "hits" , $ result ) && count ( $ result [ "hits" ] [ "hits" ] ) ) { $ data = $ result [ "hits" ] [ "hits" ] ; if ( $ this -> model ) { $ model = new $ this -> model ( $ data [ 0 ] [ "_source" ] , true ) ; } else { $ model = new Model ( $ data [ 0 ] [ "_source" ] , true ) ; $ model -> setConnection ( $ model -> getConnection ( ) ) ; $ model -> setIndex ( $ data [ 0 ] [ "_index" ] ) ; $ model -> setType ( $ data [ 0 ] [ "_type" ] ) ; } $ model -> _index = $ data [ 0 ] [ "_index" ] ; $ model -> _type = $ data [ 0 ] [ "_type" ] ; $ model -> _id = $ data [ 0 ] [ "_id" ] ; $ model -> _score = $ data [ 0 ] [ "_score" ] ; $ new = $ model ; } else { $ new = NULL ; } return $ new ; } | Retrieve only first record |
41,547 | public function paginate ( $ per_page = 10 , $ page_name = "page" , $ page = null ) { $ this -> take ( $ per_page ) ; $ page = $ page ? : Request :: get ( $ page_name , 1 ) ; $ this -> skip ( ( $ page * $ per_page ) - $ per_page ) ; $ objects = $ this -> get ( ) ; return new Pagination ( $ objects , $ objects -> total , $ per_page , $ page , [ 'path' => Request :: url ( ) , 'query' => Request :: query ( ) ] ) ; } | Paginate collection of results |
41,548 | public function bulk ( $ data ) { if ( is_callback_function ( $ data ) ) { $ bulk = new Bulk ( $ this ) ; $ data ( $ bulk ) ; $ params = $ bulk -> body ( ) ; } else { $ params = [ ] ; foreach ( $ data as $ key => $ value ) { $ params [ "body" ] [ ] = [ 'index' => [ '_index' => $ this -> getIndex ( ) , '_type' => $ this -> getType ( ) , '_id' => $ key ] ] ; $ params [ "body" ] [ ] = $ value ; } } return ( object ) $ this -> connection -> bulk ( $ params ) ; } | Insert a bulk of documents |
41,549 | public function update ( $ data , $ _id = NULL ) { if ( $ _id ) { $ this -> _id = $ _id ; } $ parameters = [ "id" => $ this -> _id , "body" => [ 'doc' => $ data ] , 'client' => [ 'ignore' => $ this -> ignores ] ] ; if ( $ index = $ this -> getIndex ( ) ) { $ parameters [ "index" ] = $ index ; } if ( $ type = $ this -> getType ( ) ) { $ parameters [ "type" ] = $ type ; } return ( object ) $ this -> connection -> update ( $ parameters ) ; } | Update a document |
41,550 | public function script ( $ script , $ params = [ ] ) { $ parameters = [ "id" => $ this -> _id , "body" => [ "script" => [ "inline" => $ script , "params" => $ params ] ] , 'client' => [ 'ignore' => $ this -> ignores ] ] ; if ( $ index = $ this -> getIndex ( ) ) { $ parameters [ "index" ] = $ index ; } if ( $ type = $ this -> getType ( ) ) { $ parameters [ "type" ] = $ type ; } return ( object ) $ this -> connection -> update ( $ parameters ) ; } | Update by script |
41,551 | function exists ( ) { $ index = new Index ( $ this -> index ) ; $ index -> connection = $ this -> connection ; return $ index -> exists ( ) ; } | Check existence of index |
41,552 | public function action ( $ actionType , $ data = [ ] ) { $ this -> body [ "body" ] [ ] = [ $ actionType => [ '_index' => $ this -> getIndex ( ) , '_type' => $ this -> getType ( ) , '_id' => $ this -> _id ] ] ; if ( ! empty ( $ data ) ) { if ( $ actionType == "update" ) { $ this -> body [ "body" ] [ ] = [ "doc" => $ data ] ; } else { $ this -> body [ "body" ] [ ] = $ data ; } } $ this -> operationCount ++ ; $ this -> reset ( ) ; if ( $ this -> autocommitAfter > 0 && $ this -> operationCount >= $ this -> autocommitAfter ) { return $ this -> commit ( ) ; } return true ; } | Add pending document abstract action |
41,553 | public function commit ( ) { if ( empty ( $ this -> body ) ) { return false ; } $ result = $ this -> query -> connection -> bulk ( $ this -> body ) ; $ this -> operationCount = 0 ; $ this -> body = [ ] ; return $ result ; } | Commit all pending operations |
41,554 | protected function getConfigException ( $ exceptionName ) { $ exceptionParentName = get_parent_class ( $ exceptionName ) ; if ( in_array ( 'M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\ExceptionInterface' , class_implements ( $ exceptionParentName ) ) ) { $ parentConfig = $ this -> getConfigException ( $ exceptionParentName ) ; } else { $ parentConfig = $ this -> defaultConfig ; } if ( isset ( $ this -> exceptions [ $ exceptionName ] ) ) { return array_merge ( $ parentConfig , $ this -> exceptions [ $ exceptionName ] ) ; } return $ parentConfig ; } | Get config to exception |
41,555 | protected function loadExceptionManager ( ContainerBuilder $ container , array $ config ) { $ definition = new Definition ( 'M6Web\Bundle\ApiExceptionBundle\Manager\ExceptionManager' , [ $ config [ 'default' ] , $ config [ 'exceptions' ] , ] ) ; $ definition -> setPublic ( true ) ; $ container -> setDefinition ( $ this -> getAlias ( ) . '.manager.exception' , $ definition ) ; } | load service exception manager |
41,556 | protected function loadExceptionListener ( ContainerBuilder $ container , array $ config ) { $ definition = new Definition ( 'M6Web\Bundle\ApiExceptionBundle\EventListener\ExceptionListener' , [ new Reference ( 'kernel' ) , new Reference ( $ this -> getAlias ( ) . '.manager.exception' ) , $ config [ 'match_all' ] , $ config [ 'default' ] , $ config [ 'stack_trace' ] , ] ) ; $ definition -> setPublic ( true ) ; $ definition -> addTag ( 'kernel.event_listener' , [ 'event' => 'kernel.exception' , 'method' => 'onKernelException' , 'priority' => '-100' ] ) ; $ container -> setDefinition ( $ this -> getAlias ( ) . '.listener.exception' , $ definition ) ; } | load service exception listener |
41,557 | public function getMessageWithVariables ( ) { $ message = $ this -> message ; preg_match ( self :: VARIABLE_REGEX , $ message , $ variables ) ; foreach ( $ variables as $ variable ) { $ variableName = substr ( $ variable , 1 , - 1 ) ; if ( ! isset ( $ this -> $ variableName ) ) { throw new \ Exception ( sprintf ( 'Variable "%s" for exception "%s" not found' , $ variableName , get_class ( $ this ) ) , 500 ) ; } if ( ! is_string ( $ this -> $ variableName ) ) { throw new \ Exception ( sprintf ( 'Variable "%s" for exception "%s" must be a string, %s found' , $ variableName , get_class ( $ this ) , gettype ( $ this -> $ variableName ) ) , 500 ) ; } $ message = str_replace ( $ variable , $ this -> $ variableName , $ message ) ; } return $ message ; } | Get message with variables |
41,558 | public function onKernelException ( GetResponseForExceptionEvent $ event ) { $ exception = $ event -> getException ( ) ; if ( ! ( $ event -> getRequest ( ) ) || ( $ this -> matchAll === false && ! $ this -> isApiException ( $ exception ) ) ) { return ; } $ data = [ ] ; if ( $ this -> isApiException ( $ exception ) ) { $ exception = $ this -> exceptionManager -> configure ( $ exception ) ; } $ statusCode = $ this -> getStatusCode ( $ exception ) ; $ data [ 'error' ] [ 'status' ] = $ statusCode ; if ( $ code = $ exception -> getCode ( ) ) { $ data [ 'error' ] [ 'code' ] = $ code ; } $ data [ 'error' ] [ 'message' ] = $ this -> getMessage ( $ exception ) ; if ( $ this -> isFlattenErrorException ( $ exception ) ) { $ data [ 'error' ] [ 'errors' ] = $ exception -> getFlattenErrors ( ) ; } if ( $ this -> stackTrace ) { $ data [ 'error' ] [ 'stack_trace' ] = $ exception -> getTrace ( ) ; array_walk_recursive ( $ data [ 'error' ] [ 'stack_trace' ] , function ( & $ item ) { if ( is_object ( $ item ) ) { $ item = get_class ( $ item ) ; } elseif ( is_resource ( $ item ) ) { $ item = get_resource_type ( $ item ) ; } } ) ; } $ response = new JsonResponse ( $ data , $ statusCode , $ this -> getHeaders ( $ exception ) ) ; $ event -> setResponse ( $ response ) ; } | Format response exception |
41,559 | private function getStatusCode ( \ Exception $ exception ) { $ statusCode = $ this -> default [ 'status' ] ; if ( $ exception instanceof SymfonyHttpExceptionInterface || $ exception instanceof HttpExceptionInterface ) { $ statusCode = $ exception -> getStatusCode ( ) ; } return $ statusCode ; } | Get exception status code |
41,560 | private function getMessage ( \ Exception $ exception ) { $ message = $ exception -> getMessage ( ) ; if ( $ this -> isApiException ( $ exception ) ) { $ message = $ exception -> getMessageWithVariables ( ) ; } return $ message ; } | Get exception message |
41,561 | private function getHeaders ( \ Exception $ exception ) { $ headers = $ this -> default [ 'headers' ] ; if ( $ exception instanceof SymfonyHttpExceptionInterface || $ exception instanceof HttpExceptionInterface ) { $ headers = $ exception -> getHeaders ( ) ; } return $ headers ; } | Get exception headers |
41,562 | public function getFlattenErrors ( FormInterface $ form = null , $ subForm = false ) { $ form = $ form ? : $ this -> form ; $ flatten = [ ] ; foreach ( $ form -> getErrors ( ) as $ error ) { if ( $ subForm ) { $ flatten [ ] = $ error -> getMessage ( ) ; } else { $ path = $ error -> getCause ( ) -> getPropertyPath ( ) ; if ( ! array_key_exists ( $ path , $ flatten ) ) { $ flatten [ $ path ] = [ $ error -> getMessage ( ) ] ; continue ; } $ flatten [ $ path ] [ ] = $ error -> getMessage ( ) ; } } $ subForm = true ; foreach ( $ form -> all ( ) as $ key => $ child ) { $ childErrors = $ this -> getFlattenErrors ( $ child , $ subForm ) ; if ( ! empty ( $ childErrors ) ) { $ flatten [ $ key ] = $ childErrors ; } } return $ flatten ; } | Flatten form errors |
41,563 | protected function processParts ( array $ parts ) { $ strValue = '' ; $ ret = [ ] ; $ filtered = $ this -> filterIgnoredSpaces ( $ parts ) ; foreach ( $ filtered as $ part ) { if ( $ part instanceof CommentPart ) { $ ret [ ] = $ part ; continue ; } $ strValue .= $ part -> getValue ( ) ; } array_unshift ( $ ret , $ this -> partFactory -> newReceivedPart ( $ this -> getPartName ( ) , $ strValue ) ) ; return $ ret ; } | Overridden to combine all part values into a single string and return it as the first element followed by any comment elements as subsequent elements . |
41,564 | public function getAddress ( $ index ) { if ( ! isset ( $ this -> addresses [ $ index ] ) ) { return null ; } return $ this -> addresses [ $ index ] ; } | Returns the AddressPart at the passed index or null . |
41,565 | protected function processParts ( array $ parts ) { $ comment = '' ; foreach ( $ parts as $ part ) { if ( $ part instanceof CommentPart ) { $ comment .= '(' . $ part -> getComment ( ) . ')' ; } elseif ( $ part instanceof LiteralPart ) { $ comment .= '"' . $ part -> getValue ( ) . '"' ; } else { $ comment .= $ part -> getValue ( ) ; } } return [ $ this -> partFactory -> newCommentPart ( $ comment ) ] ; } | Post processing involves creating a single Part \ CommentPart out of generated parts from tokens . The Part \ CommentPart is returned in an array . |
41,566 | private function matchHostPart ( $ value , & $ hostname , & $ address ) { $ matches = [ ] ; $ pattern = '~^(?P<name>[a-z0-9\-]+\.[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P<addr>[a-f\d\.\:]+)\])?$~i' ; if ( preg_match ( $ pattern , $ value , $ matches ) ) { if ( ! empty ( $ matches [ 'name' ] ) ) { $ hostname = $ matches [ 'name' ] ; } if ( ! empty ( $ matches [ 'addr' ] ) ) { $ address = $ matches [ 'addr' ] ; } return true ; } return false ; } | Attempts to match a parenthesized expression to find a hostname and an address . Returns true if the expression matched and either hostname or address were found . |
41,567 | protected function processParts ( array $ parts ) { $ ehloName = null ; $ hostname = null ; $ address = null ; $ commentPart = null ; $ filtered = $ this -> filterIgnoredSpaces ( $ parts ) ; foreach ( $ filtered as $ part ) { if ( $ part instanceof CommentPart ) { $ commentPart = $ part ; continue ; } $ ehloName .= $ part -> getValue ( ) ; } $ strValue = $ ehloName ; if ( $ commentPart !== null && $ this -> matchHostPart ( $ commentPart -> getComment ( ) , $ hostname , $ address ) ) { $ strValue .= ' (' . $ commentPart -> getComment ( ) . ')' ; $ commentPart = null ; } $ domainPart = $ this -> partFactory -> newReceivedDomainPart ( $ this -> getPartName ( ) , $ strValue , $ ehloName , $ hostname , $ address ) ; return array_filter ( [ $ domainPart , $ commentPart ] ) ; } | Creates a single ReceivedDomainPart out of matched parts . If an unmatched parenthesized expression was found it s returned as a CommentPart . |
41,568 | public function addPart ( $ value , $ isEncoded , $ index ) { if ( empty ( $ index ) ) { $ index = 0 ; } if ( $ isEncoded ) { $ this -> extractMetaInformationAndValue ( $ value , $ index ) ; } else { $ this -> literalParts [ $ index ] = $ this -> convertEncoding ( $ value ) ; } } | Adds the passed part to the running array of values . |
41,569 | public function getValue ( ) { $ parts = $ this -> literalParts ; reset ( $ this -> encodedParts ) ; ksort ( $ this -> encodedParts ) ; while ( current ( $ this -> encodedParts ) !== false ) { $ parts [ key ( $ this -> encodedParts ) ] = $ this -> getNextEncodedValue ( ) ; } ksort ( $ parts ) ; return array_reduce ( $ parts , function ( $ carry , $ item ) { return $ carry . $ item ; } , '' ) ; } | Reconstructs the value of the split parameter into a single UTF - 8 string and returns it . |
41,570 | public function setHeaders ( array $ headers ) { array_walk ( $ headers , function ( $ v , $ k ) { $ this -> validateArgument ( 'headers' , $ k , [ static :: FILTER_EXCLUDE , static :: FILTER_INCLUDE ] ) ; if ( ! is_array ( $ v ) ) { throw new InvalidArgumentException ( '$value must be an array with keys set to FILTER_EXCLUDE, ' . 'FILTER_INCLUDE and values set to an array of header ' . 'name => values' ) ; } } ) ; $ this -> headers = $ headers ; } | Sets the PartFilter s headers filter to the passed array after validating it . |
41,571 | private function failsHasContentFilter ( MessagePart $ part ) { return ( $ this -> hascontent === static :: FILTER_EXCLUDE && $ part -> hasContent ( ) ) || ( $ this -> hascontent === static :: FILTER_INCLUDE && ! $ part -> hasContent ( ) ) ; } | Returns true if the passed MessagePart fails the filter s hascontent filter settings . |
41,572 | private function failsMultiPartFilter ( MessagePart $ part ) { if ( ! ( $ part instanceof MimePart ) ) { return $ this -> multipart !== static :: FILTER_EXCLUDE ; } return ( $ this -> multipart === static :: FILTER_EXCLUDE && $ part -> isMultiPart ( ) ) || ( $ this -> multipart === static :: FILTER_INCLUDE && ! $ part -> isMultiPart ( ) ) ; } | Returns true if the passed MessagePart fails the filter s multipart filter settings . |
41,573 | private function failsTextPartFilter ( MessagePart $ part ) { return ( $ this -> textpart === static :: FILTER_EXCLUDE && $ part -> isTextPart ( ) ) || ( $ this -> textpart === static :: FILTER_INCLUDE && ! $ part -> isTextPart ( ) ) ; } | Returns true if the passed MessagePart fails the filter s textpart filter settings . |
41,574 | private function failsSignedPartFilter ( MessagePart $ part ) { if ( $ this -> signedpart === static :: FILTER_OFF ) { return false ; } elseif ( ! $ part -> isMime ( ) || $ part -> getParent ( ) === null ) { return ( $ this -> signedpart === static :: FILTER_INCLUDE ) ; } $ partMimeType = $ part -> getContentType ( ) ; $ parentMimeType = $ part -> getParent ( ) -> getContentType ( ) ; $ parentProtocol = $ part -> getParent ( ) -> getHeaderParameter ( 'Content-Type' , 'protocol' ) ; if ( strcasecmp ( $ parentMimeType , 'multipart/signed' ) === 0 && strcasecmp ( $ partMimeType , $ parentProtocol ) === 0 ) { return ( $ this -> signedpart === static :: FILTER_EXCLUDE ) ; } return ( $ this -> signedpart === static :: FILTER_INCLUDE ) ; } | Returns true if the passed MessagePart fails the filter s signedpart filter settings . |
41,575 | private function failsHeaderPartFilter ( MessagePart $ part ) { foreach ( $ this -> headers as $ type => $ values ) { foreach ( $ values as $ name => $ header ) { if ( $ this -> failsHeaderFor ( $ part , $ type , $ name , $ header ) ) { return true ; } } } return false ; } | Returns true if the passed MessagePart fails the filter s header filter settings . |
41,576 | public function filter ( MessagePart $ part ) { return ! ( $ this -> failsMultiPartFilter ( $ part ) || $ this -> failsTextPartFilter ( $ part ) || $ this -> failsSignedPartFilter ( $ part ) || $ this -> failsHeaderPartFilter ( $ part ) ) ; } | Determines if the passed MessagePart should be filtered out or not . If the MessagePart passes all filter tests true is returned . Otherwise false is returned . |
41,577 | public function getUniqueBoundary ( $ mimeType ) { $ type = ltrim ( strtoupper ( preg_replace ( '/^(multipart\/(.{3}).*|.*)$/i' , '$2-' , $ mimeType ) ) , '-' ) ; return uniqid ( '----=MMP-' . $ type . '.' , true ) ; } | Creates and returns a unique boundary . |
41,578 | public function findOtherContentPartFor ( Message $ message , $ mimeType ) { $ altPart = $ message -> getPart ( 0 , PartFilter :: fromInlineContentType ( ( $ mimeType === 'text/plain' ) ? 'text/html' : 'text/plain' ) ) ; if ( $ altPart !== null && $ altPart -> getParent ( ) !== null && $ altPart -> getParent ( ) -> isMultiPart ( ) ) { $ altPartParent = $ altPart -> getParent ( ) ; if ( $ altPartParent -> getChildCount ( PartFilter :: fromDisposition ( 'inline' , PartFilter :: FILTER_EXCLUDE ) ) !== 1 ) { $ altPart = $ this -> createMultipartRelatedPartForInlineChildrenOf ( $ altPartParent ) ; } } return $ altPart ; } | Finds an alternative inline part in the message and returns it if one exists . |
41,579 | public function createAndAddPartForAttachment ( Message $ message , $ resource , $ mimeType , $ disposition , $ filename = null ) { if ( $ filename === null ) { $ filename = 'file' . uniqid ( ) ; } $ safe = iconv ( 'UTF-8' , 'US-ASCII//translit//ignore' , $ filename ) ; if ( $ message -> isMime ( ) ) { $ builder = $ this -> partBuilderFactory -> newPartBuilder ( $ this -> mimePartFactory ) ; $ builder -> addHeader ( 'Content-Transfer-Encoding' , 'base64' ) ; if ( strcasecmp ( $ message -> getContentType ( ) , 'multipart/mixed' ) !== 0 ) { $ this -> setMessageAsMixed ( $ message ) ; } $ builder -> addHeader ( 'Content-Type' , "$mimeType;\r\n\tname=\"$safe\"" ) ; $ builder -> addHeader ( 'Content-Disposition' , "$disposition;\r\n\tfilename=\"$safe\"" ) ; } else { $ builder = $ this -> partBuilderFactory -> newPartBuilder ( $ this -> uuEncodedPartFactory ) ; $ builder -> setProperty ( 'filename' , $ safe ) ; } $ part = $ builder -> createMessagePart ( ) ; $ part -> setContent ( $ resource ) ; $ message -> addChild ( $ part ) ; } | Creates and adds a MimePart for the passed content and options as an attachment . |
41,580 | public function removeAllContentPartsByMimeType ( Message $ message , $ mimeType , $ keepOtherContent = false ) { $ alt = $ message -> getPart ( 0 , PartFilter :: fromInlineContentType ( 'multipart/alternative' ) ) ; if ( $ alt !== null ) { return $ this -> removeAllContentPartsFromAlternative ( $ message , $ mimeType , $ alt , $ keepOtherContent ) ; } $ message -> removeAllParts ( PartFilter :: fromInlineContentType ( $ mimeType ) ) ; return true ; } | Removes the content part of the message with the passed mime type . If there is a remaining content part and it is an alternative part of the main message the content part is moved to the message part . |
41,581 | public function removePartByMimeType ( Message $ message , $ mimeType , $ index = 0 ) { $ parts = $ message -> getAllParts ( PartFilter :: fromInlineContentType ( $ mimeType ) ) ; $ alt = $ message -> getPart ( 0 , PartFilter :: fromInlineContentType ( 'multipart/alternative' ) ) ; if ( $ parts === null || ! isset ( $ parts [ $ index ] ) ) { return false ; } elseif ( count ( $ parts ) === 1 ) { return $ this -> removeAllContentPartsByMimeType ( $ message , $ mimeType , true ) ; } $ part = $ parts [ $ index ] ; $ message -> removePart ( $ part ) ; if ( $ alt !== null && $ alt -> getChildCount ( ) === 1 ) { $ this -> genericHelper -> replacePart ( $ message , $ alt , $ alt -> getChild ( 0 ) ) ; } return true ; } | Removes the inline part with the passed contentType at the given index defaulting to the first |
41,582 | public static function buildValidation ( array $ schema , $ name = null ) { $ validation = new NestedValidation ( $ name ) ; foreach ( $ schema as $ key => $ value ) { if ( ! is_array ( $ value ) ) { trigger_error ( 'parsing error' , E_USER_ERROR ) ; } if ( self :: isNestedValidation ( $ value ) ) { $ validation -> addValidation ( self :: buildValidation ( $ value , $ key ) ) ; } else { $ validation -> addValidation ( self :: buildKeyValidation ( $ value , $ key ) ) ; } } return $ validation ; } | This function builds a validation acording to the specifgications of the json file |
41,583 | private static function isNestedValidation ( array $ value ) { return ! ( key_exists ( Properties :: TYPE , $ value ) && ! is_array ( $ value [ Properties :: TYPE ] ) ) ; } | Check if the found value is a nestedValidation |
41,584 | public static function buildKeyValidation ( array $ options , $ name ) { if ( ! key_exists ( Properties :: TYPE , $ options ) ) { trigger_error ( $ name . ' must have a type' ) ; } switch ( $ options [ Properties :: TYPE ] ) { case Types :: STR : case Types :: STRING : return new StringValidation ( $ name , $ options ) ; case Types :: INT : case Types :: INTEGER : return new IntegerValidation ( $ name , $ options ) ; case Types :: FLOAT : return new FloatValidation ( $ name , $ options ) ; case Types :: BOOLEAN : return new BooleanValidation ( $ name , $ options ) ; case Types :: ARRY : return new ArrayValidation ( $ name , $ options ) ; default : trigger_error ( sprintf ( '%s is unknown' , $ options [ Properties :: TYPE ] ) , E_USER_ERROR ) ; } } | Builds a KeyValidation |
41,585 | public static function escape ( $ string ) { Arguments :: define ( Boa :: either ( Boa :: either ( Boa :: instance ( SafeHtmlWrapper :: class ) , Boa :: instance ( SafeHtmlProducerInterface :: class ) ) , Boa :: string ( ) ) ) -> check ( $ string ) ; if ( $ string instanceof SafeHtmlWrapper ) { return $ string ; } elseif ( $ string instanceof SafeHtmlProducerInterface ) { $ result = $ string -> getSafeHtml ( ) ; if ( $ result instanceof SafeHtmlWrapper ) { return $ result ; } elseif ( $ result instanceof SafeHtmlProducerInterface ) { return static :: escape ( $ result ) ; } throw new CoreException ( vsprintf ( 'Object of class %s implements SafeHtmlProducerInterface' . ' but it returned an unsafe type: %s' , [ get_class ( $ string ) , TypeHound :: fetch ( $ result ) ] ) ) ; } return htmlspecialchars ( $ string , ENT_QUOTES , 'UTF-8' ) ; } | Escape the provided string . |
41,586 | public function forceWorkday ( $ next = false ) { $ weekday = $ this -> format ( 'N' ) ; if ( $ weekday == 7 ) $ this -> addDays ( 1 ) ; elseif ( $ weekday == 6 ) $ next ? $ this -> addDays ( 2 ) : $ this -> addDays ( - 1 ) ; return $ this ; } | Sets the current date to the nearest or next workday . |
41,587 | public function formatLocalized ( $ format , $ encoding = 'UTF-8' ) { $ str = strftime ( $ format , $ this -> getTimestamp ( ) ) ; if ( $ encoding == 'UTF-8' ) { $ str = utf8_encode ( $ str ) ; } return $ str ; } | Returns a string representation according to locale settings . |
41,588 | public function getLinkTypes ( ) { $ event = new Event ( 'Wasabi.Backend.MenuItems.getLinkTypes' , $ this ) ; EventManager :: instance ( ) -> dispatch ( $ event ) ; $ typeExternal = [ 'type' => 'external' ] ; $ typeCustom = [ 'type' => 'custom' ] ; $ event -> result [ __d ( 'wasabi_core' , 'General' ) ] = [ json_encode ( $ typeExternal ) => __d ( 'wasabi_core' , 'External Link' ) , json_encode ( $ typeCustom ) => __d ( 'wasabi_core' , 'Custom Controller Action' ) ] ; return $ event -> result ; } | Get available link types via an Event trigger This fetches avilable Links from all activated Plugins . |
41,589 | public function replaceArgument ( $ index , $ argument ) { if ( 0 === count ( $ this -> arguments ) ) { throw new OutOfBoundsException ( 'Cannot replace arguments if none have been configured yet.' ) ; } if ( $ index < 0 || $ index > count ( $ this -> arguments ) - 1 ) { throw new OutOfBoundsException ( sprintf ( 'The index "%d" is not in the range [0, %d].' , $ index , count ( $ this -> arguments ) - 1 ) ) ; } $ this -> arguments [ $ index ] = $ argument ; return $ this ; } | Sets a specific argument . |
41,590 | public function getLimit ( ) { if ( $ this -> max > 0 ) { return min ( $ this -> max , $ this -> limit ) ; } return $ this -> limit ; } | Gets the limit . |
41,591 | public static function Taiut1 ( $ tai1 , $ tai2 , $ dta , & $ ut11 , & $ ut12 ) { $ dtad ; $ dtad = $ dta / DAYSEC ; if ( $ tai1 > $ tai2 ) { $ ut11 = $ tai1 ; $ ut12 = $ tai2 + $ dtad ; } else { $ ut11 = $ tai1 + $ dtad ; $ ut12 = $ tai2 ; } return 0 ; } | - - - - - - - - - - i a u T a i u t 1 - - - - - - - - - - |
41,592 | public static function compare ( $ left , $ right ) { if ( $ left -> a != $ right -> a ) return $ left -> a <=> $ right -> a ; if ( $ left -> b != $ right -> b ) return $ left -> b <=> $ right -> b ; if ( $ left -> c != $ right -> c ) return $ left -> c <=> $ right -> c ; if ( $ left -> i < 0 || $ right -> i < 0 ) return 0 ; return $ left -> i <=> $ right -> i ; } | Compares to specificities |
41,593 | public static function get ( $ selector ) { $ specificity = $ selector -> hasNext ( ) ? self :: get ( $ selector -> getNext ( ) ) : new self ( ) ; if ( $ selector -> getIdentification ( ) ) $ specificity -> a ++ ; if ( $ selector -> getClasses ( ) ) $ specificity -> b += count ( $ selector -> getClasses ( ) ) ; if ( $ selector -> getAttributes ( ) ) $ specificity -> b += count ( $ selector -> getAttributes ( ) ) ; if ( $ selector -> getPseudos ( ) ) $ specificity -> b += count ( $ selector -> getPseudos ( ) ) ; if ( $ selector -> getTagName ( ) ) $ specificity -> c ++ ; return $ specificity ; } | Calculated the specificity of a selector |
41,594 | public function supports ( $ phrase , array $ arguments ) { if ( ! isset ( $ this -> forms [ $ phrase ] ) ) { return false ; } $ argumentMatch = $ this -> forms [ $ phrase ] ; if ( $ this -> validateNoArgumentsCondition ( $ arguments , $ argumentMatch ) || $ this -> validateStrictArgumentCountCondition ( $ arguments , $ argumentMatch ) ) { return false ; } return true ; } | Validates matcher condition based on specified rules |
41,595 | private function _crawlNode ( \ Twig_Node $ node ) { if ( $ node instanceof TransNode && ! $ node -> getNode ( 'body' ) instanceof \ Twig_Node_Expression_GetAttr ) { $ domain = $ node -> getNode ( 'domain' ) -> getAttribute ( 'value' ) ; $ message = $ node -> getNode ( 'body' ) -> getAttribute ( 'data' ) ; $ this -> messages -> set ( $ message , $ this -> prefix . $ message , $ domain ) ; } elseif ( $ node instanceof \ Twig_Node_Print ) { $ message = $ this -> _extractMessage ( $ node -> getNode ( 'expr' ) ) ; $ domain = $ this -> _extractDomain ( $ node -> getNode ( 'expr' ) ) ; if ( $ message !== null && $ domain !== null ) { $ this -> messages -> set ( $ message , $ this -> prefix . $ message , $ domain ) ; } } else { foreach ( $ node as $ child ) { if ( $ child != null ) { $ this -> _crawlNode ( $ child ) ; } } } } | Recursive function that extract trans message from a twig tree |
41,596 | private function _extractMessage ( \ Twig_Node $ node ) { if ( $ node -> hasNode ( 'node' ) ) { return $ this -> _extractMessage ( $ node -> getNode ( 'node' ) ) ; } if ( $ node instanceof \ Twig_Node_Expression_Constant ) { return $ node -> getAttribute ( 'value' ) ; } return null ; } | Extract a message from a \ Twig_Node_Print Return null if not a constant message |
41,597 | private function _extractDomain ( \ Twig_Node $ node ) { if ( ! $ node instanceof \ Twig_Node_Expression_Filter ) { return null ; } if ( $ node -> getNode ( 'filter' ) -> getAttribute ( 'value' ) == 'trans' ) { if ( $ node -> getNode ( 'arguments' ) -> hasNode ( 1 ) ) { return $ node -> getNode ( 'arguments' ) -> getNode ( 1 ) -> getAttribute ( 'value' ) ; } else { return $ this -> defaultDomain ; } } return $ this -> _extractDomain ( $ node -> getNode ( 'node' ) ) ; } | Extract a domain from a \ Twig_Node_Print Return null if no trans filter |
41,598 | protected function preloadEntities ( $ values ) { $ ids = array ( ) ; foreach ( $ values as $ row ) { $ id = $ row -> { $ this -> field_alias } ; if ( $ this -> view -> base_table == 'node_revision' ) { $ this -> entities [ $ id ] = node_load ( NULL , $ id ) ; } else { $ ids [ $ id ] = $ id ; } } $ base_tables = date_views_base_tables ( ) ; $ this -> entity_type = $ base_tables [ $ this -> view -> base_table ] ; if ( ! empty ( $ ids ) ) { $ this -> entities = entity_load ( $ this -> entity_type , $ ids ) ; } } | This actually was a good idea |
41,599 | public function addById ( $ id , array $ styles ) { $ this -> ids [ $ id ] = array_merge_recursive ( $ this -> getById ( $ id ) , $ styles ) ; } | Add a style by ID |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.