idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
42,200 | function createCustomConfigFile ( $ tld ) { $ customConfigPath = $ this -> customConfigPath ( ) ; $ this -> copyExampleConfig ( ) ; $ this -> appendCustomConfigImport ( $ customConfigPath ) ; $ this -> files -> putAsUser ( $ customConfigPath , 'address=/.' . $ tld . '/127.0.0.1' . PHP_EOL . 'listen-address=127.0.0.1' .... | Append the custom DnsMasq configuration file to the main configuration file . |
42,201 | function copyExampleConfig ( ) { if ( ! $ this -> files -> exists ( $ this -> configPath ) ) { $ this -> files -> copyAsUser ( $ this -> exampleConfigPath , $ this -> configPath ) ; } } | Copy the Homebrew installed example DnsMasq configuration file . |
42,202 | function appendCustomConfigImport ( $ customConfigPath ) { $ contents = preg_replace ( '/^conf-file=.*\/\.valet\/.*$/m' , '' , $ this -> files -> get ( $ this -> configPath ) ) ; $ this -> files -> putAsUser ( $ this -> configPath , $ contents ) ; if ( ! $ this -> customConfigIsBeingImported ( $ customConfigPath ) ) { ... | Append import command for our custom configuration to DnsMasq file . |
42,203 | function customConfigIsBeingImported ( $ customConfigPath ) { return strpos ( $ this -> files -> get ( $ this -> configPath ) , $ customConfigPath ) !== false ; } | Determine if Valet s custom DnsMasq configuration is being imported . |
42,204 | function createTldResolver ( $ tld ) { $ this -> files -> ensureDirExists ( $ this -> resolverPath ) ; $ this -> files -> put ( $ this -> resolverPath . '/' . $ tld , 'nameserver 127.0.0.1' . PHP_EOL ) ; } | Create the resolver file to point the configured TLD to 127 . 0 . 0 . 1 . |
42,205 | function installed ( $ formula ) { return in_array ( $ formula , explode ( PHP_EOL , $ this -> cli -> runAsUser ( 'brew list | grep ' . $ formula ) ) ) ; } | Determine if the given formula is installed . |
42,206 | function ensureInstalled ( $ formula , $ options = [ ] , $ taps = [ ] ) { if ( ! $ this -> installed ( $ formula ) ) { $ this -> installOrFail ( $ formula , $ options , $ taps ) ; } } | Ensure that the given formula is installed . |
42,207 | function tap ( $ formulas ) { $ formulas = is_array ( $ formulas ) ? $ formulas : func_get_args ( ) ; foreach ( $ formulas as $ formula ) { $ this -> cli -> passthru ( 'sudo -u "' . user ( ) . '" brew tap ' . $ formula ) ; } } | Tap the given formulas . |
42,208 | function stopService ( $ services ) { $ services = is_array ( $ services ) ? $ services : func_get_args ( ) ; foreach ( $ services as $ service ) { if ( $ this -> installed ( $ service ) ) { info ( "Stopping {$service}..." ) ; $ this -> cli -> quietly ( 'sudo brew services stop ' . $ service ) ; } } } | Stop the given Homebrew services . |
42,209 | function getParsedLinkedPhp ( ) { if ( ! $ this -> hasLinkedPhp ( ) ) { throw new DomainException ( "Homebrew PHP appears not to be linked." ) ; } $ resolvedPath = $ this -> files -> readLink ( '/usr/local/bin/php' ) ; preg_match ( '~\w{3,}/(php)(@?\d\.?\d)?/(\d\.\d)?([_\d\.]*)?/?\w{3,}~' , $ resolvedPath , $ matches )... | Get the linked php parsed |
42,210 | function linkedPhp ( ) { $ matches = $ this -> getParsedLinkedPhp ( ) ; $ resolvedPhpVersion = $ matches [ 3 ] ? : $ matches [ 2 ] ; return $ this -> supportedPhpVersions ( ) -> first ( function ( $ version ) use ( $ resolvedPhpVersion ) { $ resolvedVersionNormalized = preg_replace ( '/[^\d]/' , '' , $ resolvedPhpVersi... | Determine which version of PHP is linked in Homebrew . |
42,211 | function link ( $ formula , $ force = false ) { return $ this -> cli -> runAsUser ( sprintf ( 'brew link %s%s' , $ formula , $ force ? ' --force' : '' ) , function ( $ exitCode , $ errorOutput ) use ( $ formula ) { output ( $ errorOutput ) ; throw new DomainException ( 'Brew was unable to link [' . $ formula . '].' ) ;... | Link passed formula |
42,212 | function getRunningServices ( ) { return collect ( array_filter ( explode ( PHP_EOL , $ this -> cli -> runAsUser ( 'brew services list | grep started | awk \'{ print $1; }\'' , function ( $ exitCode , $ errorOutput ) { output ( $ errorOutput ) ; throw new DomainException ( 'Brew was unable to check which services are r... | Get the currently running brew services |
42,213 | private function getRealSiteName ( $ name ) { if ( ! is_null ( $ name ) ) { return $ name ; } if ( is_string ( $ link = $ this -> getLinkNameByCurrentDir ( ) ) ) { return $ link ; } return basename ( getcwd ( ) ) ; } | Get the name of the site . |
42,214 | private function getLinkNameByCurrentDir ( ) { $ count = count ( $ links = $ this -> links ( ) -> where ( 'path' , getcwd ( ) ) ) ; if ( $ count == 1 ) { return $ links -> shift ( ) [ 'site' ] ; } if ( $ count > 1 ) { throw new DomainException ( "There are {$count} links related to the current directory, please specify... | Get link name based on the current directory . |
42,215 | function host ( $ path ) { foreach ( $ this -> files -> scandir ( $ this -> sitesPath ( ) ) as $ link ) { if ( $ resolved = realpath ( $ this -> sitesPath ( ) . '/' . $ link ) === $ path ) { return $ link ; } } return basename ( $ path ) ; } | Get the real hostname for the given path checking links . |
42,216 | function link ( $ target , $ link ) { $ this -> files -> ensureDirExists ( $ linkPath = $ this -> sitesPath ( ) , user ( ) ) ; $ this -> config -> prependPath ( $ linkPath ) ; $ this -> files -> symlinkAsUser ( $ target , $ linkPath . '/' . $ link ) ; return $ linkPath . '/' . $ link ; } | Link the current working directory with the given name . |
42,217 | function links ( ) { $ certsPath = VALET_HOME_PATH . '/Certificates' ; $ this -> files -> ensureDirExists ( $ certsPath , user ( ) ) ; $ certs = $ this -> getCertificates ( $ certsPath ) ; return $ this -> getLinks ( $ this -> sitesPath ( ) , $ certs ) ; } | Pretty print out all links in Valet . |
42,218 | function getCertificates ( $ path ) { return collect ( $ this -> files -> scandir ( $ path ) ) -> filter ( function ( $ value , $ key ) { return ends_with ( $ value , '.crt' ) ; } ) -> map ( function ( $ cert ) { $ certWithoutSuffix = substr ( $ cert , 0 , - 4 ) ; return substr ( $ certWithoutSuffix , 0 , strrpos ( $ c... | Get all certificates from config folder . |
42,219 | function getLinks ( $ path , $ certs ) { $ config = $ this -> config -> read ( ) ; return collect ( $ this -> files -> scandir ( $ path ) ) -> mapWithKeys ( function ( $ site ) use ( $ path ) { return [ $ site => $ this -> files -> readLink ( $ path . '/' . $ site ) ] ; } ) -> map ( function ( $ path , $ site ) use ( $... | Get list of links and present them formatted . |
42,220 | function unlink ( $ name ) { $ name = $ this -> getRealSiteName ( $ name ) ; if ( $ this -> files -> exists ( $ path = $ this -> sitesPath ( ) . '/' . $ name ) ) { $ this -> files -> unlink ( $ path ) ; } return $ name ; } | Unlink the given symbolic link . |
42,221 | function pruneLinks ( ) { $ this -> files -> ensureDirExists ( $ this -> sitesPath ( ) , user ( ) ) ; $ this -> files -> removeBrokenLinksAt ( $ this -> sitesPath ( ) ) ; } | Remove all broken symbolic links . |
42,222 | function resecureForNewTld ( $ oldTld , $ tld ) { if ( ! $ this -> files -> exists ( $ this -> certificatesPath ( ) ) ) { return ; } $ secured = $ this -> secured ( ) ; foreach ( $ secured as $ url ) { $ this -> unsecure ( $ url ) ; } foreach ( $ secured as $ url ) { $ this -> secure ( str_replace ( '.' . $ oldTld , '.... | Resecure all currently secured sites with a fresh tld . |
42,223 | function secured ( ) { return collect ( $ this -> files -> scandir ( $ this -> certificatesPath ( ) ) ) -> map ( function ( $ file ) { return str_replace ( [ '.key' , '.csr' , '.crt' , '.conf' ] , '' , $ file ) ; } ) -> unique ( ) -> values ( ) -> all ( ) ; } | Get all of the URLs that are currently secured . |
42,224 | function secure ( $ url ) { $ this -> unsecure ( $ url ) ; $ this -> files -> ensureDirExists ( $ this -> caPath ( ) , user ( ) ) ; $ this -> files -> ensureDirExists ( $ this -> certificatesPath ( ) , user ( ) ) ; $ this -> createCa ( ) ; $ this -> createCertificate ( $ url ) ; $ this -> files -> putAsUser ( VALET_HOM... | Secure the given host with TLS . |
42,225 | function createCa ( ) { $ caPemPath = $ this -> caPath ( ) . '/LaravelValetCASelfSigned.pem' ; $ caKeyPath = $ this -> caPath ( ) . '/LaravelValetCASelfSigned.key' ; if ( $ this -> files -> exists ( $ caKeyPath ) && $ this -> files -> exists ( $ caPemPath ) ) { return ; } $ oName = 'Laravel Valet CA Self Signed Organiz... | If CA and root certificates are nonexistent crete them and trust the root cert . |
42,226 | function createCertificate ( $ url ) { $ caPemPath = $ this -> caPath ( ) . '/LaravelValetCASelfSigned.pem' ; $ caKeyPath = $ this -> caPath ( ) . '/LaravelValetCASelfSigned.key' ; $ caSrlPath = $ this -> caPath ( ) . '/LaravelValetCASelfSigned.srl' ; $ keyPath = $ this -> certificatesPath ( ) . '/' . $ url . '.key' ; ... | Create and trust a certificate for the given URL . |
42,227 | function createSigningRequest ( $ url , $ keyPath , $ csrPath , $ confPath ) { $ this -> cli -> runAsUser ( sprintf ( 'openssl req -new -key "%s" -out "%s" -subj "/C=/ST=/O=/localityName=/commonName=%s/organizationalUnitName=/emailAddress=%s%s/" -config "%s"' , $ keyPath , $ csrPath , $ url , $ url , '@laravel.valet' ,... | Create the signing request for the TLS certificate . |
42,228 | function buildCertificateConf ( $ path , $ url ) { $ config = str_replace ( 'VALET_DOMAIN' , $ url , $ this -> files -> get ( __DIR__ . '/../stubs/openssl.conf' ) ) ; $ this -> files -> putAsUser ( $ path , $ config ) ; } | Build the SSL config for the given URL . |
42,229 | function buildSecureNginxServer ( $ url ) { $ path = $ this -> certificatesPath ( ) ; return str_replace ( [ 'VALET_HOME_PATH' , 'VALET_SERVER_PATH' , 'VALET_STATIC_PREFIX' , 'VALET_SITE' , 'VALET_CERT' , 'VALET_KEY' ] , [ VALET_HOME_PATH , VALET_SERVER_PATH , VALET_STATIC_PREFIX , $ url , $ path . '/' . $ url . '.crt'... | Build the TLS secured Nginx server for the given URL . |
42,230 | function unsecure ( $ url ) { if ( $ this -> files -> exists ( $ this -> certificatesPath ( ) . '/' . $ url . '.crt' ) ) { $ this -> files -> unlink ( VALET_HOME_PATH . '/Nginx/' . $ url ) ; $ this -> files -> unlink ( $ this -> certificatesPath ( ) . '/' . $ url . '.conf' ) ; $ this -> files -> unlink ( $ this -> cert... | Unsecure the given URL so that it will use HTTP again . |
42,231 | function install ( ) { $ this -> createConfigurationDirectory ( ) ; $ this -> createDriversDirectory ( ) ; $ this -> createSitesDirectory ( ) ; $ this -> createExtensionsDirectory ( ) ; $ this -> createLogDirectory ( ) ; $ this -> createCertificatesDirectory ( ) ; $ this -> writeBaseConfiguration ( ) ; $ this -> files ... | Install the Valet configuration file . |
42,232 | function createConfigurationDirectory ( ) { $ this -> files -> ensureDirExists ( preg_replace ( '~/valet$~' , '' , VALET_HOME_PATH ) , user ( ) ) ; $ oldPath = posix_getpwuid ( fileowner ( __FILE__ ) ) [ 'dir' ] . '/.valet' ; if ( $ this -> files -> isDir ( $ oldPath ) ) { rename ( $ oldPath , VALET_HOME_PATH ) ; $ thi... | Create the Valet configuration directory . |
42,233 | function createDriversDirectory ( ) { if ( $ this -> files -> isDir ( $ driversDirectory = VALET_HOME_PATH . '/Drivers' ) ) { return ; } $ this -> files -> mkdirAsUser ( $ driversDirectory ) ; $ this -> files -> putAsUser ( $ driversDirectory . '/SampleValetDriver.php' , $ this -> files -> get ( __DIR__ . '/../stubs/Sa... | Create the Valet drivers directory . |
42,234 | function createLogDirectory ( ) { $ this -> files -> ensureDirExists ( VALET_HOME_PATH . '/Log' , user ( ) ) ; $ this -> files -> touch ( VALET_HOME_PATH . '/Log/nginx-error.log' ) ; } | Create the directory for Nginx logs . |
42,235 | function writeBaseConfiguration ( ) { if ( ! $ this -> files -> exists ( $ this -> path ( ) ) ) { $ this -> write ( [ 'tld' => 'test' , 'paths' => [ ] ] ) ; } $ config = $ this -> read ( ) ; if ( isset ( $ config [ 'tld' ] ) ) { return ; } $ this -> updateKey ( 'tld' , ! empty ( $ config [ 'domain' ] ) ? $ config [ 'do... | Write the base initial configuration for Valet . |
42,236 | function addPath ( $ path , $ prepend = false ) { $ this -> write ( tap ( $ this -> read ( ) , function ( & $ config ) use ( $ path , $ prepend ) { $ method = $ prepend ? 'prepend' : 'push' ; $ config [ 'paths' ] = collect ( $ config [ 'paths' ] ) -> { $ method } ( $ path ) -> unique ( ) -> all ( ) ; } ) ) ; } | Add the given path to the configuration . |
42,237 | function removePath ( $ path ) { $ this -> write ( tap ( $ this -> read ( ) , function ( & $ config ) use ( $ path ) { $ config [ 'paths' ] = collect ( $ config [ 'paths' ] ) -> reject ( function ( $ value ) use ( $ path ) { return $ value === $ path ; } ) -> values ( ) -> all ( ) ; } ) ) ; } | Remove the given path from the configuration . |
42,238 | function prune ( ) { if ( ! $ this -> files -> exists ( $ this -> path ( ) ) ) { return ; } $ this -> write ( tap ( $ this -> read ( ) , function ( & $ config ) { $ config [ 'paths' ] = collect ( $ config [ 'paths' ] ) -> filter ( function ( $ path ) { return $ this -> files -> isDir ( $ path ) ; } ) -> values ( ) -> a... | Prune all non - existent paths from the configuration . |
42,239 | function updateKey ( $ key , $ value ) { return tap ( $ this -> read ( ) , function ( & $ config ) use ( $ key , $ value ) { $ config [ $ key ] = $ value ; $ this -> write ( $ config ) ; } ) ; } | Update a specific key in the configuration file . |
42,240 | function write ( $ config ) { $ this -> files -> putAsUser ( $ this -> path ( ) , json_encode ( $ config , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . PHP_EOL ) ; } | Write the given configuration to disk . |
42,241 | function symlinkToUsersBin ( ) { $ this -> cli -> quietlyAsUser ( 'rm ' . $ this -> valetBin ) ; $ this -> cli -> runAsUser ( 'ln -s "' . realpath ( __DIR__ . '/../../valet' ) . '" ' . $ this -> valetBin ) ; } | Symlink the Valet Bash script into the user s local bin . |
42,242 | function extensions ( ) { if ( ! $ this -> files -> isDir ( VALET_HOME_PATH . '/Extensions' ) ) { return [ ] ; } return collect ( $ this -> files -> scandir ( VALET_HOME_PATH . '/Extensions' ) ) -> reject ( function ( $ file ) { return is_dir ( $ file ) ; } ) -> map ( function ( $ file ) { return VALET_HOME_PATH . '/Ex... | Get the paths to all of the Valet extensions . |
42,243 | public function getUriLocale ( $ uri ) { $ parts = explode ( '/' , $ uri ) ; $ locale = $ parts [ 1 ] ; if ( count ( $ parts ) < 2 || ! in_array ( $ locale , $ this -> getLocales ( ) ) ) { return ; } return $ locale ; } | Get the locale from this URI |
42,244 | protected function getStaticPath ( $ sitePath ) { $ parts = parse_url ( $ _SERVER [ 'REQUEST_URI' ] ) ; $ query = isset ( $ parts [ 'query' ] ) ? $ parts [ 'query' ] : '' ; return $ sitePath . '/static' . $ parts [ 'path' ] . '_' . $ query . '.html' ; } | Get the path to a statically cached page |
42,245 | function currentTunnelUrl ( ) { return retry ( 20 , function ( ) { $ body = Request :: get ( $ this -> tunnelsEndpoint ) -> send ( ) -> body ; if ( isset ( $ body -> tunnels ) && count ( $ body -> tunnels ) > 0 ) { return $ this -> findHttpTunnelUrl ( $ body -> tunnels ) ; } else { throw new DomainException ( "Tunnel n... | Get the current tunnel URL from the Ngrok API . |
42,246 | public function frontControllerDirectory ( $ sitePath ) { $ dirs = [ 'web' , 'public' ] ; foreach ( $ dirs as $ dir ) { if ( is_dir ( $ sitePath . '/' . $ dir ) ) { return $ dir ; } } return is_file ( $ sitePath . '/craft' ) ? 'web' : 'public' ; } | Determine the name of the directory where the front controller lives . |
42,247 | function install ( ) { if ( ! $ this -> brew -> hasInstalledNginx ( ) ) { $ this -> brew -> installOrFail ( 'nginx' , [ ] ) ; } $ this -> installConfiguration ( ) ; $ this -> installServer ( ) ; $ this -> installNginxDirectory ( ) ; } | Install the configuration files for Nginx . |
42,248 | function installConfiguration ( ) { info ( 'Installing nginx configuration...' ) ; $ contents = $ this -> files -> get ( __DIR__ . '/../stubs/nginx.conf' ) ; $ this -> files -> putAsUser ( static :: NGINX_CONF , str_replace ( [ 'VALET_USER' , 'VALET_HOME_PATH' ] , [ user ( ) , VALET_HOME_PATH ] , $ contents ) ) ; } | Install the Nginx configuration file . |
42,249 | function installServer ( ) { $ this -> files -> ensureDirExists ( '/usr/local/etc/nginx/valet' ) ; $ this -> files -> putAsUser ( '/usr/local/etc/nginx/valet/valet.conf' , str_replace ( [ 'VALET_HOME_PATH' , 'VALET_SERVER_PATH' , 'VALET_STATIC_PREFIX' ] , [ VALET_HOME_PATH , VALET_SERVER_PATH , VALET_STATIC_PREFIX ] , ... | Install the Valet Nginx server configuration file . |
42,250 | function rewriteSecureNginxFiles ( ) { $ tld = $ this -> configuration -> read ( ) [ 'tld' ] ; $ this -> site -> resecureForNewTld ( $ tld , $ tld ) ; } | Generate fresh Nginx servers for existing secure sites . |
42,251 | function updateConfiguration ( ) { info ( 'Updating PHP configuration...' ) ; $ contents = $ this -> files -> get ( $ this -> fpmConfigPath ( ) ) ; $ contents = preg_replace ( '/^user = .+$/m' , 'user = ' . user ( ) , $ contents ) ; $ contents = preg_replace ( '/^group = .+$/m' , 'group = staff' , $ contents ) ; $ cont... | Update the PHP FPM configuration . |
42,252 | function fpmConfigPath ( ) { $ version = $ this -> brew -> linkedPhp ( ) ; $ versionNormalized = preg_replace ( '/php@?(\d)\.?(\d)/' , '$1.$2' , $ version === 'php' ? Brew :: LATEST_PHP_VERSION : $ version ) ; return $ versionNormalized === '5.6' ? '/usr/local/etc/php/5.6/php-fpm.conf' : "/usr/local/etc/php/${versionNo... | Get the path to the FPM configuration file for the current PHP version . |
42,253 | function stopRunning ( ) { $ this -> brew -> stopService ( $ this -> brew -> getRunningServices ( ) -> filter ( function ( $ service ) { return substr ( $ service , 0 , 3 ) === 'php' ; } ) -> all ( ) ) ; } | Only stop running php services |
42,254 | function useVersion ( $ version ) { $ version = preg_replace ( '/(php)([0-9+])(?:.)?([0-9+])/i' , '$1@$2.$3' , $ version ) ; if ( ! $ this -> brew -> supportedPhpVersions ( ) -> contains ( $ version ) ) { throw new DomainException ( sprintf ( 'Valet doesn\'t support PHP version: %s (try something like \'php7.2\' instea... | Use a specific version of php |
42,255 | function ensureDirExists ( $ path , $ owner = null , $ mode = 0755 ) { if ( ! $ this -> isDir ( $ path ) ) { $ this -> mkdir ( $ path , $ owner , $ mode ) ; } } | Ensure that the given directory exists . |
42,256 | function touch ( $ path , $ owner = null ) { touch ( $ path ) ; if ( $ owner ) { $ this -> chown ( $ path , $ owner ) ; } return $ path ; } | Touch the given path . |
42,257 | function put ( $ path , $ contents , $ owner = null ) { file_put_contents ( $ path , $ contents ) ; if ( $ owner ) { $ this -> chown ( $ path , $ owner ) ; } } | Write to the given file . |
42,258 | function append ( $ path , $ contents , $ owner = null ) { file_put_contents ( $ path , $ contents , FILE_APPEND ) ; if ( $ owner ) { $ this -> chown ( $ path , $ owner ) ; } } | Append the contents to the given file . |
42,259 | function copyAsUser ( $ from , $ to ) { copy ( $ from , $ to ) ; $ this -> chown ( $ to , user ( ) ) ; } | Copy the given file to a new location for the non - root user . |
42,260 | function symlink ( $ target , $ link ) { if ( $ this -> exists ( $ link ) ) { $ this -> unlink ( $ link ) ; } symlink ( $ target , $ link ) ; } | Create a symlink to the given target . |
42,261 | function symlinkAsUser ( $ target , $ link ) { if ( $ this -> exists ( $ link ) ) { $ this -> unlink ( $ link ) ; } CommandLineFacade :: runAsUser ( 'ln -s ' . escapeshellarg ( $ target ) . ' ' . escapeshellarg ( $ link ) ) ; } | Create a symlink to the given target for the non - root user . |
42,262 | function removeBrokenLinksAt ( $ path ) { collect ( $ this -> scandir ( $ path ) ) -> filter ( function ( $ file ) use ( $ path ) { return $ this -> isBrokenLink ( $ path . '/' . $ file ) ; } ) -> each ( function ( $ file ) use ( $ path ) { $ this -> unlink ( $ path . '/' . $ file ) ; } ) ; } | Remove all of the broken symbolic links at the given path . |
42,263 | function scandir ( $ path ) { return collect ( scandir ( $ path ) ) -> reject ( function ( $ file ) { return in_array ( $ file , [ '.' , '..' ] ) ; } ) -> values ( ) -> all ( ) ; } | Scan the given directory path . |
42,264 | private function checkMageMode ( $ sitePath ) { if ( null !== $ this -> mageMode ) { return ; } if ( ! file_exists ( $ sitePath . '/index.php' ) ) { $ this -> mageMode = 'production' ; return ; } $ mageConfig = [ ] ; if ( file_exists ( $ sitePath . '/app/etc/env.php' ) ) { $ mageConfig = require $ sitePath . '/app/etc/... | Determine the current MAGE_MODE |
42,265 | private function isPubDirectory ( $ sitePath , $ route , $ pub = '' ) { $ sitePath .= '/pub/' ; $ dirs = glob ( $ sitePath . '*' , GLOB_ONLYDIR ) ; $ dirs = str_replace ( $ sitePath , '' , $ dirs ) ; foreach ( $ dirs as $ dir ) { if ( strpos ( $ route , $ pub . $ dir . '/' ) === 0 ) { return true ; } } return false ; } | Checks to see if route is referencing any directory inside pub . This is a dynamic check so that if any new directories are added to pub this driver will not need to be updated . |
42,266 | public function addSubdirectory ( $ sitePath ) { $ paths = array_map ( function ( $ subDir ) use ( $ sitePath ) { return "$sitePath/$subDir" ; } , $ this -> possibleSubdirectories ( ) ) ; $ foundPaths = array_filter ( $ paths , function ( $ path ) { return file_exists ( $ path ) ; } ) ; if ( ! empty ( $ foundPaths ) ) ... | Add any matching subdirectory to the site path . |
42,267 | public function execute ( $ timeout = 10 ) { $ req = array ( 'operations' => $ this -> operations ) ; $ result = $ this -> MailChimp -> post ( 'batches' , $ req , $ timeout ) ; if ( $ result && isset ( $ result [ 'id' ] ) ) { $ this -> batch_id = $ result [ 'id' ] ; } return $ result ; } | Execute the batch request |
42,268 | public function check_status ( $ batch_id = null ) { if ( $ batch_id === null && $ this -> batch_id ) { $ batch_id = $ this -> batch_id ; } return $ this -> MailChimp -> get ( 'batches/' . $ batch_id ) ; } | Check the status of a batch request . If the current instance of the Batch object was used to make the request the batch_id is already known and is therefore optional . |
42,269 | private function queueOperation ( $ http_verb , $ id , $ method , $ args = null ) { $ operation = array ( 'operation_id' => $ id , 'method' => $ http_verb , 'path' => $ method , ) ; if ( $ args ) { if ( $ http_verb == 'GET' ) { $ key = 'params' ; $ operation [ $ key ] = $ args ; } else { $ key = 'body' ; $ operation [ ... | Add an operation to the internal queue . |
42,270 | public static function subscribe ( $ event , callable $ callback ) { if ( ! isset ( self :: $ eventSubscriptions [ $ event ] ) ) self :: $ eventSubscriptions [ $ event ] = array ( ) ; self :: $ eventSubscriptions [ $ event ] [ ] = $ callback ; self :: receive ( ) ; } | Subscribe to an incoming webhook request . The callback will be invoked when a matching webhook is received . |
42,271 | public static function receive ( $ input = null ) { if ( is_null ( $ input ) ) { if ( self :: $ receivedWebhook !== null ) { $ input = self :: $ receivedWebhook ; } else { $ input = file_get_contents ( "php://input" ) ; } } if ( ! is_null ( $ input ) && $ input != '' ) { return self :: processWebhook ( $ input ) ; } re... | Retrieve the incoming webhook request as sent . |
42,272 | private static function processWebhook ( $ input ) { self :: $ receivedWebhook = $ input ; parse_str ( $ input , $ result ) ; if ( $ result && isset ( $ result [ 'type' ] ) ) { self :: dispatchWebhookEvent ( $ result [ 'type' ] , $ result [ 'data' ] ) ; return $ result ; } return false ; } | Process the raw request into a PHP array and dispatch any matching subscription callbacks |
42,273 | public function delete ( $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { return $ this -> makeRequest ( 'delete' , $ method , $ args , $ timeout ) ; } | Make an HTTP DELETE request - for deleting data |
42,274 | public function get ( $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { return $ this -> makeRequest ( 'get' , $ method , $ args , $ timeout ) ; } | Make an HTTP GET request - for retrieving data |
42,275 | public function patch ( $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { return $ this -> makeRequest ( 'patch' , $ method , $ args , $ timeout ) ; } | Make an HTTP PATCH request - for performing partial updates |
42,276 | public function post ( $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { return $ this -> makeRequest ( 'post' , $ method , $ args , $ timeout ) ; } | Make an HTTP POST request - for creating and updating items |
42,277 | public function put ( $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { return $ this -> makeRequest ( 'put' , $ method , $ args , $ timeout ) ; } | Make an HTTP PUT request - for creating new items |
42,278 | private function makeRequest ( $ http_verb , $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { $ url = $ this -> api_endpoint . '/' . $ method ; $ response = $ this -> prepareStateForRequest ( $ http_verb , $ method , $ url , $ timeout ) ; $ httpHeader = array ( 'Accept: application/vnd.api+json' , 'Conte... | Performs the underlying HTTP request . Not very exciting . |
42,279 | private function getHeadersAsArray ( $ headersAsString ) { $ headers = array ( ) ; foreach ( explode ( "\r\n" , $ headersAsString ) as $ i => $ line ) { if ( preg_match ( '/HTTP\/[1-2]/' , substr ( $ line , 0 , 7 ) ) === 1 ) { continue ; } $ line = trim ( $ line ) ; if ( empty ( $ line ) ) { continue ; } list ( $ key ,... | Get the HTTP headers as an array of header - name = > header - value pairs . |
42,280 | private function getLinkHeaderAsArray ( $ linkHeaderAsString ) { $ urls = array ( ) ; if ( preg_match_all ( '/<(.*?)>\s*;\s*rel="(.*?)"\s*/' , $ linkHeaderAsString , $ matches ) ) { foreach ( $ matches [ 2 ] as $ i => $ relName ) { $ urls [ $ relName ] = $ matches [ 1 ] [ $ i ] ; } } return $ urls ; } | Extract all rel = > URL pairs from the provided Link header value |
42,281 | private function attachRequestPayload ( & $ ch , $ data ) { $ encoded = json_encode ( $ data ) ; $ this -> last_request [ 'body' ] = $ encoded ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ encoded ) ; } | Encode the data and attach it to the request |
42,282 | private function formatResponse ( $ response ) { $ this -> last_response = $ response ; if ( ! empty ( $ response [ 'body' ] ) ) { return json_decode ( $ response [ 'body' ] , true ) ; } return false ; } | Decode the response and format any error messages for debugging |
42,283 | private function setResponseState ( $ response , $ responseContent , $ ch ) { if ( $ responseContent === false ) { $ this -> last_error = curl_error ( $ ch ) ; } else { $ headerSize = $ response [ 'headers' ] [ 'header_size' ] ; $ response [ 'httpHeaders' ] = $ this -> getHeadersAsArray ( substr ( $ responseContent , 0... | Do post - request formatting and setting state from the response |
42,284 | private function determineSuccess ( $ response , $ formattedResponse , $ timeout ) { $ status = $ this -> findHTTPStatus ( $ response , $ formattedResponse ) ; if ( $ status >= 200 && $ status <= 299 ) { $ this -> request_successful = true ; return true ; } if ( isset ( $ formattedResponse [ 'detail' ] ) ) { $ this -> ... | Check if the response was successful or a failure . If it failed store the error . |
42,285 | private function findHTTPStatus ( $ response , $ formattedResponse ) { if ( ! empty ( $ response [ 'headers' ] ) && isset ( $ response [ 'headers' ] [ 'http_code' ] ) ) { return ( int ) $ response [ 'headers' ] [ 'http_code' ] ; } if ( ! empty ( $ response [ 'body' ] ) && isset ( $ formattedResponse [ 'status' ] ) ) { ... | Find the HTTP status code from the headers or API response body |
42,286 | protected function removeCallback ( $ response ) { if ( false !== strpos ( $ response , 'callback' ) ) { $ lpos = strpos ( $ response , '(' ) ; $ rpos = strrpos ( $ response , ')' ) ; $ response = substr ( $ response , $ lpos + 1 , $ rpos - $ lpos - 1 ) ; } return $ response ; } | Remove the fucking callback parentheses . |
42,287 | protected function createDefaultRequest ( ) { $ request = Request :: createFromGlobals ( ) ; $ session = new Session ( ) ; $ request -> setSession ( $ session ) ; return $ request ; } | Create default request instance . |
42,288 | protected function getOAuthUrl ( $ state ) { $ queries = [ 'appid' => $ this -> clientId , 'redirect_uri' => $ this -> redirectUrl , 'response_type' => 'code' , 'scope' => $ this -> formatScopes ( $ this -> scopes , $ this -> scopeSeparator ) , 'agentid' => $ this -> agentId , 'state' => $ state , ] ; return sprintf ( ... | OAuth url . |
42,289 | protected function getQrConnectUrl ( $ state ) { $ queries = [ 'appid' => $ this -> clientId , 'agentid' => $ this -> agentId , 'redirect_uri' => $ this -> redirectUrl , 'state' => $ state , ] ; return 'https://open.work.weixin.qq.com/wwopen/sso/qrConnect?' . http_build_query ( $ queries ) ; } | Qr connect url . |
42,290 | protected function getUserInfo ( AccessTokenInterface $ token ) { $ response = $ this -> getHttpClient ( ) -> get ( 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo' , [ 'query' => array_filter ( [ 'access_token' => $ token -> getToken ( ) , 'code' => $ this -> getCode ( ) , ] ) , ] ) ; return json_decode ( $ resp... | Get user base info . |
42,291 | protected function getUserDetail ( AccessTokenInterface $ token , $ ticket ) { $ response = $ this -> getHttpClient ( ) -> post ( 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail' , [ 'query' => [ 'access_token' => $ token -> getToken ( ) , ] , 'json' => [ 'user_ticket' => $ ticket , ] , ] ) ; return json_decode... | Get user detail info . |
42,292 | protected function getCodeFields ( $ state = null ) { $ fields = array_merge ( [ 'client_id' => $ this -> clientId , 'redirect_uri' => $ this -> redirectUrl , 'scope' => $ this -> formatScopes ( $ this -> scopes , $ this -> scopeSeparator ) , 'response_type' => 'code' , ] , $ this -> parameters ) ; if ( $ this -> usesS... | Get the GET parameters for the code request . |
42,293 | protected function parseAccessToken ( $ body ) { if ( ! is_array ( $ body ) ) { $ body = json_decode ( $ body , true ) ; } if ( empty ( $ body [ 'access_token' ] ) ) { throw new AuthorizeFailedException ( 'Authorize Failed: ' . json_encode ( $ body , JSON_UNESCAPED_UNICODE ) , $ body ) ; } return new AccessToken ( $ bo... | Get the access token from the token response body . |
42,294 | protected function makeState ( ) { if ( ! $ this -> request -> hasSession ( ) ) { return false ; } $ state = sha1 ( uniqid ( mt_rand ( 1 , 1000000 ) , true ) ) ; $ session = $ this -> request -> getSession ( ) ; if ( is_callable ( [ $ session , 'put' ] ) ) { $ session -> put ( 'state' , $ state ) ; } elseif ( is_callab... | Put state to session storage and return it . |
42,295 | function init ( ) { $ this -> ch = curl_init ( ) ; if ( $ this -> failonerror ) { curl_setopt ( $ this -> ch , CURLOPT_FAILONERROR , true ) ; } curl_setopt ( $ this -> ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ this -> ch , CURLOPT_ENCODING , 'gzip, deflate' ) ; curl_setopt ( $ this -> ch , CURLOPT_SSL_VERI... | Init Curl session |
42,296 | function setUserAgent ( $ useragent = null ) { $ this -> userAgent = $ useragent ; curl_setopt ( $ this -> ch , CURLOPT_USERAGENT , $ useragent ) ; } | Set client s useragent |
42,297 | function post ( $ url , $ postdata , $ ip = null , $ timeout = 10 ) { curl_setopt ( $ this -> ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ this -> ch , CURLOPT_RETURNTRANSFER , true ) ; if ( $ ip ) { if ( $ this -> debug ) { echo "Binding to ip $ip\n" ; } curl_setopt ( $ this -> ch , CURLOPT_INTERFACE , $ ip ) ; } curl... | Send post data to target URL return data returned from url or false if error occured |
42,298 | function get ( $ url , $ ip = null , $ timeout = 5 ) { curl_setopt ( $ this -> ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ this -> ch , CURLOPT_HTTPGET , true ) ; curl_setopt ( $ this -> ch , CURLOPT_RETURNTRANSFER , true ) ; if ( empty ( $ this -> reqHeader [ 'User-Agent' ] ) ) { curl_setopt ( $ this -> ch , CURLOPT_... | fetch data from target URL return data returned from url or false if error occured |
42,299 | function download ( $ url , $ fp , $ ip = null , $ timeout = 5 ) { curl_setopt ( $ this -> ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ this -> ch , CURLOPT_HTTPGET , true ) ; curl_setopt ( $ this -> ch , CURLOPT_FILE , $ fp ) ; if ( $ ip ) { if ( $ this -> debug ) { echo "Binding to ip $ip\n" ; } curl_setopt ( $ this ... | Fetch data from target URL and store it directly to file |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.