idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
2,100 | public function interpolate ( string $ contents ) : string { return str_replace ( '{{ key_max_length }}' , ( string ) ( $ this -> keyMaxLength ?? self :: DEFAULT_KEY_MAX_LENGTH ) , $ contents ) ; } | Replaces config values in template and returns it . |
2,101 | public function loadConfiguration ( ) : void { $ extensions = [ ] ; foreach ( $ this -> getConfig ( ) as $ name => $ extension ) { if ( is_int ( $ name ) ) { $ name = null ; } if ( is_array ( $ extension ) ) { $ extension = array_merge ( [ 'priority' => 10 , ] , $ extension ) ; if ( ! array_key_exists ( 'class' , $ ext... | Register other extensions with pleasure . |
2,102 | public function beforeCompile ( ) : void { $ builder = $ this -> getContainerBuilder ( ) ; foreach ( $ builder -> findByType ( IContainerAware :: class ) as $ service ) { $ service -> addSetup ( 'setContainer' ) ; } } | Tweak DI container |
2,103 | protected function findClasses ( string $ namespace , array $ dirs , array $ excludes = [ ] ) : array { $ loader = $ this -> createLoader ( ) ; $ loader -> addDirectory ( $ dirs ) ; $ loader -> rebuild ( ) ; $ indexed = $ loader -> getIndexedClasses ( ) ; $ classes = [ ] ; foreach ( $ indexed as $ class => $ file ) { i... | Find classes by given arguments |
2,104 | public function beforeCompile ( ) : void { $ config = $ this -> validateConfig ( $ this -> defaults ) ; $ definitions = $ config [ 'all' ] === true ? $ this -> getContainerBuilder ( ) -> getDefinitions ( ) : array_map ( [ $ this -> getContainerBuilder ( ) , 'getDefinition' ] , array_keys ( $ this -> getContainerBuilder... | Find all definitions and inject into |
2,105 | protected function registerType ( $ type , $ implements , $ name , $ class , $ instantiate = false ) { $ name = strtolower ( $ name ) ; $ refl = new \ ReflectionClass ( $ class ) ; if ( ! $ refl -> implementsInterface ( $ implements ) ) { $ message = sprintf ( 'Class must implement %s' , $ implements ) ; throw new \ In... | Register a type with the factory by name |
2,106 | protected function loadFiles ( $ directory , $ namespace , $ callback ) { foreach ( new \ DirectoryIterator ( $ directory ) as $ file ) { $ filename = $ file -> getBasename ( ) ; if ( $ file -> isFile ( ) && substr ( $ filename , - 4 ) == '.php' ) { $ name = substr ( $ filename , 0 , - 4 ) ; $ class = $ namespace . $ n... | Load a set of classes from a directory into the factory |
2,107 | public static function createFromServerConfiguration ( ) { if ( extension_loaded ( 'gmp' ) ) { return new \ SecurityLib \ BigMath \ GMP ( ) ; } elseif ( extension_loaded ( 'bcmath' ) ) { return new \ SecurityLib \ BigMath \ BCMath ( ) ; } else { return new \ SecurityLib \ BigMath \ PHPMath ( ) ; } } | Get an instance of the big math class |
2,108 | public function add ( $ left , $ right ) { if ( empty ( $ left ) ) { return $ right ; } elseif ( empty ( $ right ) ) { return $ left ; } $ negative = '' ; if ( $ left [ 0 ] == '-' && $ right [ 0 ] == '-' ) { $ negative = '-' ; $ left = substr ( $ left , 1 ) ; $ right = substr ( $ right , 1 ) ; } elseif ( $ left [ 0 ] =... | Add two numbers together |
2,109 | public function subtract ( $ left , $ right ) { if ( empty ( $ left ) ) { return $ right ; } elseif ( empty ( $ right ) ) { return $ left ; } elseif ( $ right [ 0 ] == '-' ) { return $ this -> add ( $ left , substr ( $ right , 1 ) ) ; } elseif ( $ left [ 0 ] == '-' ) { return '-' . $ this -> add ( ltrim ( $ left , '-' ... | Subtract two numbers |
2,110 | protected function addBinary ( $ left , $ right ) { $ len = max ( strlen ( $ left ) , strlen ( $ right ) ) ; $ left = str_pad ( $ left , $ len , chr ( 0 ) , STR_PAD_LEFT ) ; $ right = str_pad ( $ right , $ len , chr ( 0 ) , STR_PAD_LEFT ) ; $ result = '' ; $ carry = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ sum = ... | Add two binary strings together |
2,111 | protected function subtractBinary ( $ left , $ right ) { $ len = max ( strlen ( $ left ) , strlen ( $ right ) ) ; $ left = str_pad ( $ left , $ len , chr ( 0 ) , STR_PAD_LEFT ) ; $ right = str_pad ( $ right , $ len , chr ( 0 ) , STR_PAD_LEFT ) ; $ right = $ this -> compliment ( $ right ) ; $ result = $ this -> addBinar... | Subtract two binary strings using 256 s compliment |
2,112 | protected function compliment ( $ string ) { $ result = '' ; $ len = strlen ( $ string ) ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ result .= chr ( 255 - ord ( $ string [ $ i ] ) ) ; } return $ result ; } | Take the 256 base compliment |
2,113 | public static function convertFromBinary ( $ string , $ characters ) { if ( $ string === '' || empty ( $ characters ) ) { return '' ; } $ string = str_split ( $ string ) ; $ callback = function ( $ str ) { return ord ( $ str ) ; } ; $ string = array_map ( $ callback , $ string ) ; $ converted = static :: baseConvert ( ... | Convert from a raw binary string to a string of characters |
2,114 | public static function convertToBinary ( $ string , $ characters ) { if ( empty ( $ string ) || empty ( $ characters ) ) { return '' ; } $ string = str_split ( $ string ) ; $ callback = function ( $ str ) use ( $ characters ) { return strpos ( $ characters , $ str ) ; } ; $ string = array_map ( $ callback , $ string ) ... | Convert to a raw binary string from a string of characters |
2,115 | public static function baseConvert ( array $ source , $ srcBase , $ dstBase ) { if ( $ dstBase < 2 ) { $ message = sprintf ( 'Invalid Destination Base: %d' , $ dstBase ) ; throw new \ InvalidArgumentException ( $ message ) ; } $ result = array ( ) ; $ count = count ( $ source ) ; while ( $ count ) { $ itMax = $ count ;... | Convert an array of input blocks to another numeric base |
2,116 | public function compare ( Enum $ arg ) { if ( $ this -> value == $ arg -> value ) { return 0 ; } elseif ( $ this -> value > $ arg -> value ) { return - 1 ; } else { return 1 ; } } | Compare two enums using numeric comparison |
2,117 | public function config ( array $ config ) : void { if ( $ this -> routeCounter > 0 ) { throw new \ LogicException ( 'Routing has been added, and configuration is not allowed!' ) ; } $ props = [ 'name' => 1 , 'chains' => 1 , 'ignoreLastSlash' => 1 , 'tmpCacheNumber' => 1 , 'handleMethodNotAllowed' => 1 , 'autoRoute' => ... | config the router |
2,118 | protected function appendGroupInfo ( Route $ route ) : void { $ path = $ bak = $ route -> getPath ( ) ; $ path = \ strpos ( $ path , '/' ) === 0 ? $ path : '/' . $ path ; $ path = $ this -> currentGroupPrefix . $ path ; if ( $ path !== '/' && $ this -> ignoreLastSlash ) { $ path = \ rtrim ( $ path , '/' ) ; } if ( $ ba... | prepare for add |
2,119 | protected function matchDynamicRoute ( string $ path , string $ method ) : array { $ first = \ strstr ( \ ltrim ( $ path , '/' ) , '/' , true ) ; $ fKey = $ first ? $ method . ' ' . $ first : '' ; if ( $ fKey && isset ( $ this -> regularRoutes [ $ fKey ] ) ) { foreach ( $ this -> regularRoutes [ $ fKey ] as $ route ) {... | is a dynamic route match by regexp |
2,120 | public function getRoutes ( ) : array { $ routes = [ ] ; $ this -> each ( function ( Route $ route ) use ( & $ routes ) { $ routes [ ] = $ route ; } ) ; return $ routes ; } | get all routes |
2,121 | public function get ( $ condition = null ) : Router { if ( ! $ condition ) { return $ this -> getDefault ( ) ; } if ( \ is_string ( $ condition ) ) { return $ this -> getByName ( $ condition ) ; } $ useName = self :: DEFAULT_ROUTER ; foreach ( $ this -> conditions as $ name => $ cond ) { if ( $ this -> compareArray ( $... | get router by condition |
2,122 | public function loadRoutesCache ( ) : bool { if ( ! $ this -> isCacheEnable ( ) ) { return false ; } $ file = $ this -> cacheFile ; if ( ! $ file || ! \ file_exists ( $ file ) ) { return false ; } $ map = require $ file ; $ this -> routeCounter = 0 ; $ staticRoutes = $ regularRoutes = $ vagueRoutes = [ ] ; foreach ( $ ... | load route caches from the cache file |
2,123 | protected function dumpRoutesCache ( ) : int { if ( ! $ file = $ this -> cacheFile ) { return 0 ; } if ( $ this -> isCacheEnable ( ) && \ file_exists ( $ file ) ) { return 1 ; } $ date = \ date ( 'Y-m-d H:i:s' ) ; $ class = static :: class ; $ count = $ this -> count ( ) ; $ staticRoutes = \ var_export ( $ this -> stat... | dump routes to cache file |
2,124 | public function namedTo ( string $ name , Router $ router , bool $ register = false ) : void { if ( $ name = $ this -> setName ( $ name ) -> name ) { if ( $ register ) { $ router -> addRoute ( $ this ) ; } else { $ router -> nameRoute ( $ name , $ this ) ; } } } | name the route and bind name to router . |
2,125 | public function parseParam ( array $ bindParams = [ ] ) : string { $ argPos = \ strpos ( $ this -> path , '{' ) ; $ optPos = \ strpos ( $ this -> path , '[' ) ; return $ this -> quickParseParams ( $ argPos , $ optPos , $ bindParams ) ; } | parse route path string . fetch route params |
2,126 | public function toUri ( array $ pathVars = [ ] ) : string { if ( $ pathVars ) { return \ strtr ( $ this -> path , $ pathVars ) ; } return $ this -> path ; } | build uri string . |
2,127 | public function toArray ( ) : array { return [ 'name' => $ this -> name , 'path' => $ this -> path , 'method' => $ this -> method , 'handler' => $ this -> handler , 'binds' => $ this -> bindVars , 'params' => $ this -> params , 'options' => $ this -> options , 'pathVars' => $ this -> pathVars , 'pathStart' => $ this ->... | get all info data |
2,128 | public static function isStaticRoute ( string $ route ) : bool { return \ strpos ( $ route , '{' ) === false && \ strpos ( $ route , '[' ) === false ; } | is Static Route |
2,129 | public static function formatPath ( string $ path , bool $ ignoreLastSlash = true ) : string { if ( $ path === '/' ) { return '/' ; } if ( false !== \ strpos ( $ path , '//' ) ) { $ path = \ preg_replace ( '#\/\/+#' , '/' , $ path ) ; } if ( \ strpos ( $ path , '/' ) !== 0 ) { $ path = '/' . $ path ; } $ path = \ rawur... | format URI path |
2,130 | public function dispatchUri ( string $ path = null , string $ method = null ) { $ path = ( string ) ( $ path ? : $ _SERVER [ 'REQUEST_URI' ] ) ; if ( \ strpos ( $ path , '?' ) ) { $ path = \ parse_url ( $ path , \ PHP_URL_PATH ) ; } if ( $ path === self :: FAV_ICON && $ this -> options [ 'filterFavicon' ] ) { return nu... | Runs the callback for the given path and method . |
2,131 | protected function callHandler ( string $ path , string $ method , $ handler , array $ args = [ ] ) { if ( \ is_object ( $ handler ) ) { return $ handler ( $ args ) ; } if ( \ is_array ( $ handler ) ) { $ segments = $ handler ; } elseif ( \ is_string ( $ handler ) ) { if ( \ strpos ( $ handler , '@' ) === false && \ fu... | execute the matched Route Handler |
2,132 | public function on ( string $ event , $ handler ) { if ( self :: isSupportedEvent ( $ event ) ) { $ this -> options [ $ event ] = $ handler ; } } | Defines callback on happen event |
2,133 | public function setRepositoryReference ( RepositoryReference $ repositoryReference ) { parent :: setRepositoryReference ( $ repositoryReference ) ; $ this -> repository -> setRepositoryReference ( $ repositoryReference ) ; } | Set repository reference . |
2,134 | private function applyTransformersToResult ( Result $ result ) : Result { return empty ( $ result -> getSubresults ( ) ) ? Result :: create ( $ result -> getQueryUUID ( ) , $ result -> getTotalItems ( ) , $ result -> getTotalHits ( ) , $ result -> getAggregations ( ) , $ result -> getSuggests ( ) , $ this -> transforme... | Apply transformers on Result . |
2,135 | public function addObject ( $ object ) { $ item = $ this -> transformer -> toItem ( $ object ) ; if ( $ item instanceof Item ) { $ this -> addItem ( $ item ) ; } } | Generate item document by a simple object . |
2,136 | public static function createInvalidTokenMaxHitsPerQuery ( string $ tokenReference , int $ maxHitsPerQuery ) : self { return new self ( sprintf ( 'Token %s not valid. Max %d hits allowed' , $ tokenReference , $ maxHitsPerQuery ) ) ; } | Throw an invalid key exception . |
2,137 | public static function createLocated ( ItemUUID $ uuid , Coordinate $ coordinate , array $ metadata = [ ] , array $ indexedMetadata = [ ] , array $ searchableMetadata = [ ] , array $ exactMatchingMetadata = [ ] , array $ suggest = [ ] ) { return new self ( $ uuid , $ coordinate , $ metadata , $ indexedMetadata , $ sear... | Create located . |
2,138 | public function getHighlight ( string $ fieldName ) : ? string { return isset ( $ this -> highlights [ $ fieldName ] ) ? ( ( string ) $ this -> highlights [ $ fieldName ] ) : null ; } | Get Highlights . |
2,139 | public function addRepository ( string $ appName , string $ indexName , TransformableRepository $ repository ) { $ this -> repositories [ $ appName ] [ $ indexName ] = $ repository ; } | Add repository . |
2,140 | public static function createFieldBoosting ( string $ field , float $ factor = self :: DEFAULT_FACTOR , float $ missing = self :: DEFAULT_MISSING , string $ modifier = self :: MODIFIER_NONE , float $ weight = self :: DEFAULT_WEIGHT , Filter $ filter = null , string $ scoreMode = self :: SCORE_MODE_AVG ) : ScoreStrategy... | Create default field scoring . |
2,141 | private static function fixFilterFieldPath ( ? Filter $ filter ) : ? Filter { if ( is_null ( $ filter ) ) { return $ filter ; } $ filterAsArray = $ filter -> toArray ( ) ; $ filterAsArray [ 'field' ] = Item :: getPathByField ( $ filterAsArray [ 'field' ] ) ; return Filter :: createFromArray ( $ filterAsArray ) ; } | Fix filter path . |
2,142 | public static function createByActiveElements ( string $ name , int $ n , array $ activeElements ) : ? self { $ values = Metadata :: fromMetadata ( $ name ) ; if ( is_null ( $ values ) ) { return null ; } return new self ( $ values , in_array ( $ values [ 'id' ] , $ activeElements ) , $ n ) ; } | Create or return null if the used element is not valid . |
2,143 | public static function create ( AppUUID $ appUUID = null , IndexUUID $ indexUUID = null ) : RepositoryReference { return new self ( $ appUUID , $ indexUUID ) ; } | Create by appUUID and indexUUID . |
2,144 | public static function createFromComposed ( string $ composed ) : RepositoryReference { list ( $ appUUIDComposed , $ indexUUIDComposed ) = explode ( '_' , $ composed , 2 ) ; return RepositoryReference :: create ( AppUUID :: createById ( $ appUUIDComposed ) , IndexUUID :: createById ( $ indexUUIDComposed ) ) ; } | Create from composed . |
2,145 | private function parseFieldsFromHeaderAndItemAsArray ( array $ header , array $ item ) { return [ 'metadata' => $ this -> parseSectionFromHeaderAndItemAsArray ( $ header , 'metadata' , $ item ) , 'indexed_metadata' => $ this -> parseSectionFromHeaderAndItemAsArray ( $ header , 'indexed_metadata' , $ item ) , 'searchabl... | Parse fields from item having header . |
2,146 | private function parseSectionFromHeaderAndItemAsArray ( array $ header , string $ section , array $ item ) { return array_intersect_key ( $ item , array_flip ( $ header [ $ section ] ?? [ ] ) ) ; } | Parse section fields from item having header . |
2,147 | public static function create ( ? string $ queryUUID , int $ totalItems , int $ totalHits , ? Aggregations $ aggregations , array $ suggests , array $ items ) : self { $ result = new self ( $ queryUUID , $ totalItems , $ totalHits ) ; $ result -> aggregations = $ aggregations ; $ result -> suggests = $ suggests ; $ res... | Create by . |
2,148 | public function getItemsGroupedByTypes ( ) : array { if ( is_array ( $ this -> itemsGroupedByTypeCache ) ) { return $ this -> itemsGroupedByTypeCache ; } $ items = $ this -> getItems ( ) ; $ itemsGroupedByType = [ ] ; foreach ( $ items as $ item ) { if ( ! isset ( $ itemsGroupedByType [ $ item -> getType ( ) ] ) ) { $ ... | Get items grouped by type . |
2,149 | public function getItemsByTypes ( array $ types ) : array { return array_filter ( $ this -> getItems ( ) , function ( Item $ item ) use ( $ types ) { return in_array ( $ item -> getType ( ) , $ types ) ; } ) ; } | Get Items by a certain types . |
2,150 | public function getFirstItem ( ) { $ results = $ this -> getItems ( ) ; if ( empty ( $ results ) ) { return null ; } $ firstItem = reset ( $ results ) ; return $ firstItem ; } | Get first result . |
2,151 | public function getAggregation ( string $ name ) : ? Aggregation { if ( is_null ( $ this -> aggregations ) ) { return null ; } return $ this -> aggregations -> getAggregation ( $ name ) ; } | Get aggregation . |
2,152 | public function hasNotEmptyAggregation ( string $ name ) : bool { if ( is_null ( $ this -> aggregations ) ) { return false ; } return $ this -> aggregations -> hasNotEmptyAggregation ( $ name ) ; } | Has not empty aggregation . |
2,153 | public function readSynonymsFromFile ( string $ filepath ) : array { if ( ! is_file ( $ filepath ) || ! is_readable ( $ filepath ) ) { throw SynonymsException :: synonymsFileNotFound ( $ filepath ) ; } $ data = file_get_contents ( $ filepath ) ; if ( ! is_string ( $ data ) ) { throw SynonymsException :: synonymsMalform... | Read synonyms from file . |
2,154 | public function readSynonymsFromCommaSeparatedArray ( array $ synonymsAsCommaSeparatedArray ) : array { return array_filter ( array_map ( function ( string $ line ) { if ( empty ( $ line ) ) { return false ; } $ words = explode ( ',' , $ line ) ; if ( count ( $ words ) <= 1 ) { return false ; } return Synonym :: create... | Read synonyms from comma separated array . |
2,155 | public function importIndex ( Repository $ repository , string $ data , string $ format ) { $ items = $ this -> exporterCollection -> getExporterByName ( $ format ) -> formatToItems ( $ data ) ; $ repository -> addItems ( $ items ) ; $ repository -> flush ( ) ; } | Import index . |
2,156 | public function exportIndex ( Repository $ repository , string $ format ) : string { $ allItems = [ ] ; $ iteration = 0 ; while ( true ) { $ items = $ repository -> query ( Query :: create ( '' , $ iteration , 10000 ) ) -> getItems ( ) ; if ( empty ( $ items ) ) { break ; } $ allItems = array_merge ( $ allItems , $ ite... | Export index . |
2,157 | public static function createLocated ( Coordinate $ coordinate , string $ queryText , int $ page = self :: DEFAULT_PAGE , int $ size = self :: DEFAULT_SIZE ) { $ query = self :: create ( $ queryText , $ page , $ size ) ; $ query -> coordinate = $ coordinate ; return $ query ; } | Create located Query . |
2,158 | public static function create ( string $ queryText , int $ page = self :: DEFAULT_PAGE , int $ size = self :: DEFAULT_SIZE ) : self { $ page = ( int ) ( max ( 1 , $ page ) ) ; $ query = new self ( $ queryText ) ; $ query -> from = ( $ page - 1 ) * $ size ; $ query -> size = $ size ; $ query -> page = $ page ; return $ ... | Create new . |
2,159 | public static function createByUUIDs ( array $ uuids ) : self { $ ids = array_map ( function ( ItemUUID $ uuid ) { return $ uuid -> composeUUID ( ) ; } , $ uuids ) ; $ query = self :: create ( '' , self :: DEFAULT_PAGE , count ( $ uuids ) ) -> disableAggregations ( ) -> disableSuggestions ( ) ; $ query -> filters [ '_i... | Create by references . |
2,160 | public function filterUniverseByTypes ( array $ values ) : self { $ fieldPath = Item :: getPathByField ( 'type' ) ; if ( ! empty ( $ values ) ) { $ this -> universeFilters [ 'type' ] = Filter :: create ( $ fieldPath , $ values , Filter :: AT_LEAST_ONE , Filter :: TYPE_FIELD ) ; } else { unset ( $ this -> universeFilter... | Filter universe by types . |
2,161 | public function filterUniverseBy ( string $ field , array $ values , int $ applicationType = Filter :: AT_LEAST_ONE ) : self { $ fieldPath = Item :: getPathByField ( $ field ) ; if ( ! empty ( $ values ) ) { $ this -> universeFilters [ $ field ] = Filter :: create ( $ fieldPath , $ values , $ applicationType , Filter :... | Filter universe by . |
2,162 | public function filterBy ( string $ filterName , string $ field , array $ values , int $ applicationType = Filter :: AT_LEAST_ONE , bool $ aggregate = true , array $ aggregationSort = Aggregation :: SORT_BY_COUNT_DESC ) : self { $ fieldPath = Item :: getPathByField ( $ field ) ; if ( ! empty ( $ values ) ) { $ this -> ... | Filter by . |
2,163 | public function filterUniverseByLocation ( LocationRange $ locationRange ) : self { $ this -> universeFilters [ 'coordinate' ] = Filter :: create ( 'coordinate' , $ locationRange -> toArray ( ) , Filter :: AT_LEAST_ONE , Filter :: TYPE_GEO ) ; return $ this ; } | Filter universe by location . |
2,164 | public function sortBy ( SortBy $ sortBy ) : self { if ( $ sortBy -> isSortedByGeoDistance ( ) ) { if ( ! $ this -> coordinate instanceof Coordinate ) { throw InvalidFormatException :: querySortedByDistanceWithoutCoordinate ( ) ; } $ sortBy -> setCoordinate ( $ this -> coordinate ) ; } $ this -> sortBy = $ sortBy ; ret... | Sort by . |
2,165 | public function aggregateBy ( string $ filterName , string $ field , int $ applicationType , array $ aggregationSort = Aggregation :: SORT_BY_COUNT_DESC , int $ limit = Aggregation :: NO_LIMIT ) : self { $ this -> aggregations [ $ filterName ] = Aggregation :: create ( $ filterName , Item :: getPathByField ( $ field ) ... | Add Families aggregation . |
2,166 | public function getQueryText ( ) : string { return ( isset ( $ this -> filters [ '_query' ] ) && $ this -> filters [ '_query' ] instanceof Filter ) ? $ this -> filters [ '_query' ] -> getValues ( ) [ 0 ] : '' ; } | Return Querytext . |
2,167 | public function excludeUUIDs ( array $ uuids ) : self { $ this -> filters [ 'excluded_ids' ] = Filter :: create ( '_id' , array_map ( function ( ItemUUID $ uuid ) { return $ uuid -> composeUUID ( ) ; } , $ uuids ) , Filter :: EXCLUDE , Filter :: TYPE_FIELD ) ; return $ this ; } | Exclude reference . |
2,168 | public function setMetadataValue ( string $ name , $ value ) : self { $ this -> metadata [ $ name ] = $ value ; return $ this ; } | Set metadata . |
2,169 | public function addSubQuery ( string $ name , Query $ query ) : self { $ this -> subqueries [ $ name ] = $ query ; return $ this ; } | Add subquery . |
2,170 | protected static function throwTransportableExceptionIfNeeded ( array $ response , string $ url = '' ) { if ( ! isset ( $ response [ 'code' ] ) || 0 === $ response [ 'code' ] ) { throw ConnectionException :: buildConnectExceptionByUrl ( $ url ) ; } switch ( $ response [ 'code' ] ) { case ResourceNotAvailableException :... | Transform transportable http errors to exceptions . |
2,171 | public function fromItems ( array $ items ) : array { $ objects = [ ] ; foreach ( $ items as $ item ) { $ objects [ ] = $ this -> fromItem ( $ item ) ; } return $ objects ; } | Transform a set of items into a set of objects . |
2,172 | public function fromItem ( Item $ item ) { foreach ( $ this -> readTransformers as $ readTransformer ) { if ( $ readTransformer -> isValidItem ( $ item ) ) { return $ readTransformer -> fromItem ( $ item ) ; } } return $ item ; } | Transform an item into an object . |
2,173 | public function toItems ( array $ objects ) : array { $ items = [ ] ; foreach ( $ objects as $ object ) { $ item = $ this -> toItem ( $ object ) ; if ( $ item instanceof Item ) { $ items [ ] = $ item ; } } return $ items ; } | Transform a set of objects into a set of items . |
2,174 | public function toItem ( $ object ) : ? Item { foreach ( $ this -> writeTransformers as $ writeTransformer ) { if ( $ writeTransformer -> isValidObject ( $ object ) ) { $ item = $ writeTransformer -> toItem ( $ object ) ; $ this -> eventDispatcher -> dispatch ( 'apisearch.item_transformed' , new ItemTransformed ( $ ite... | Transform an object into an item . |
2,175 | public function toItemUUIDs ( array $ objects ) : array { $ itemUUIDs = [ ] ; foreach ( $ objects as $ object ) { $ itemUUID = $ this -> toItemUUID ( $ object ) ; if ( $ itemUUID instanceof ItemUUID ) { $ itemUUIDs [ ] = $ itemUUID ; } } return $ itemUUIDs ; } | Transform a set of objects into a set of itemUUIDs . |
2,176 | public function toItemUUID ( $ object ) : ? ItemUUID { foreach ( $ this -> writeTransformers as $ writeTransformer ) { if ( $ writeTransformer -> isValidObject ( $ object ) ) { return $ writeTransformer -> toItemUUID ( $ object ) ; } } return null ; } | Transform an object into an itemUUID or return NULL if the object is not transformable . |
2,177 | public static function byFieldsValues ( array $ shortSortByElements ) : SortBy { $ sortBy = self :: create ( ) ; foreach ( $ shortSortByElements as $ field => $ order ) { $ sortBy -> byFieldValue ( $ field , $ order ) ; } return $ sortBy ; } | Create sort by with passed simple fields and values . |
2,178 | public function byValue ( array $ value ) : SortBy { if ( self :: SCORE !== $ value && self :: RANDOM !== $ value ) { $ value [ 'type' ] = $ value [ 'type' ] ?? self :: TYPE_FIELD ; } $ this -> sortsBy [ ] = $ value ; return $ this ; } | Sort by value . |
2,179 | public function byFieldValue ( string $ field , string $ order ) : SortBy { $ this -> sortsBy [ ] = [ 'type' => self :: TYPE_FIELD , 'field' => Item :: getPathByField ( $ field ) , 'order' => $ order , ] ; return $ this ; } | Sort by field . |
2,180 | public function byFunction ( string $ function , string $ order ) : SortBy { $ this -> sortsBy [ ] = [ 'type' => self :: TYPE_FUNCTION , 'function' => $ function , 'order' => $ order , ] ; return $ this ; } | Sort by function . |
2,181 | public function isSortedByGeoDistance ( ) : bool { foreach ( $ this -> sortsBy as $ sortBy ) { if ( self :: TYPE_DISTANCE === $ sortBy [ 'type' ] ) { return true ; } } return false ; } | Is sorted by geo distance . |
2,182 | public function setCoordinate ( Coordinate $ coordinate ) { $ this -> sortsBy = array_map ( function ( array $ sortBy ) use ( $ coordinate ) { if ( self :: TYPE_DISTANCE === $ sortBy [ 'type' ] ) { $ sortBy [ 'coordinate' ] = $ coordinate ; } return $ sortBy ; } , $ this -> sortsBy ) ; return $ this ; } | Set coordinate . |
2,183 | public function hasRandomSort ( ) { foreach ( $ this -> sortsBy as $ sortBy ) { if ( self :: TYPE_RANDOM === $ sortBy [ 'type' ] ) { return true ; } } return false ; } | Has random sort . |
2,184 | public function buildRequestParts ( string $ url , array $ query = [ ] , array $ body = [ ] , array $ server = [ ] ) : RequestParts { $ url = trim ( $ url , '/' ) ; $ url = trim ( "{$this->version}/$url" , '/' ) ; $ url = $ this -> buildUrlParams ( $ url , $ query ) ; return new RequestParts ( $ url , [ 'json' => $ bod... | Get some parameters and build a RequestParts instance . |
2,185 | private function buildUrlParams ( string $ url , array $ params ) { array_walk ( $ params , function ( & $ value , $ key ) { $ value = "$key=$value" ; } ) ; return $ url . '?' . implode ( '&' , $ params ) ; } | Build url params . |
2,186 | public static function createForMissingDependency ( string $ format , string $ missingClass , string $ package ) : self { return new self ( sprintf ( 'Exporter %s not available. Missing class %s. To resolve it, add %d in your composer' , $ format , $ missingClass , $ package ) ) ; } | Create exporter not available because of missing dependency . |
2,187 | public function guessFilterValue ( Result $ result , Aggregation $ aggregation , Counter $ counter ) : string { return $ counter -> isUsed ( ) ? $ this -> removeFilterValue ( $ result , $ aggregation -> getName ( ) , $ counter -> getId ( ) ) : $ this -> addFilterValue ( $ result , $ aggregation -> getName ( ) , $ count... | Guess filter value . |
2,188 | public function addFilterValue ( Result $ result , string $ filterName , string $ value ) : string { if ( isset ( $ this -> routesCache [ spl_object_hash ( $ result ) ] [ $ filterName ] ) ) { return str_replace ( [ '{id}' , '{slug}' ] , $ result -> getAggregation ( $ filterName ) -> getCounter ( $ value ) -> getValues ... | Add filter into query . |
2,189 | public function removeFilterValue ( Result $ result , string $ filterName , string $ value = null ) : string { $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; if ( is_null ( $ value ) || ! isset ( $ urlParameters [ $ filterName ] ) ) { unset ( $ urlParameters [ $ filterName ] ) ; } elseif ( false ... | Remove filter from query . |
2,190 | public function removePriceRangeFilter ( Result $ result ) : string { $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; unset ( $ urlParameters [ 'price' ] ) ; return $ this -> createUrlByUrlParameters ( $ result , $ urlParameters ) [ 'route' ] ; } | Change price range . |
2,191 | public function getCurrent ( Result $ result , bool $ addQuersyStringPlaceholder = false ) : ? string { $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; if ( $ addQuersyStringPlaceholder ) { $ urlParameters [ 'q' ] = '{{q}}' ; } return $ this -> createUrlByUrlParameters ( $ result , $ urlParameters... | Get current . |
2,192 | public function addPage ( Result $ result , int $ page ) : string { $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; $ urlParameters [ 'page' ] = $ page ; return $ this -> createUrlByUrlParameters ( $ result , $ urlParameters ) [ 'route' ] ; } | Set pagination . |
2,193 | public function addPrevPage ( Result $ result ) : ? string { $ query = $ result -> getQuery ( ) ; $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; $ page = $ query -> getPage ( ) ; $ prevPage = $ page - 1 ; if ( $ prevPage < 1 ) { return null ; } $ urlParameters [ 'page' ] = $ prevPage ; return $ t... | Add previous page . |
2,194 | public function addNextPage ( Result $ result ) : ? string { $ query = $ result -> getQuery ( ) ; $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; $ page = $ query -> getPage ( ) ; $ nextPage = $ page + 1 ; if ( ( ( $ nextPage - 1 ) * $ query -> getSize ( ) ) > $ result -> getTotalHits ( ) ) { retu... | Add next page . |
2,195 | public function addSortBy ( Result $ result , string $ field , string $ mode ) : ? string { $ urlParameters = $ this -> generateQueryUrlParameters ( $ result ) ; if ( isset ( $ urlParameters [ 'sort_by' ] [ $ field ] ) && $ urlParameters [ 'sort_by' ] [ $ field ] == $ mode ) { return null ; } if ( ! isset ( $ urlParame... | Add sort by . Return null if doesn t change . |
2,196 | private function generateQueryUrlParameters ( Result $ result , string $ filterName = null ) : array { $ query = $ result -> getQuery ( ) ; $ queryFilters = $ query -> getFilters ( ) ; $ urlParameters = [ ] ; foreach ( $ queryFilters as $ currentFilterName => $ filter ) { $ urlParameters [ $ currentFilterName ] = ( ! i... | Query to url parameters . |
2,197 | private function createUrlByUrlParameters ( Result $ result , array $ urlParameters ) : array { foreach ( $ this -> routesDictionary as $ field => $ route ) { if ( ! isset ( $ urlParameters [ $ field ] ) || ( is_array ( $ urlParameters [ $ field ] ) && 1 !== count ( $ urlParameters [ $ field ] ) ) ) { continue ; } $ va... | Generate url by query parameters . |
2,198 | public function addChange ( string $ field , $ value , int $ type = self :: TYPE_VALUE ) : self { $ this -> changes [ ] = [ 'field' => $ field , 'type' => $ type , 'value' => $ value , ] ; return $ this ; } | Add change . |
2,199 | public function deleteElementFromList ( string $ field , string $ condition ) : self { $ this -> changes [ ] = [ 'field' => $ field , 'type' => self :: TYPE_ARRAY_ELEMENT_DELETE , 'condition' => $ condition , ] ; return $ this ; } | Delete change from a list . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.