idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
44,400
protected function model ( ) : Model { if ( ! $ this -> model ) { $ this -> model = $ this -> option ( 'model' ) ?? Config :: get ( 'ldap_auth.model' ) ? : $ this -> determineModel ( ) ; } return new $ this -> model ; }
Set and create a new instance of the eloquent model to use .
44,401
protected function determineModel ( ) { $ providers = array_where ( Config :: get ( 'auth.providers' ) , function ( $ value , $ key ) { return $ value [ 'driver' ] == 'ldap' && array_key_exists ( 'model' , $ value ) ; } ) ; if ( $ ldap = reset ( $ providers ) ) { return $ ldap [ 'model' ] ; } throw new UnexpectedValueE...
Retrieves the model by checking the configured LDAP authentication providers .
44,402
protected function addProviders ( Adldap $ adldap , array $ connections = [ ] ) { foreach ( $ connections as $ name => $ config ) { $ provider = $ this -> newProvider ( $ config [ 'settings' ] , new $ config [ 'connection' ] ) ; if ( $ this -> shouldAutoConnect ( $ config ) ) { try { $ provider -> connect ( ) ; } catch...
Adds providers to the specified Adldap instance .
44,403
public function addResolver ( $ filter , ResolverInterface $ resolver ) { $ this -> resolvers [ $ filter ] = $ resolver ; if ( $ resolver instanceof CacheManagerAwareInterface ) { $ resolver -> setCacheManager ( $ this ) ; } }
Adds a resolver to handle cached images for the given filter .
44,404
public function getBrowserPath ( $ path , $ filter , array $ runtimeConfig = [ ] , $ resolver = null ) { if ( ! empty ( $ runtimeConfig ) ) { $ rcPath = $ this -> getRuntimePath ( $ path , $ runtimeConfig ) ; return $ this -> isStored ( $ rcPath , $ filter , $ resolver ) ? $ this -> resolve ( $ rcPath , $ filter , $ re...
Gets filtered path for rendering in the browser . It could be the cached one or an url of filter action .
44,405
public function isStored ( $ path , $ filter , $ resolver = null ) { return $ this -> getResolver ( $ filter , $ resolver ) -> isStored ( $ path , $ filter ) ; }
Checks whether the path is already stored within the respective Resolver .
44,406
protected function getResolver ( $ filter , $ resolver ) { if ( ! $ resolver ) { $ config = $ this -> filterConfig -> get ( $ filter ) ; $ resolverName = empty ( $ config [ 'cache' ] ) ? $ this -> defaultResolver : $ config [ 'cache' ] ; } else { $ resolverName = $ resolver ; } if ( ! isset ( $ this -> resolvers [ $ re...
Gets a resolver for the given filter .
44,407
protected function getObjectPath ( $ path , $ filter ) { $ path = $ this -> cachePrefix ? sprintf ( '%s/%s/%s' , $ this -> cachePrefix , $ filter , $ path ) : sprintf ( '%s/%s' , $ filter , $ path ) ; return str_replace ( '//' , '/' , $ path ) ; }
Returns the object path within the bucket .
44,408
public function isStored ( $ path , $ filter ) { return $ this -> flysystem -> has ( $ this -> getFilePath ( $ path , $ filter ) ) ; }
Checks whether the given path is stored within this Resolver .
44,409
public function store ( BinaryInterface $ binary , $ path , $ filter ) { $ this -> flysystem -> put ( $ this -> getFilePath ( $ path , $ filter ) , $ binary -> getContent ( ) , [ 'visibility' => $ this -> visibility ] ) ; }
Stores the content of the given binary .
44,410
public function getLoader ( $ filter ) { $ config = $ this -> filterConfig -> get ( $ filter ) ; $ loaderName = empty ( $ config [ 'data_loader' ] ) ? $ this -> defaultLoader : $ config [ 'data_loader' ] ; if ( ! isset ( $ this -> loaders [ $ loaderName ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Could no...
Returns a loader previously attached to the given filter .
44,411
public function find ( $ filter , $ path ) { $ loader = $ this -> getLoader ( $ filter ) ; $ binary = $ loader -> find ( $ path ) ; if ( ! $ binary instanceof BinaryInterface ) { $ mimeType = $ this -> mimeTypeGuesser -> guess ( $ binary ) ; $ binary = new Binary ( $ binary , $ mimeType , $ this -> extensionGuesser -> ...
Retrieves an image with the given filter applied .
44,412
public function getDefaultImageUrl ( $ filter ) { $ config = $ this -> filterConfig -> get ( $ filter ) ; $ defaultImage = null ; if ( false === empty ( $ config [ 'default_image' ] ) ) { $ defaultImage = $ config [ 'default_image' ] ; } elseif ( ! empty ( $ this -> globalDefaultImage ) ) { $ defaultImage = $ this -> g...
Get default image url with the given filter applied .
44,413
public function get ( $ filter ) { if ( false === \ array_key_exists ( $ filter , $ this -> filters ) ) { throw new NonExistingFilterException ( sprintf ( 'Could not find configuration for a filter: %s' , $ filter ) ) ; } return $ this -> filters [ $ filter ] ; }
Gets a previously configured filter .
44,414
public function filterAction ( Request $ request , $ path , $ filter ) { $ path = PathHelper :: urlPathToFilePath ( $ path ) ; $ resolver = $ request -> get ( 'resolver' ) ; try { return new RedirectResponse ( $ this -> filterService -> getUrlOfFilteredImage ( $ path , $ filter , $ resolver ) , 301 ) ; } catch ( NotLoa...
This action applies a given filter to a given image saves the image and redirects the browser to the stored image .
44,415
public function filterRuntimeAction ( Request $ request , $ hash , $ path , $ filter ) { $ resolver = $ request -> get ( 'resolver' ) ; $ runtimeConfig = $ request -> query -> get ( 'filters' , [ ] ) ; if ( ! \ is_array ( $ runtimeConfig ) ) { throw new NotFoundHttpException ( sprintf ( 'Filters must be an array. Value...
This action applies a given filter - merged with additional runtime filters - to a given image saves the image and redirects the browser to the stored image .
44,416
public function generateCacheKey ( $ path , $ filter ) { return implode ( '.' , [ $ this -> sanitizeCacheKeyPart ( $ this -> options [ 'global_prefix' ] ) , $ this -> sanitizeCacheKeyPart ( $ this -> options [ 'prefix' ] ) , $ this -> sanitizeCacheKeyPart ( $ filter ) , $ this -> sanitizeCacheKeyPart ( $ path ) , ] ) ;...
Generate a unique cache key based on the given parameters .
44,417
protected function generateIndexKey ( $ cacheKey ) { $ cacheKeyStack = explode ( '.' , $ cacheKey ) ; return implode ( '.' , [ $ this -> sanitizeCacheKeyPart ( $ this -> options [ 'global_prefix' ] ) , $ this -> sanitizeCacheKeyPart ( $ this -> options [ 'prefix' ] ) , $ this -> sanitizeCacheKeyPart ( $ this -> options...
Generate the index key for the given cacheKey .
44,418
protected function saveToCache ( $ cacheKey , $ content ) { $ indexKey = $ this -> generateIndexKey ( $ cacheKey ) ; if ( $ this -> cache -> contains ( $ indexKey ) ) { $ index = ( array ) $ this -> cache -> fetch ( $ indexKey ) ; if ( ! \ in_array ( $ cacheKey , $ index , true ) ) { $ index [ ] = $ cacheKey ; } } else...
Save the given content to the cache and update the cache index .
44,419
public function addLoader ( string $ filter , LoaderInterface $ loader ) : void { $ this -> loaders [ $ filter ] = $ loader ; }
Adds a loader to handle the given filter .
44,420
public function addPostProcessor ( string $ name , PostProcessorInterface $ postProcessor ) : void { $ this -> postProcessors [ $ name ] = $ postProcessor ; }
Adds a post - processor to handle binaries .
44,421
public function applyFilter ( BinaryInterface $ binary , $ filter , array $ runtimeConfig = [ ] ) { $ config = array_replace_recursive ( $ this -> getFilterConfiguration ( ) -> get ( $ filter ) , $ runtimeConfig ) ; return $ this -> apply ( $ binary , $ config ) ; }
Apply the provided filter set on the given binary .
44,422
public function load ( ImageInterface $ image , array $ options = [ ] ) { $ angle = isset ( $ options [ 'angle' ] ) ? ( int ) $ options [ 'angle' ] : 0 ; return 0 === $ angle ? $ image : $ image -> rotate ( $ angle ) ; }
Loads and applies a filter on the given image .
44,423
public static function getDriverList ( bool $ FQCNAsKey = false ) : array { static $ driverList ; if ( self :: getDefaultNamespacePath ( ) === self :: getNamespacePath ( ) ) { if ( $ driverList === null ) { $ prefix = self :: CORE_DRIVER_NAMESPACE ; $ classMap = self :: createClassMap ( __DIR__ . '/Drivers' ) ; $ drive...
Return the list of available drivers Capitalized with optional FQCN as key
44,424
public static function getChangelog ( ) : string { $ changelogFilename = __DIR__ . '/../../CHANGELOG_API.md' ; if ( \ file_exists ( $ changelogFilename ) ) { $ string = \ str_replace ( [ "\r\n" , "\r" ] , "\n" , \ trim ( \ file_get_contents ( $ changelogFilename ) ) ) ; if ( $ string ) { return $ string ; } throw new P...
Return the API changelog as a string .
44,425
protected function collectionExists ( $ collectionName ) : bool { foreach ( $ this -> database -> listCollections ( ) as $ collection ) { if ( $ collection -> getName ( ) === $ collectionName ) { return true ; } } return false ; }
Checks if a collection name exists on the Mongo database .
44,426
protected function buildConnectionURI ( $ databaseName = '' ) : string { $ servers = $ this -> getConfig ( ) -> getServers ( ) ; $ options = $ this -> getConfig ( ) -> getOptions ( ) ; $ host = $ this -> getConfig ( ) -> getHost ( ) ; $ port = $ this -> getConfig ( ) -> getPort ( ) ; $ username = $ this -> getConfig ( ...
Builds the connection URI from the given parameters .
44,427
public function initDB ( \ PDO $ db ) { $ db -> exec ( 'drop table if exists "caching"' ) ; $ db -> exec ( 'CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)' ) ; $ db -> exec ( 'CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")' ) ; $ db ...
INIT NEW DB
44,428
public function initIndexing ( \ PDO $ db ) { $ dir = opendir ( $ this -> SqliteDir ) ; while ( $ file = readdir ( $ dir ) ) { if ( $ file != '.' && $ file != '..' && $ file != 'indexing' && $ file != 'dbfastcache' ) { unlink ( $ this -> SqliteDir . '/' . $ file ) ; } } $ db -> exec ( 'DROP TABLE if exists "balancing"'...
INIT Indexing DB
44,429
public function indexing ( $ keyword ) { if ( $ this -> indexing == null ) { $ tableCreated = false ; if ( ! \ file_exists ( $ this -> SqliteDir . '/indexing' ) ) { $ tableCreated = true ; } $ PDO = new PDO ( "sqlite:" . $ this -> SqliteDir . '/' . self :: INDEXING_FILE ) ; $ PDO -> setAttribute ( PDO :: ATTR_ERRMODE ,...
INIT Instant DB Return Database of Keyword
44,430
public static function dirSize ( string $ directory , bool $ includeDirAllocSize = false ) : int { $ size = 0 ; foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ directory ) ) as $ file ) { if ( $ file -> isFile ( ) ) { $ size += filesize ( $ file -> getRealPath ( ) ) ; } else { if ( $ includ...
Get the directory size
44,431
public function isAttached ( CacheItemInterface $ item ) { if ( isset ( $ this -> itemInstances [ $ item -> getKey ( ) ] ) ) { return \ spl_object_hash ( $ item ) === \ spl_object_hash ( $ this -> itemInstances [ $ item -> getKey ( ) ] ) ; } return null ; }
Returns true if the item exists is attached and the Spl Hash matches Returns false if the item exists is attached and the Spl Hash mismatches Returns null if the item does not exists
44,432
public function getDataAsJsonString ( $ option = 0 , $ depth = 512 ) : string { $ data = $ this -> get ( ) ; if ( \ is_object ( $ data ) || \ is_array ( $ data ) ) { $ data = \ json_encode ( $ data , $ option , $ depth ) ; } else { $ data = \ json_encode ( [ $ data ] , $ option , $ depth ) ; } return \ json_encode ( $ ...
Return the data as a well - formatted string . Any scalar value will be casted to an array
44,433
public function push ( CollectorRegistry $ collectorRegistry , $ job , $ groupingKey = null ) { $ this -> doRequest ( $ collectorRegistry , $ job , $ groupingKey , 'put' ) ; }
Pushes all metrics in a Collector replacing all those with the same job . Uses HTTP PUT .
44,434
public function pushAdd ( CollectorRegistry $ collectorRegistry , $ job , $ groupingKey = null ) { $ this -> doRequest ( $ collectorRegistry , $ job , $ groupingKey , 'post' ) ; }
Pushes all metrics in a Collector replacing only previously pushed metrics of the same name and job . Uses HTTP POST .
44,435
private function correctPluginName ( $ vars ) { $ camelCasedName = preg_replace_callback ( '/(-[a-z])/' , function ( $ matches ) { return strtoupper ( $ matches [ 0 ] [ 1 ] ) ; } , $ vars [ 'name' ] ) ; $ vars [ 'name' ] = ucfirst ( $ camelCasedName ) ; return $ vars ; }
Change hyphenated names to camelcase
44,436
protected function checkDuplicates ( $ path , array $ vars = array ( ) ) { $ packageType = substr ( $ vars [ 'type' ] , strlen ( 'bitrix' ) + 1 ) ; $ localDir = explode ( '/' , $ vars [ 'bitrix_dir' ] ) ; array_pop ( $ localDir ) ; $ localDir [ ] = 'local' ; $ localDir = implode ( '/' , $ localDir ) ; $ oldPath = str_r...
Duplicates search packages .
44,437
public function inflectPackageVars ( $ vars ) { $ vars [ 'name' ] = strtolower ( $ vars [ 'name' ] ) ; $ vars [ 'name' ] = preg_replace ( '/.ontowiki$/' , '' , $ vars [ 'name' ] ) ; $ vars [ 'name' ] = preg_replace ( '/-theme$/' , '' , $ vars [ 'name' ] ) ; $ vars [ 'name' ] = preg_replace ( '/-translation$/' , '' , $ ...
Format package name to lower case and remove . ontowiki suffix
44,438
public function inflectPackageVars ( $ vars ) { if ( $ vars [ 'type' ] == 'mautic-plugin' ) { $ vars [ 'name' ] = preg_replace_callback ( '/(-[a-z])/' , function ( $ matches ) { return strtoupper ( $ matches [ 0 ] [ 1 ] ) ; } , ucfirst ( $ vars [ 'name' ] ) ) ; } return $ vars ; }
Format package name of mautic - plugins to CamelCase
44,439
public function inflectPackageVars ( $ vars ) { $ restrictedWords = implode ( '|' , array_keys ( $ this -> locations ) ) ; $ vars [ 'name' ] = strtolower ( $ vars [ 'name' ] ) ; $ vars [ 'name' ] = preg_replace ( '/^(?:grav-)?(?:(?:' . $ restrictedWords . ')-)?(.*?)(?:-(?:' . $ restrictedWords . '))?$/ui' , '$1' , $ va...
Format package name
44,440
public function getLocations ( ) { if ( $ this -> matchesCakeVersion ( '>=' , '3.0.0' ) ) { $ this -> locations [ 'plugin' ] = $ this -> composer -> getConfig ( ) -> get ( 'vendor-dir' ) . '/{$vendor}/{$name}/' ; } return $ this -> locations ; }
Change the default plugin location when cakephp > = 3 . 0
44,441
protected function matchesCakeVersion ( $ matcher , $ version ) { if ( class_exists ( 'Composer\Semver\Constraint\MultiConstraint' ) ) { $ multiClass = 'Composer\Semver\Constraint\MultiConstraint' ; $ constraintClass = 'Composer\Semver\Constraint\Constraint' ; } else { $ multiClass = 'Composer\Package\LinkConstraint\Mu...
Check if CakePHP version matches against a version
44,442
public function inflectPackageVars ( $ vars ) { $ autoload = $ this -> package -> getAutoload ( ) ; if ( isset ( $ autoload [ 'psr-0' ] ) && is_array ( $ autoload [ 'psr-0' ] ) ) { $ namespace = key ( $ autoload [ 'psr-0' ] ) ; $ vars [ 'name' ] = str_replace ( '\\' , '.' , $ namespace ) ; } if ( isset ( $ autoload [ '...
Modify the package name to be a TYPO3 Flow style key .
44,443
public function inflectPackageVars ( $ vars ) { if ( $ vars [ 'type' ] == 'sydes-module' ) { return $ this -> inflectModuleVars ( $ vars ) ; } if ( $ vars [ 'type' ] === 'sydes-theme' ) { return $ this -> inflectThemeVars ( $ vars ) ; } return $ vars ; }
Format module name .
44,444
protected function findFrameworkType ( $ type ) { $ frameworkType = false ; krsort ( $ this -> supportedTypes ) ; foreach ( $ this -> supportedTypes as $ key => $ val ) { if ( $ key === substr ( $ type , 0 , strlen ( $ key ) ) ) { $ frameworkType = substr ( $ type , 0 , strlen ( $ key ) ) ; break ; } } return $ framewo...
Finds a supported framework type if it exists and returns it
44,445
protected function removeDisabledInstallers ( ) { $ extra = $ this -> composer -> getPackage ( ) -> getExtra ( ) ; if ( ! isset ( $ extra [ 'installer-disable' ] ) || $ extra [ 'installer-disable' ] === false ) { return ; } $ disable = $ extra [ 'installer-disable' ] ; if ( ! is_array ( $ disable ) ) { $ disable = arra...
Look for installers set to be disabled in composer s extra config and remove them from the list of supported installers .
44,446
public function update ( ) { $ this -> helper -> progress ( '--- Currencies' ) ; $ this -> helper -> eraseDataDir ( $ dataDir = '/currencies/default' ) ; $ currencies = $ this -> helper -> loadJsonFiles ( $ directory = $ this -> helper -> dataDir ( 'third-party/world-currencies/package/src' ) ) ; if ( $ currencies -> i...
Update all currencies .
44,447
protected function instantiateCache ( Cache $ cache = null ) { if ( is_null ( $ this -> cache ) || ! is_null ( $ cache ) ) { $ this -> cache = ! is_null ( $ cache ) ? $ cache : new Cache ( $ this -> config ) ; } return $ this -> cache ; }
Instantiate cache .
44,448
protected function instantiateConfig ( $ config = null ) { if ( is_null ( $ this -> config ) || ! is_null ( $ config ) ) { $ this -> config = ! is_null ( $ config ) ? $ config : new Config ( $ this -> helper ) ; } return $ this -> config ; }
Instantiate config .
44,449
protected function instantiateHydrator ( Hydrator $ hydrator = null ) { if ( is_null ( $ this -> hydrator ) || ! is_null ( $ hydrator ) ) { $ this -> hydrator = ! is_null ( $ hydrator ) ? $ hydrator : new Hydrator ( $ this -> config ) ; } return $ this -> hydrator ; }
Instantiate hydrator .
44,450
public function update ( ) { $ this -> helper -> progress ( '--- Countries' ) ; $ dataDir = '/countries/default/' ; $ this -> updater -> setCountries ( $ this -> cache -> remember ( 'updateCountries->buildCountriesCoollection' , 160 , function ( ) use ( $ dataDir ) { $ this -> helper -> eraseDataDir ( $ dataDir ) ; ret...
Update countries .
44,451
public function buildCountriesCoollection ( $ dataDir ) { $ this -> helper -> message ( 'Processing countries...' ) ; $ mledoze = $ this -> mledoze -> loadMledozeCountries ( ) ; $ shapeFile = $ this -> helper -> loadShapeFile ( 'third-party/natural_earth/ne_10m_admin_0_countries' ) ; $ this -> helper -> message ( 'Gene...
Build countries collection .
44,452
public function fillRinvexFields ( $ natural ) { $ mergeable = [ 'calling_code' => 'dialling' , 'area' => 'geo' , 'continent' => 'geo' , 'landlocked' => 'geo' , 'region' => 'geo' , 'region_un' => 'geo' , 'region_wb' => 'geo' , 'subregion' => 'geo' , 'latlng' => 'geo' , ] ; coollect ( $ mergeable ) -> each ( function ( ...
Fill array with Rinvex usable data .
44,453
public function findRinvexState ( $ country , $ needle ) { $ states = $ this -> findRinvex ( $ country , 'divisions' ) -> map ( function ( $ state , $ postal ) { $ state [ 'postal' ] = $ postal ; $ state [ 'name' ] = $ this -> helper -> fixUtf8 ( $ state [ 'name' ] ) ; return $ state ; } ) ; if ( $ states -> isEmpty ( ...
Find the Rinvex state .
44,454
public function mergeWithRinvex ( $ natural , $ rinvex , $ translation , $ suffix = '_rinvex' ) { $ defaultToRinvex = coollect ( [ 'currency' , 'languages' , 'dialling' , ] ) ; $ merge = coollect ( [ 'geo' , 'translations' , 'flag' , ] ) ; $ natural = $ this -> fillRinvexFields ( $ natural ) ; if ( $ rinvex -> isEmpty ...
Merge country data with Rinvex data .
44,455
public function update ( ) { $ this -> helper -> progress ( '--- Cities' ) ; $ this -> helper -> eraseDataDir ( $ dataDir = '/cities/default/' ) ; $ result = $ this -> helper -> loadShapeFile ( 'third-party/natural_earth/ne_10m_populated_places' ) ; $ this -> helper -> message ( 'Processing cities...' ) ; $ normalizerC...
Update cities .
44,456
public function loadJsonFiles ( $ dir ) { return coollect ( glob ( "$dir/*.json*" ) ) -> mapWithKeys ( function ( $ file ) { $ key = str_replace ( '.json' , '' , str_replace ( '.json5' , '' , basename ( $ file ) ) ) ; return [ $ key => $ this -> loadJson ( $ file ) ] ; } ) ; }
Load json files from dir .
44,457
public function moveFilesWildcard ( $ from , $ to ) { coollect ( glob ( $ this -> dataDir ( $ from ) ) ) -> each ( function ( $ from ) use ( $ to ) { $ this -> mkDir ( $ dir = $ this -> dataDir ( $ to ) ) ; rename ( $ from , $ dir . '/' . basename ( $ from ) ) ; } ) ; }
Move files using wildcard filter .
44,458
public function dataDir ( $ path = '' ) { $ path = ( empty ( $ path ) || starts_with ( $ path , DIRECTORY_SEPARATOR ) ) ? $ path : "/{$path}" ; return __COUNTRIES_DIR__ . $ this -> toDir ( "/src/data$path" ) ; }
Get data directory .
44,459
public function fillMledozeFields ( $ fields ) { $ fields [ 'name_nev' ] = $ fields [ 'name' ] ; $ fields [ 'name' ] = [ 'common' => $ fields [ 'name' ] , 'official' => $ fields [ 'formal_en' ] , ] ; $ fields [ 'cca2' ] = $ fields [ 'iso_a2' ] == '-99' ? $ fields [ 'adm0_a3' ] : $ fields [ 'iso_a2' ] ; $ fields [ 'ccn3...
Fill mledoze fields with natural earth vector data .
44,460
public function findMledozeCountry ( $ mledoze , $ natural ) { list ( $ country , $ countryCode ) = $ this -> updater -> findCountryByAnyField ( $ mledoze , $ natural ) ; if ( ! $ country -> isEmpty ( ) ) { return [ coollect ( $ this -> helper -> arrayKeysSnakeRecursive ( $ country ) ) , $ countryCode ] ; } return [ co...
Find a mledoze country from natural earth vector data .
44,461
public function mergeWithMledoze ( $ mledoze , $ natural , $ suffix = '_nev' ) { if ( $ mledoze -> isEmpty ( ) || $ natural -> isEmpty ( ) ) { return $ mledoze -> isEmpty ( ) ? $ this -> fillMledozeFields ( $ natural ) : $ this -> natural -> fillNaturalFields ( $ mledoze ) ; } $ result = [ ] ; foreach ( $ mledoze -> ke...
Merge the two countries sources .
44,462
public function where ( $ key , $ operator , $ value = null ) { if ( func_num_args ( ) == 2 ) { $ value = $ operator ; $ operator = '=' ; } $ countries = method_exists ( $ this , 'where' . ucfirst ( $ key ) ) ? $ this -> { 'where' . ucfirst ( $ key ) } ( $ value ) : parent :: where ( $ key , $ operator , $ value ) ; re...
Where on steroids .
44,463
private function _whereKey ( string $ arrayName , $ value ) { $ finderClosure = function ( $ value , $ attributeValue ) { return Arr :: has ( $ attributeValue , $ value ) ; } ; return $ this -> hydrateDefaultElements ( $ this -> arrayFinder ( $ arrayName , $ value , $ finderClosure ) ) ; }
Where for keys .
44,464
public function instantiateManager ( $ config , $ manager , $ path ) { return is_null ( $ manager ) ? new NetteManager ( $ config , $ path ) : $ manager ; }
Instantiate the cache manager .
44,465
private function hydrateCountries ( $ countries , $ elements = null ) { return countriesCollect ( $ countries -> map ( function ( $ country ) use ( $ elements ) { return $ this -> hydrateCountry ( $ country , $ elements ) ; } ) ) ; }
Hydrate elements of a collection of countries .
44,466
private function hydrateCountry ( $ country , $ elements ) { $ countryCode = $ country [ 'cca3' ] ; $ this -> addCountry ( $ countryCode , $ country ) ; foreach ( $ elements as $ element => $ enabled ) { $ this -> hydrateCountryElement ( $ countryCode , $ element , $ enabled ) ; } return $ this -> getCountry ( $ countr...
Hydrate elements of a country .
44,467
private function loadCities ( $ country ) { return $ this -> repository -> getHelper ( ) -> loadJson ( $ country [ 'cca3' ] , 'cities/default' ) -> overwrite ( $ this -> repository -> getHelper ( ) -> loadJson ( $ country [ 'cca3' ] , 'cities/overload' ) ) ; }
Load the cities file and merge overloads .
44,468
private function loadStates ( $ country ) { return $ this -> repository -> getHelper ( ) -> loadJson ( $ country [ 'cca3' ] , 'states/default' ) -> overwrite ( $ this -> repository -> getHelper ( ) -> loadJson ( $ country [ 'cca3' ] , 'states/overload' ) ) ; }
Load the states file and merge overloads .
44,469
private function loadTaxes ( $ country ) { return $ this -> repository -> getHelper ( ) -> loadJson ( $ country [ 'cca3' ] , 'taxes/default' ) -> overwrite ( $ this -> repository -> getHelper ( ) -> loadJson ( $ country [ 'cca3' ] , 'taxes/overload' ) ) ; }
Load the taxes file and merge overloads .
44,470
protected function needsHydration ( $ countryCode , $ element , $ enabled = false ) { if ( ! $ this -> canHydrate ( $ element , $ enabled , $ countryCode ) ) { return false ; } return $ this -> updateHydrated ( $ countryCode , $ element ) ; }
Check if an element needs hydrated .
44,471
protected function getHydrationElements ( $ elements ) { $ elements = ( $ elements ? : $ this -> config -> get ( 'hydrate.elements' ) ) ; if ( is_string ( $ elements ) || is_numeric ( $ elements ) ) { return [ $ elements => true ] ; } return $ this -> checkHydrationElements ( $ elements ) ; }
Get hydration elements .
44,472
public function hydrateFlag ( $ country ) { $ country = countriesCollect ( $ country ) -> overwrite ( [ 'flag' => $ this -> repository -> makeAllFlags ( $ country ) ] ) ; return $ country ; }
Hydrate flag .
44,473
public function hydrateBorders ( $ country ) { $ country [ 'borders' ] = isset ( $ country [ 'borders' ] ) ? $ country [ 'borders' ] = countriesCollect ( $ country [ 'borders' ] ) -> map ( function ( $ border ) { return $ this -> repository -> call ( 'where' , [ 'cca3' , $ border ] ) -> first ( ) ; } ) : countriesColle...
Hydrate borders .
44,474
public function hydrateTimezonesTimes ( $ country ) { $ country = $ this -> hydrateTimezones ( $ country ) ; $ country [ 'timezones' ] = $ country -> timezones -> map ( function ( $ timezone ) { return $ timezone -> overwrite ( [ 'times' => $ this -> repository -> findTimezoneTime ( $ timezone [ 'zone_id' ] ) ] ) ; } )...
Hydrate all times for a country timezones .
44,475
public function hydrateCurrencies ( $ country ) { $ currencies = [ ] ; $ country = $ this -> fixCurrencies ( $ country ) ; if ( isset ( $ country [ 'currencies' ] ) ) { $ currencies = countriesCollect ( $ country [ 'currencies' ] ) -> mapWithKeys ( function ( $ code ) { if ( $ this -> isCurrenciesArray ( $ code ) ) { r...
Hydrate currencies .
44,476
public function hydrate ( $ target , $ elements = null ) { $ elements = $ this -> getHydrationElements ( $ elements ) ; if ( coollect ( $ elements ) -> count ( ) === 0 ) { return $ target ; } return $ this -> isCountry ( $ target -> toArray ( ) ) ? $ this -> hydrateCountry ( $ target , $ elements ) : $ this -> hydrateC...
Hydrate a countries collection with languages .
44,477
public function addCountry ( $ countryCode , $ country ) { if ( ! isset ( $ this -> repository -> countries [ $ countryCode ] ) ) { $ this -> repository -> countries [ $ countryCode ] = $ country ; } }
Check and create a country in the repository .
44,478
public function hydrateCountryElement ( $ countryCode , $ element , $ enabled ) { if ( $ this -> needsHydration ( $ countryCode , $ element , $ enabled ) ) { $ this -> repository -> countries [ $ countryCode ] = $ this -> { 'hydrate' . Str :: studly ( $ element ) } ( $ this -> repository -> countries [ $ countryCode ] ...
Hydrate a country element .
44,479
protected function checkHydrationElements ( $ elements ) { $ elements = countriesCollect ( $ elements ) -> mapWithKeys ( function ( $ value , $ key ) { if ( is_numeric ( $ key ) ) { $ key = $ value ; $ value = true ; } return [ $ key => $ value ] ; } ) -> filter ( function ( $ element ) { return $ element ; } ) ; retur...
Check hydration elements .
44,480
protected function updateHydrated ( $ countryCode , $ element ) { $ hydrated = $ this -> createHydrated ( $ countryCode ) ; $ hydrated [ $ element ] = true ; $ this -> repository -> countries [ $ countryCode ] [ 'hydrated' ] = $ hydrated ; return true ; }
Update hydrated .
44,481
public function getCacheDir ( ) { if ( is_null ( $ this -> dir ) ) { $ this -> dir = $ this -> config -> cache -> directory ? : sys_get_temp_dir ( ) . '/__PRAGMARX_COUNTRIES__/cache' ; if ( ! file_exists ( $ this -> dir ) ) { mkdir ( $ this -> dir , 0755 , true ) ; } } return $ this -> dir ; }
Get the cache directory .
44,482
public function update ( $ command = null ) { $ this -> command = $ this -> instantiateCommand ( $ command ) ; $ this -> helper -> downloadFiles ( ) ; $ this -> countries -> update ( ) ; $ this -> currencies -> update ( ) ; $ this -> loadCountries ( ) ; $ this -> states -> update ( ) ; $ this -> cities -> update ( ) ; ...
Update all data .
44,483
public function addDataSource ( $ record , $ source ) { if ( arrayable ( $ record ) ) { $ record = $ record -> toArray ( ) ; } if ( ! isset ( $ record [ $ field = 'data_sources' ] ) ) { $ record [ 'data_sources' ] = [ ] ; } $ record [ 'data_sources' ] [ ] = $ source ; return coollect ( $ record ) ; }
Add data sources to collection .
44,484
public function generateAllJsonFiles ( $ dir , $ makeGroupKeyClosure , $ records , $ groupKey ) { if ( ! empty ( $ groupKey ) ) { $ records = $ records -> groupBy ( $ groupKey ) ; } $ records -> each ( function ( Coollection $ record , $ key ) use ( $ dir , $ makeGroupKeyClosure ) { $ this -> helper -> mkdir ( dirname ...
Generate all json files .
44,485
public function generateJsonFiles ( $ data , $ dir , $ normalizerClosure , $ makeGroupKeyClosure , $ mergeData , $ groupKey = 'cca3' ) { $ this -> helper -> message ( 'Normalizing data...' ) ; $ data = $ this -> normalizeData ( $ data , $ dir , $ normalizerClosure ) ; $ this -> helper -> message ( 'Merging data...' ) ;...
Generate json files from array .
44,486
public function update ( ) { $ this -> helper -> progress ( '--- States' ) ; $ this -> helper -> eraseDataDir ( $ dataDir = '/states/default' ) ; $ result = $ this -> helper -> loadShapeFile ( 'third-party/natural_earth/ne_10m_admin_1_states_provinces' ) ; $ this -> helper -> message ( 'Processing states...' ) ; $ norm...
Update states .
44,487
public function makeStatePostalCode ( $ item ) { $ item = coollect ( $ item ) ; if ( $ item -> iso_3166_2 !== '' ) { $ code = explode ( '-' , $ item -> iso_3166_2 ) ; if ( count ( $ code ) > 1 ) { return $ code [ 1 ] ; } } if ( ! empty ( trim ( $ item -> postal ) ) ) { $ item -> postal ; } if ( $ item -> code_hasc !== ...
Get the state postal code .
44,488
protected function addSuffix ( $ suffix , $ string ) { if ( substr ( $ string , - strlen ( $ suffix ) ) !== ( string ) $ suffix ) { $ string .= $ suffix ; } return $ string ; }
Add suffix to string .
44,489
protected function deleteDirectory ( $ dir ) { $ files = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ dir , RecursiveDirectoryIterator :: SKIP_DOTS ) , RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ files as $ fileInfo ) { $ todo = ( $ fileInfo -> isDir ( ) ? 'rmdir' : 'unlink' ) ; $ tod...
Delete a whole directory .
44,490
public function download ( $ url , $ directory ) { coollect ( ( array ) $ url ) -> each ( function ( $ url ) use ( $ directory ) { $ filename = basename ( $ url ) ; $ destination = $ this -> toDir ( "{$directory}/{$filename}" ) ; $ this -> message ( "Downloading to {$destination}" ) ; $ this -> mkDir ( $ directory ) ; ...
Download one or more files .
44,491
public function delTree ( $ dir ) { if ( ! file_exists ( $ dir ) ) { return false ; } $ files = array_diff ( scandir ( $ dir ) , [ '.' , '..' ] ) ; $ this -> deleteAllFiles ( $ dir , $ files ) ; return rmdir ( $ dir ) ; }
Delete a directory and all its files .
44,492
public function shapeFile ( $ dir ) { $ shapeRecords = new ShapeFile ( $ dir ) ; $ result = [ ] ; foreach ( $ shapeRecords as $ record ) { if ( $ record [ 'dbf' ] [ '_deleted' ] ) { continue ; } $ data = $ record [ 'dbf' ] ; unset ( $ data [ '_deleted' ] ) ; $ result [ ] = $ data ; } unset ( $ shapeRecords ) ; return c...
Load a shapeFile .
44,493
public function arrayKeysSnakeRecursive ( $ array ) { $ result = [ ] ; $ array = arrayable ( $ array ) ? $ array -> toArray ( ) : $ array ; array_walk ( $ array , function ( $ value , $ key ) use ( & $ result ) { $ result [ snake_case ( $ key ) ] = arrayable ( $ value ) || is_array ( $ value ) ? $ this -> arrayKeysSnak...
Recursively change all array keys case .
44,494
public function downloadDataFiles ( ) { $ this -> config -> get ( 'downloadable' ) -> each ( function ( $ urls , $ path ) { if ( ! file_exists ( $ destination = $ this -> dataDir ( "third-party/$path" ) ) ) { coollect ( $ urls ) -> each ( function ( $ url ) use ( $ path , $ destination ) { $ this -> download ( $ url , ...
Download files .
44,495
public function moveDataFile ( $ from , $ to ) { if ( str_contains ( $ from , '*.' ) ) { $ this -> moveFilesWildcard ( $ from , $ to ) ; return ; } if ( file_exists ( $ from = $ this -> dataDir ( $ from ) ) ) { $ this -> mkDir ( dirname ( $ to = $ this -> dataDir ( $ to ) ) ) ; rename ( $ from , $ to ) ; } }
Move a data file or many using wildcards .
44,496
public function moveDataFiles ( ) { $ this -> config -> get ( 'moveable' ) -> each ( function ( $ to , $ from ) { $ this -> moveDataFile ( $ from , $ to ) ; } ) ; }
Move data files to the proper location .
44,497
public function progress ( $ string = '' ) { if ( is_null ( $ this -> command ) ) { dump ( $ string ) ; return ; } $ this -> command -> line ( $ string ) ; }
Show the progress .
44,498
public function message ( $ message , $ type = 'line' ) { if ( ! is_null ( $ this -> command ) ) { $ this -> command -> { $ type } ( $ message ) ; } }
Display a message in console .
44,499
public function makeJsonFileName ( $ key , $ dir = '' ) { if ( ! ends_with ( $ dir , ( DIRECTORY_SEPARATOR ) ) ) { $ dir .= DIRECTORY_SEPARATOR ; } return $ this -> dataDir ( $ this -> addSuffix ( '.json' , $ this -> toDir ( $ dir ) . strtolower ( $ key ) ) ) ; }
Make state json filename .