repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.loadInstalledPaths
private function loadInstalledPaths() { if ($this->isPHPCodeSnifferInstalled() === true) { $this->processExecutor->execute( sprintf( 'phpcs --config-show %s', self::PHPCS_CONFIG_KEY ), $output, $this->composer->getConfig()->get('bin-dir') ); $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output); $phpcsInstalledPaths = trim($phpcsInstalledPaths); if ($phpcsInstalledPaths !== '') { $this->installedPaths = explode(',', $phpcsInstalledPaths); } } }
php
private function loadInstalledPaths() { if ($this->isPHPCodeSnifferInstalled() === true) { $this->processExecutor->execute( sprintf( 'phpcs --config-show %s', self::PHPCS_CONFIG_KEY ), $output, $this->composer->getConfig()->get('bin-dir') ); $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output); $phpcsInstalledPaths = trim($phpcsInstalledPaths); if ($phpcsInstalledPaths !== '') { $this->installedPaths = explode(',', $phpcsInstalledPaths); } } }
[ "private", "function", "loadInstalledPaths", "(", ")", "{", "if", "(", "$", "this", "->", "isPHPCodeSnifferInstalled", "(", ")", "===", "true", ")", "{", "$", "this", "->", "processExecutor", "->", "execute", "(", "sprintf", "(", "'phpcs --config-show %s'", ",...
Load all paths from PHP_CodeSniffer into an array. @throws LogicException @throws ProcessFailedException @throws RuntimeException
[ "Load", "all", "paths", "from", "PHP_CodeSniffer", "into", "an", "array", "." ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L193-L212
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.saveInstalledPaths
private function saveInstalledPaths() { // Check if we found installed paths to set. if (count($this->installedPaths) !== 0) { $paths = implode(',', $this->installedPaths); $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); $configMessage = sprintf( 'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>', self::PHPCS_CONFIG_KEY, $paths ); } else { // Delete the installed paths if none were found. $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); $configMessage = sprintf( 'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>', self::PHPCS_CONFIG_KEY ); } $this->io->write($configMessage); $this->processExecutor->execute( sprintf( 'phpcs %s', implode(' ', $arguments) ), $configResult, $this->composer->getConfig()->get('bin-dir') ); if ($this->io->isVerbose() && !empty($configResult)) { $this->io->write(sprintf('<info>%s</info>', $configResult)); } }
php
private function saveInstalledPaths() { // Check if we found installed paths to set. if (count($this->installedPaths) !== 0) { $paths = implode(',', $this->installedPaths); $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); $configMessage = sprintf( 'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>', self::PHPCS_CONFIG_KEY, $paths ); } else { // Delete the installed paths if none were found. $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); $configMessage = sprintf( 'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>', self::PHPCS_CONFIG_KEY ); } $this->io->write($configMessage); $this->processExecutor->execute( sprintf( 'phpcs %s', implode(' ', $arguments) ), $configResult, $this->composer->getConfig()->get('bin-dir') ); if ($this->io->isVerbose() && !empty($configResult)) { $this->io->write(sprintf('<info>%s</info>', $configResult)); } }
[ "private", "function", "saveInstalledPaths", "(", ")", "{", "// Check if we found installed paths to set.", "if", "(", "count", "(", "$", "this", "->", "installedPaths", ")", "!==", "0", ")", "{", "$", "paths", "=", "implode", "(", "','", ",", "$", "this", "...
Save all coding standard paths back into PHP_CodeSniffer @throws LogicException @throws ProcessFailedException @throws RuntimeException
[ "Save", "all", "coding", "standard", "paths", "back", "into", "PHP_CodeSniffer" ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L221-L255
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.cleanInstalledPaths
private function cleanInstalledPaths() { $changes = false; foreach ($this->installedPaths as $key => $path) { // This might be a relative path as well $alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path); if ((is_dir($path) === false || is_readable($path) === false) && (is_dir($alternativePath) === false || is_readable($alternativePath) === false) ) { unset($this->installedPaths[$key]); $changes = true; } } return $changes; }
php
private function cleanInstalledPaths() { $changes = false; foreach ($this->installedPaths as $key => $path) { // This might be a relative path as well $alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path); if ((is_dir($path) === false || is_readable($path) === false) && (is_dir($alternativePath) === false || is_readable($alternativePath) === false) ) { unset($this->installedPaths[$key]); $changes = true; } } return $changes; }
[ "private", "function", "cleanInstalledPaths", "(", ")", "{", "$", "changes", "=", "false", ";", "foreach", "(", "$", "this", "->", "installedPaths", "as", "$", "key", "=>", "$", "path", ")", "{", "// This might be a relative path as well", "$", "alternativePath"...
Iterate trough all known paths and check if they are still valid. If path does not exists, is not an directory or isn't readable, the path is removed from the list. @return bool True if changes where made, false otherwise
[ "Iterate", "trough", "all", "known", "paths", "and", "check", "if", "they", "are", "still", "valid", "." ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L265-L280
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.updateInstalledPaths
private function updateInstalledPaths() { $changes = false; $searchPaths = array($this->cwd); $codingStandardPackages = $this->getPHPCodingStandardPackages(); foreach ($codingStandardPackages as $package) { $installPath = $this->composer->getInstallationManager()->getInstallPath($package); if ($this->filesystem->isAbsolutePath($installPath) === false) { $installPath = $this->filesystem->normalizePath( $this->cwd . DIRECTORY_SEPARATOR . $installPath ); } $searchPaths[] = $installPath; } $finder = new Finder(); $finder->files() ->depth('<= ' . $this->getMaxDepth()) ->depth('>= ' . $this->getMinDepth()) ->ignoreUnreadableDirs() ->ignoreVCS(true) ->in($searchPaths) ->name('ruleset.xml'); // Process each found possible ruleset. foreach ($finder as $ruleset) { $standardsPath = $ruleset->getPath(); // Pick the directory above the directory containing the standard, unless this is the project root. if ($standardsPath !== $this->cwd) { $standardsPath = dirname($standardsPath); } // Use relative paths for local project repositories. if ($this->isRunningGlobally() === false) { $standardsPath = $this->filesystem->findShortestPath( $this->getPHPCodeSnifferInstallPath(), $standardsPath, true ); } // De-duplicate and add when directory is not configured. if (in_array($standardsPath, $this->installedPaths, true) === false) { $this->installedPaths[] = $standardsPath; $changes = true; } } return $changes; }
php
private function updateInstalledPaths() { $changes = false; $searchPaths = array($this->cwd); $codingStandardPackages = $this->getPHPCodingStandardPackages(); foreach ($codingStandardPackages as $package) { $installPath = $this->composer->getInstallationManager()->getInstallPath($package); if ($this->filesystem->isAbsolutePath($installPath) === false) { $installPath = $this->filesystem->normalizePath( $this->cwd . DIRECTORY_SEPARATOR . $installPath ); } $searchPaths[] = $installPath; } $finder = new Finder(); $finder->files() ->depth('<= ' . $this->getMaxDepth()) ->depth('>= ' . $this->getMinDepth()) ->ignoreUnreadableDirs() ->ignoreVCS(true) ->in($searchPaths) ->name('ruleset.xml'); // Process each found possible ruleset. foreach ($finder as $ruleset) { $standardsPath = $ruleset->getPath(); // Pick the directory above the directory containing the standard, unless this is the project root. if ($standardsPath !== $this->cwd) { $standardsPath = dirname($standardsPath); } // Use relative paths for local project repositories. if ($this->isRunningGlobally() === false) { $standardsPath = $this->filesystem->findShortestPath( $this->getPHPCodeSnifferInstallPath(), $standardsPath, true ); } // De-duplicate and add when directory is not configured. if (in_array($standardsPath, $this->installedPaths, true) === false) { $this->installedPaths[] = $standardsPath; $changes = true; } } return $changes; }
[ "private", "function", "updateInstalledPaths", "(", ")", "{", "$", "changes", "=", "false", ";", "$", "searchPaths", "=", "array", "(", "$", "this", "->", "cwd", ")", ";", "$", "codingStandardPackages", "=", "$", "this", "->", "getPHPCodingStandardPackages", ...
Check all installed packages (including the root package) against the installed paths from PHP_CodeSniffer and add the missing ones. @return bool True if changes where made, false otherwise @throws \InvalidArgumentException @throws \RuntimeException
[ "Check", "all", "installed", "packages", "(", "including", "the", "root", "package", ")", "against", "the", "installed", "paths", "from", "PHP_CodeSniffer", "and", "add", "the", "missing", "ones", "." ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L291-L342
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.getPHPCodingStandardPackages
private function getPHPCodingStandardPackages() { $codingStandardPackages = array_filter( $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), function (PackageInterface $package) { if ($package instanceof AliasPackage) { return false; } return $package->getType() === Plugin::PACKAGE_TYPE; } ); if (! $this->composer->getPackage() instanceof RootpackageInterface && $this->composer->getPackage()->getType() === self::PACKAGE_TYPE ) { $codingStandardPackages[] = $this->composer->getPackage(); } return $codingStandardPackages; }
php
private function getPHPCodingStandardPackages() { $codingStandardPackages = array_filter( $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), function (PackageInterface $package) { if ($package instanceof AliasPackage) { return false; } return $package->getType() === Plugin::PACKAGE_TYPE; } ); if (! $this->composer->getPackage() instanceof RootpackageInterface && $this->composer->getPackage()->getType() === self::PACKAGE_TYPE ) { $codingStandardPackages[] = $this->composer->getPackage(); } return $codingStandardPackages; }
[ "private", "function", "getPHPCodingStandardPackages", "(", ")", "{", "$", "codingStandardPackages", "=", "array_filter", "(", "$", "this", "->", "composer", "->", "getRepositoryManager", "(", ")", "->", "getLocalRepository", "(", ")", "->", "getPackages", "(", ")...
Iterates through Composers' local repository looking for valid Coding Standard packages. If the package is the RootPackage (the one the plugin is installed into), the package is ignored for now since it needs a different install path logic. @return array Composer packages containing coding standard(s)
[ "Iterates", "through", "Composers", "local", "repository", "looking", "for", "valid", "Coding", "Standard", "packages", "." ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L353-L372
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.getPHPCodeSnifferPackage
private function getPHPCodeSnifferPackage($versionConstraint = null) { $packages = $this ->composer ->getRepositoryManager() ->getLocalRepository() ->findPackages(self::PACKAGE_NAME, $versionConstraint); return array_shift($packages); }
php
private function getPHPCodeSnifferPackage($versionConstraint = null) { $packages = $this ->composer ->getRepositoryManager() ->getLocalRepository() ->findPackages(self::PACKAGE_NAME, $versionConstraint); return array_shift($packages); }
[ "private", "function", "getPHPCodeSnifferPackage", "(", "$", "versionConstraint", "=", "null", ")", "{", "$", "packages", "=", "$", "this", "->", "composer", "->", "getRepositoryManager", "(", ")", "->", "getLocalRepository", "(", ")", "->", "findPackages", "(",...
Searches for the installed PHP_CodeSniffer Composer package @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against @return PackageInterface|null
[ "Searches", "for", "the", "installed", "PHP_CodeSniffer", "Composer", "package" ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L381-L390
Dealerdirect/phpcodesniffer-composer-installer
src/Plugin.php
Plugin.getMaxDepth
private function getMaxDepth() { $maxDepth = 3; $extra = $this->composer->getPackage()->getExtra(); if (array_key_exists(self::KEY_MAX_DEPTH, $extra)) { $maxDepth = $extra[self::KEY_MAX_DEPTH]; $minDepth = $this->getMinDepth(); if (is_int($maxDepth) === false /* Must be an integer */ || $maxDepth <= $minDepth /* Larger than the minimum */ || is_float($maxDepth) === true /* Within the boundaries of integer */ ) { $message = vsprintf( self::MESSAGE_ERROR_WRONG_MAX_DEPTH, array( 'key' => self::KEY_MAX_DEPTH, 'min' => $minDepth, 'given' => var_export($maxDepth, true), ) ); throw new \InvalidArgumentException($message); } } return $maxDepth; }
php
private function getMaxDepth() { $maxDepth = 3; $extra = $this->composer->getPackage()->getExtra(); if (array_key_exists(self::KEY_MAX_DEPTH, $extra)) { $maxDepth = $extra[self::KEY_MAX_DEPTH]; $minDepth = $this->getMinDepth(); if (is_int($maxDepth) === false /* Must be an integer */ || $maxDepth <= $minDepth /* Larger than the minimum */ || is_float($maxDepth) === true /* Within the boundaries of integer */ ) { $message = vsprintf( self::MESSAGE_ERROR_WRONG_MAX_DEPTH, array( 'key' => self::KEY_MAX_DEPTH, 'min' => $minDepth, 'given' => var_export($maxDepth, true), ) ); throw new \InvalidArgumentException($message); } } return $maxDepth; }
[ "private", "function", "getMaxDepth", "(", ")", "{", "$", "maxDepth", "=", "3", ";", "$", "extra", "=", "$", "this", "->", "composer", "->", "getPackage", "(", ")", "->", "getExtra", "(", ")", ";", "if", "(", "array_key_exists", "(", "self", "::", "K...
Determines the maximum search depth when searching for Coding Standards. @return int @throws \InvalidArgumentException
[ "Determines", "the", "maximum", "search", "depth", "when", "searching", "for", "Coding", "Standards", "." ]
train
https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/e749410375ff6fb7a040a68878c656c2e610b132/src/Plugin.php#L434-L462
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.getReportArray
public static function getReportArray() { $composerArray = self::getComposerArray(); $packages = self::getPackagesAndDependencies($composerArray['require']); $version = self::getDecomposerVersion($composerArray, $packages); $reportArray['Server Environment'] = self::getServerEnv(); $reportArray['Laravel Environment'] = self::getLaravelEnv($version); $reportArray['Installed Packages'] = self::getPackagesArray($composerArray['require']); empty(self::getExtraStats()) ? '' : $reportArray['Extra Stats'] = self::getExtraStats(); return $reportArray; }
php
public static function getReportArray() { $composerArray = self::getComposerArray(); $packages = self::getPackagesAndDependencies($composerArray['require']); $version = self::getDecomposerVersion($composerArray, $packages); $reportArray['Server Environment'] = self::getServerEnv(); $reportArray['Laravel Environment'] = self::getLaravelEnv($version); $reportArray['Installed Packages'] = self::getPackagesArray($composerArray['require']); empty(self::getExtraStats()) ? '' : $reportArray['Extra Stats'] = self::getExtraStats(); return $reportArray; }
[ "public", "static", "function", "getReportArray", "(", ")", "{", "$", "composerArray", "=", "self", "::", "getComposerArray", "(", ")", ";", "$", "packages", "=", "self", "::", "getPackagesAndDependencies", "(", "$", "composerArray", "[", "'require'", "]", ")"...
Get the Decomposer system report as a PHP array @return array
[ "Get", "the", "Decomposer", "system", "report", "as", "a", "PHP", "array" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L30-L43
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.getPackagesAndDependencies
public static function getPackagesAndDependencies($packagesArray) { foreach ($packagesArray as $key => $value) { $packageFile = base_path("/vendor/{$key}/composer.json"); if ($key !== 'php' && file_exists($packageFile)) { $json2 = file_get_contents($packageFile); $dependenciesArray = json_decode($json2, true); $dependencies = array_key_exists('require', $dependenciesArray) ? $dependenciesArray['require'] : 'No dependencies'; $devDependencies = array_key_exists('require-dev', $dependenciesArray) ? $dependenciesArray['require-dev'] : 'No dependencies'; $packages[] = [ 'name' => $key, 'version' => $value, 'dependencies' => $dependencies, 'dev-dependencies' => $devDependencies ]; } } return $packages; }
php
public static function getPackagesAndDependencies($packagesArray) { foreach ($packagesArray as $key => $value) { $packageFile = base_path("/vendor/{$key}/composer.json"); if ($key !== 'php' && file_exists($packageFile)) { $json2 = file_get_contents($packageFile); $dependenciesArray = json_decode($json2, true); $dependencies = array_key_exists('require', $dependenciesArray) ? $dependenciesArray['require'] : 'No dependencies'; $devDependencies = array_key_exists('require-dev', $dependenciesArray) ? $dependenciesArray['require-dev'] : 'No dependencies'; $packages[] = [ 'name' => $key, 'version' => $value, 'dependencies' => $dependencies, 'dev-dependencies' => $devDependencies ]; } } return $packages; }
[ "public", "static", "function", "getPackagesAndDependencies", "(", "$", "packagesArray", ")", "{", "foreach", "(", "$", "packagesArray", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "packageFile", "=", "base_path", "(", "\"/vendor/{$key}/composer.json\"", ...
Get Installed packages & their Dependencies @param $packagesArray @return array
[ "Get", "Installed", "packages", "&", "their", "Dependencies" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L134-L155
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.getLaravelEnv
public static function getLaravelEnv($decomposerVersion) { return array_merge([ 'version' => App::version(), 'timezone' => config('app.timezone'), 'debug_mode' => config('app.debug'), 'storage_dir_writable' => is_writable(base_path('storage')), 'cache_dir_writable' => is_writable(base_path('bootstrap/cache')), 'decomposer_version' => $decomposerVersion, 'app_size' => self::sizeFormat(self::folderSize(base_path())) ], self::getLaravelExtras()); }
php
public static function getLaravelEnv($decomposerVersion) { return array_merge([ 'version' => App::version(), 'timezone' => config('app.timezone'), 'debug_mode' => config('app.debug'), 'storage_dir_writable' => is_writable(base_path('storage')), 'cache_dir_writable' => is_writable(base_path('bootstrap/cache')), 'decomposer_version' => $decomposerVersion, 'app_size' => self::sizeFormat(self::folderSize(base_path())) ], self::getLaravelExtras()); }
[ "public", "static", "function", "getLaravelEnv", "(", "$", "decomposerVersion", ")", "{", "return", "array_merge", "(", "[", "'version'", "=>", "App", "::", "version", "(", ")", ",", "'timezone'", "=>", "config", "(", "'app.timezone'", ")", ",", "'debug_mode'"...
Get Laravel environment details @param $decomposerVersion @return array
[ "Get", "Laravel", "environment", "details" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L164-L175
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.getServerEnv
public static function getServerEnv() { return array_merge([ 'version' => phpversion(), 'server_software' => $_SERVER['SERVER_SOFTWARE'], 'server_os' => php_uname(), 'database_connection_name' => config('database.default'), 'ssl_installed' => self::checkSslIsInstalled(), 'cache_driver' => config('cache.default'), 'session_driver' => config('session.driver'), 'openssl' => extension_loaded('openssl'), 'pdo' => extension_loaded('pdo'), 'mbstring' => extension_loaded('mbstring'), 'tokenizer' => extension_loaded('tokenizer'), 'xml' => extension_loaded('xml') ], self::getServerExtras()); }
php
public static function getServerEnv() { return array_merge([ 'version' => phpversion(), 'server_software' => $_SERVER['SERVER_SOFTWARE'], 'server_os' => php_uname(), 'database_connection_name' => config('database.default'), 'ssl_installed' => self::checkSslIsInstalled(), 'cache_driver' => config('cache.default'), 'session_driver' => config('session.driver'), 'openssl' => extension_loaded('openssl'), 'pdo' => extension_loaded('pdo'), 'mbstring' => extension_loaded('mbstring'), 'tokenizer' => extension_loaded('tokenizer'), 'xml' => extension_loaded('xml') ], self::getServerExtras()); }
[ "public", "static", "function", "getServerEnv", "(", ")", "{", "return", "array_merge", "(", "[", "'version'", "=>", "phpversion", "(", ")", ",", "'server_software'", "=>", "$", "_SERVER", "[", "'SERVER_SOFTWARE'", "]", ",", "'server_os'", "=>", "php_uname", "...
Get PHP/Server environment details @return array
[ "Get", "PHP", "/", "Server", "environment", "details" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L181-L197
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.getPackagesArray
private static function getPackagesArray($composerRequireArray) { $packagesArray = self::getPackagesAndDependencies($composerRequireArray); foreach ($packagesArray as $packageArray) { $packages[$packageArray['name']] = $packageArray['version']; } return $packages; }
php
private static function getPackagesArray($composerRequireArray) { $packagesArray = self::getPackagesAndDependencies($composerRequireArray); foreach ($packagesArray as $packageArray) { $packages[$packageArray['name']] = $packageArray['version']; } return $packages; }
[ "private", "static", "function", "getPackagesArray", "(", "$", "composerRequireArray", ")", "{", "$", "packagesArray", "=", "self", "::", "getPackagesAndDependencies", "(", "$", "composerRequireArray", ")", ";", "foreach", "(", "$", "packagesArray", "as", "$", "pa...
Get Installed packages & their version numbers as an associative array @param $packagesArray @return array
[ "Get", "Installed", "packages", "&", "their", "version", "numbers", "as", "an", "associative", "array" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L206-L215
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.getDecomposerVersion
public static function getDecomposerVersion($composerArray, $packages) { if (isset($composerArray['require'][self::PACKAGE_NAME])) { return $composerArray['require'][self::PACKAGE_NAME]; } if (isset($composerArray['require-dev'][self::PACKAGE_NAME])) { return $composerArray['require-dev'][self::PACKAGE_NAME]; } foreach ($packages as $package) { if (isset($package['dependencies'][self::PACKAGE_NAME])) { return $package['dependencies'][self::PACKAGE_NAME]; } if (isset($package['dev-dependencies'][self::PACKAGE_NAME])) { return $package['dev-dependencies'][self::PACKAGE_NAME]; } } return 'unknown'; }
php
public static function getDecomposerVersion($composerArray, $packages) { if (isset($composerArray['require'][self::PACKAGE_NAME])) { return $composerArray['require'][self::PACKAGE_NAME]; } if (isset($composerArray['require-dev'][self::PACKAGE_NAME])) { return $composerArray['require-dev'][self::PACKAGE_NAME]; } foreach ($packages as $package) { if (isset($package['dependencies'][self::PACKAGE_NAME])) { return $package['dependencies'][self::PACKAGE_NAME]; } if (isset($package['dev-dependencies'][self::PACKAGE_NAME])) { return $package['dev-dependencies'][self::PACKAGE_NAME]; } } return 'unknown'; }
[ "public", "static", "function", "getDecomposerVersion", "(", "$", "composerArray", ",", "$", "packages", ")", "{", "if", "(", "isset", "(", "$", "composerArray", "[", "'require'", "]", "[", "self", "::", "PACKAGE_NAME", "]", ")", ")", "{", "return", "$", ...
Get current installed Decomposer version @param $composerArray @param $packages @return string
[ "Get", "current", "installed", "Decomposer", "version" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L225-L246
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.folderSize
private static function folderSize($dir) { $size = 0; foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) { $size += is_file($each) ? filesize($each) : self::folderSize($each); } return $size; }
php
private static function folderSize($dir) { $size = 0; foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) { $size += is_file($each) ? filesize($each) : self::folderSize($each); } return $size; }
[ "private", "static", "function", "folderSize", "(", "$", "dir", ")", "{", "$", "size", "=", "0", ";", "foreach", "(", "glob", "(", "rtrim", "(", "$", "dir", ",", "'/'", ")", ".", "'/*'", ",", "GLOB_NOSORT", ")", "as", "$", "each", ")", "{", "$", ...
Get the laravel app's size @param $dir @return int
[ "Get", "the", "laravel", "app", "s", "size" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L265-L272
lubusIN/laravel-decomposer
src/Decomposer.php
Decomposer.sizeFormat
private static function sizeFormat($bytes) { $kb = 1024; $mb = $kb * 1024; $gb = $mb * 1024; $tb = $gb * 1024; if (($bytes >= 0) && ($bytes < $kb)) { return $bytes . ' B'; } elseif (($bytes >= $kb) && ($bytes < $mb)) { return ceil($bytes / $kb) . ' KB'; } elseif (($bytes >= $mb) && ($bytes < $gb)) { return ceil($bytes / $mb) . ' MB'; } elseif (($bytes >= $gb) && ($bytes < $tb)) { return ceil($bytes / $gb) . ' GB'; } elseif ($bytes >= $tb) { return ceil($bytes / $tb) . ' TB'; } else { return $bytes . ' B'; } }
php
private static function sizeFormat($bytes) { $kb = 1024; $mb = $kb * 1024; $gb = $mb * 1024; $tb = $gb * 1024; if (($bytes >= 0) && ($bytes < $kb)) { return $bytes . ' B'; } elseif (($bytes >= $kb) && ($bytes < $mb)) { return ceil($bytes / $kb) . ' KB'; } elseif (($bytes >= $mb) && ($bytes < $gb)) { return ceil($bytes / $mb) . ' MB'; } elseif (($bytes >= $gb) && ($bytes < $tb)) { return ceil($bytes / $gb) . ' GB'; } elseif ($bytes >= $tb) { return ceil($bytes / $tb) . ' TB'; } else { return $bytes . ' B'; } }
[ "private", "static", "function", "sizeFormat", "(", "$", "bytes", ")", "{", "$", "kb", "=", "1024", ";", "$", "mb", "=", "$", "kb", "*", "1024", ";", "$", "gb", "=", "$", "mb", "*", "1024", ";", "$", "tb", "=", "$", "gb", "*", "1024", ";", ...
Format the app's size in correct units @param $bytes @return string
[ "Format", "the", "app", "s", "size", "in", "correct", "units" ]
train
https://github.com/lubusIN/laravel-decomposer/blob/e060fff7aefacd8664be0f53132986ecf481a802/src/Decomposer.php#L281-L301
GrahamCampbell/Laravel-Flysystem
src/Adapters/AzureConnector.php
AzureConnector.getClient
protected function getClient(array $auth) { $endpoint = sprintf('DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', $auth['account-name'], $auth['api-key']); return ServicesBuilder::getInstance()->createBlobService($endpoint); }
php
protected function getClient(array $auth) { $endpoint = sprintf('DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', $auth['account-name'], $auth['api-key']); return ServicesBuilder::getInstance()->createBlobService($endpoint); }
[ "protected", "function", "getClient", "(", "array", "$", "auth", ")", "{", "$", "endpoint", "=", "sprintf", "(", "'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s'", ",", "$", "auth", "[", "'account-name'", "]", ",", "$", "auth", "[", "'api-key'", "]",...
Get the azure client. @param string[] $auth @return \MicrosoftAzure\Storage\Blob\Internal\IBlob
[ "Get", "the", "azure", "client", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/AzureConnector.php#L70-L75
GrahamCampbell/Laravel-Flysystem
src/FlysystemManager.php
FlysystemManager.getConnectionConfig
public function getConnectionConfig(string $name = null) { $name = $name ?: $this->getDefaultConnection(); $connections = $this->config->get($this->getConfigName().'.connections'); if (!is_array($config = array_get($connections, $name)) && !$config) { throw new InvalidArgumentException("Adapter [$name] not configured."); } if (is_string($cache = array_get($config, 'cache'))) { $config['cache'] = $this->getCacheConfig($cache); } $config['name'] = $name; return $config; }
php
public function getConnectionConfig(string $name = null) { $name = $name ?: $this->getDefaultConnection(); $connections = $this->config->get($this->getConfigName().'.connections'); if (!is_array($config = array_get($connections, $name)) && !$config) { throw new InvalidArgumentException("Adapter [$name] not configured."); } if (is_string($cache = array_get($config, 'cache'))) { $config['cache'] = $this->getCacheConfig($cache); } $config['name'] = $name; return $config; }
[ "public", "function", "getConnectionConfig", "(", "string", "$", "name", "=", "null", ")", "{", "$", "name", "=", "$", "name", "?", ":", "$", "this", "->", "getDefaultConnection", "(", ")", ";", "$", "connections", "=", "$", "this", "->", "config", "->...
Get the configuration for a connection. @param string|null $name @throws \InvalidArgumentException @return array
[ "Get", "the", "configuration", "for", "a", "connection", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemManager.php#L104-L121
GrahamCampbell/Laravel-Flysystem
src/FlysystemManager.php
FlysystemManager.getCacheConfig
protected function getCacheConfig(string $name) { $cache = $this->config->get($this->getConfigName().'.cache'); if (!is_array($config = array_get($cache, $name)) && !$config) { throw new InvalidArgumentException("Cache [$name] not configured."); } $config['name'] = $name; return $config; }
php
protected function getCacheConfig(string $name) { $cache = $this->config->get($this->getConfigName().'.cache'); if (!is_array($config = array_get($cache, $name)) && !$config) { throw new InvalidArgumentException("Cache [$name] not configured."); } $config['name'] = $name; return $config; }
[ "protected", "function", "getCacheConfig", "(", "string", "$", "name", ")", "{", "$", "cache", "=", "$", "this", "->", "config", "->", "get", "(", "$", "this", "->", "getConfigName", "(", ")", ".", "'.cache'", ")", ";", "if", "(", "!", "is_array", "(...
Get the cache configuration. @param string $name @throws \InvalidArgumentException @return array
[ "Get", "the", "cache", "configuration", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemManager.php#L132-L143
GrahamCampbell/Laravel-Flysystem
src/Cache/AdapterConnector.php
AdapterConnector.getClient
protected function getClient(array $config) { $name = array_get($config, 'adapter'); $config = $this->manager->getConnectionConfig($name); return $this->manager->getFactory()->createAdapter($config); }
php
protected function getClient(array $config) { $name = array_get($config, 'adapter'); $config = $this->manager->getConnectionConfig($name); return $this->manager->getFactory()->createAdapter($config); }
[ "protected", "function", "getClient", "(", "array", "$", "config", ")", "{", "$", "name", "=", "array_get", "(", "$", "config", ",", "'adapter'", ")", ";", "$", "config", "=", "$", "this", "->", "manager", "->", "getConnectionConfig", "(", "$", "name", ...
Get the cache client. @param string[] $config @return \League\Flysystem\AdapterInterface
[ "Get", "the", "cache", "client", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/AdapterConnector.php#L88-L94
GrahamCampbell/Laravel-Flysystem
src/Cache/AdapterConnector.php
AdapterConnector.getAdapter
protected function getAdapter(AdapterInterface $client, array $config) { $file = array_get($config, 'file', 'flysystem.json'); $ttl = array_get($config, 'ttl'); return new Adapter($client, $file, $ttl); }
php
protected function getAdapter(AdapterInterface $client, array $config) { $file = array_get($config, 'file', 'flysystem.json'); $ttl = array_get($config, 'ttl'); return new Adapter($client, $file, $ttl); }
[ "protected", "function", "getAdapter", "(", "AdapterInterface", "$", "client", ",", "array", "$", "config", ")", "{", "$", "file", "=", "array_get", "(", "$", "config", ",", "'file'", ",", "'flysystem.json'", ")", ";", "$", "ttl", "=", "array_get", "(", ...
Get the adapter cache adapter. @param \League\Flysystem\AdapterInterface $client @param string[] $config @return \League\Flysystem\Cached\Storage\Adapter
[ "Get", "the", "adapter", "cache", "adapter", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/AdapterConnector.php#L104-L110
GrahamCampbell/Laravel-Flysystem
src/Cache/IlluminateConnector.php
IlluminateConnector.connect
public function connect(array $config) { $client = $this->getClient($config); return $this->getAdapter($client, $config); }
php
public function connect(array $config) { $client = $this->getClient($config); return $this->getAdapter($client, $config); }
[ "public", "function", "connect", "(", "array", "$", "config", ")", "{", "$", "client", "=", "$", "this", "->", "getClient", "(", "$", "config", ")", ";", "return", "$", "this", "->", "getAdapter", "(", "$", "client", ",", "$", "config", ")", ";", "...
Establish a cache connection. @param string[] $config @return \GrahamCampbell\Flysystem\Cache\IlluminateCache
[ "Establish", "a", "cache", "connection", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/IlluminateConnector.php#L53-L58
GrahamCampbell/Laravel-Flysystem
src/Cache/IlluminateConnector.php
IlluminateConnector.getClient
protected function getClient(array $config) { $name = array_get($config, 'connector'); return $this->cache->driver($name)->getStore(); }
php
protected function getClient(array $config) { $name = array_get($config, 'connector'); return $this->cache->driver($name)->getStore(); }
[ "protected", "function", "getClient", "(", "array", "$", "config", ")", "{", "$", "name", "=", "array_get", "(", "$", "config", ",", "'connector'", ")", ";", "return", "$", "this", "->", "cache", "->", "driver", "(", "$", "name", ")", "->", "getStore",...
Get the cache client. @param string[] $config @return \Illuminate\Contracts\Cache\Store
[ "Get", "the", "cache", "client", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/IlluminateConnector.php#L67-L72
GrahamCampbell/Laravel-Flysystem
src/Cache/IlluminateConnector.php
IlluminateConnector.getAdapter
protected function getAdapter(Store $client, array $config) { $key = array_get($config, 'key', 'flysystem'); $ttl = array_get($config, 'ttl'); return new IlluminateCache($client, $key, $ttl); }
php
protected function getAdapter(Store $client, array $config) { $key = array_get($config, 'key', 'flysystem'); $ttl = array_get($config, 'ttl'); return new IlluminateCache($client, $key, $ttl); }
[ "protected", "function", "getAdapter", "(", "Store", "$", "client", ",", "array", "$", "config", ")", "{", "$", "key", "=", "array_get", "(", "$", "config", ",", "'key'", ",", "'flysystem'", ")", ";", "$", "ttl", "=", "array_get", "(", "$", "config", ...
Get the illuminate cache adapter. @param \Illuminate\Contracts\Cache\Store $client @param string[] $config @return \GrahamCampbell\Flysystem\Cache\IlluminateCache
[ "Get", "the", "illuminate", "cache", "adapter", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/IlluminateConnector.php#L82-L88
GrahamCampbell/Laravel-Flysystem
src/Adapters/AwsS3Connector.php
AwsS3Connector.getAuth
protected function getAuth(array $config) { if (!array_key_exists('version', $config)) { throw new InvalidArgumentException('The awss3 connector requires version configuration.'); } if (!array_key_exists('region', $config)) { throw new InvalidArgumentException('The awss3 connector requires region configuration.'); } $auth = [ 'region' => $config['region'], 'version' => $config['version'], ]; if (isset($config['key'])) { if (!array_key_exists('secret', $config)) { throw new InvalidArgumentException('The awss3 connector requires authentication.'); } $auth['credentials'] = array_only($config, ['key', 'secret']); } if (array_key_exists('bucket_endpoint', $config)) { $auth['bucket_endpoint'] = $config['bucket_endpoint']; } if (array_key_exists('calculate_md5', $config)) { $auth['calculate_md5'] = $config['calculate_md5']; } if (array_key_exists('scheme', $config)) { $auth['scheme'] = $config['scheme']; } if (array_key_exists('endpoint', $config)) { $auth['endpoint'] = $config['endpoint']; } return $auth; }
php
protected function getAuth(array $config) { if (!array_key_exists('version', $config)) { throw new InvalidArgumentException('The awss3 connector requires version configuration.'); } if (!array_key_exists('region', $config)) { throw new InvalidArgumentException('The awss3 connector requires region configuration.'); } $auth = [ 'region' => $config['region'], 'version' => $config['version'], ]; if (isset($config['key'])) { if (!array_key_exists('secret', $config)) { throw new InvalidArgumentException('The awss3 connector requires authentication.'); } $auth['credentials'] = array_only($config, ['key', 'secret']); } if (array_key_exists('bucket_endpoint', $config)) { $auth['bucket_endpoint'] = $config['bucket_endpoint']; } if (array_key_exists('calculate_md5', $config)) { $auth['calculate_md5'] = $config['calculate_md5']; } if (array_key_exists('scheme', $config)) { $auth['scheme'] = $config['scheme']; } if (array_key_exists('endpoint', $config)) { $auth['endpoint'] = $config['endpoint']; } return $auth; }
[ "protected", "function", "getAuth", "(", "array", "$", "config", ")", "{", "if", "(", "!", "array_key_exists", "(", "'version'", ",", "$", "config", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The awss3 connector requires version configuration....
Get the authentication data. @param string[] $config @throws \InvalidArgumentException @return string[]
[ "Get", "the", "authentication", "data", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/AwsS3Connector.php#L54-L93
GrahamCampbell/Laravel-Flysystem
src/Adapters/AwsS3Connector.php
AwsS3Connector.getConfig
protected function getConfig(array $config) { if (!array_key_exists('prefix', $config)) { $config['prefix'] = null; } if (!array_key_exists('bucket', $config)) { throw new InvalidArgumentException('The awss3 connector requires bucket configuration.'); } return array_only($config, ['bucket', 'prefix']); }
php
protected function getConfig(array $config) { if (!array_key_exists('prefix', $config)) { $config['prefix'] = null; } if (!array_key_exists('bucket', $config)) { throw new InvalidArgumentException('The awss3 connector requires bucket configuration.'); } return array_only($config, ['bucket', 'prefix']); }
[ "protected", "function", "getConfig", "(", "array", "$", "config", ")", "{", "if", "(", "!", "array_key_exists", "(", "'prefix'", ",", "$", "config", ")", ")", "{", "$", "config", "[", "'prefix'", "]", "=", "null", ";", "}", "if", "(", "!", "array_ke...
Get the configuration. @param string[] $config @throws \InvalidArgumentException @return array
[ "Get", "the", "configuration", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/AwsS3Connector.php#L116-L127
GrahamCampbell/Laravel-Flysystem
src/Adapters/RackspaceConnector.php
RackspaceConnector.connect
public function connect(array $config) { $auth = $this->getAuth($config); $client = $this->getClient($auth); return $this->getAdapter($client); }
php
public function connect(array $config) { $auth = $this->getAuth($config); $client = $this->getClient($auth); return $this->getAdapter($client); }
[ "public", "function", "connect", "(", "array", "$", "config", ")", "{", "$", "auth", "=", "$", "this", "->", "getAuth", "(", "$", "config", ")", ";", "$", "client", "=", "$", "this", "->", "getClient", "(", "$", "auth", ")", ";", "return", "$", "...
Establish an adapter connection. @codeCoverageIgnore @param string[] $config @return \League\Flysystem\Rackspace\RackspaceAdapter
[ "Establish", "an", "adapter", "connection", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/RackspaceConnector.php#L38-L44
GrahamCampbell/Laravel-Flysystem
src/Adapters/RackspaceConnector.php
RackspaceConnector.getAuth
protected function getAuth(array $config) { if (!array_key_exists('username', $config) || !array_key_exists('apiKey', $config)) { throw new InvalidArgumentException('The rackspace connector requires authentication.'); } if (!array_key_exists('endpoint', $config)) { throw new InvalidArgumentException('The rackspace connector requires endpoint configuration.'); } if (!array_key_exists('region', $config)) { throw new InvalidArgumentException('The rackspace connector requires region configuration.'); } if (!array_key_exists('container', $config)) { throw new InvalidArgumentException('The rackspace connector requires container configuration.'); } return array_only($config, ['username', 'apiKey', 'endpoint', 'region', 'container', 'internal']); }
php
protected function getAuth(array $config) { if (!array_key_exists('username', $config) || !array_key_exists('apiKey', $config)) { throw new InvalidArgumentException('The rackspace connector requires authentication.'); } if (!array_key_exists('endpoint', $config)) { throw new InvalidArgumentException('The rackspace connector requires endpoint configuration.'); } if (!array_key_exists('region', $config)) { throw new InvalidArgumentException('The rackspace connector requires region configuration.'); } if (!array_key_exists('container', $config)) { throw new InvalidArgumentException('The rackspace connector requires container configuration.'); } return array_only($config, ['username', 'apiKey', 'endpoint', 'region', 'container', 'internal']); }
[ "protected", "function", "getAuth", "(", "array", "$", "config", ")", "{", "if", "(", "!", "array_key_exists", "(", "'username'", ",", "$", "config", ")", "||", "!", "array_key_exists", "(", "'apiKey'", ",", "$", "config", ")", ")", "{", "throw", "new", ...
Get the authentication data. @param string[] $config @throws \InvalidArgumentException @return string[]
[ "Get", "the", "authentication", "data", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/RackspaceConnector.php#L55-L74
GrahamCampbell/Laravel-Flysystem
src/Adapters/RackspaceConnector.php
RackspaceConnector.getClient
protected function getClient(array $auth) { $client = new OpenStackRackspace($auth['endpoint'], [ 'username' => $auth['username'], 'apiKey' => $auth['apiKey'], ]); $urlType = array_get($auth, 'internal', false) ? 'internalURL' : 'publicURL'; return $client->objectStoreService('cloudFiles', $auth['region'], $urlType)->getContainer($auth['container']); }
php
protected function getClient(array $auth) { $client = new OpenStackRackspace($auth['endpoint'], [ 'username' => $auth['username'], 'apiKey' => $auth['apiKey'], ]); $urlType = array_get($auth, 'internal', false) ? 'internalURL' : 'publicURL'; return $client->objectStoreService('cloudFiles', $auth['region'], $urlType)->getContainer($auth['container']); }
[ "protected", "function", "getClient", "(", "array", "$", "auth", ")", "{", "$", "client", "=", "new", "OpenStackRackspace", "(", "$", "auth", "[", "'endpoint'", "]", ",", "[", "'username'", "=>", "$", "auth", "[", "'username'", "]", ",", "'apiKey'", "=>"...
Get the rackspace client. @param string[] $auth @return \OpenCloud\ObjectStore\Resource\Container
[ "Get", "the", "rackspace", "client", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/RackspaceConnector.php#L83-L93
GrahamCampbell/Laravel-Flysystem
src/Adapters/LocalConnector.php
LocalConnector.getAdapter
protected function getAdapter(array $config) { // Pull parameters from config and set defaults for optional values $path = $config['path']; $writeFlags = array_get($config, 'write_flags', LOCK_EX); $linkHandling = array_get($config, 'link_handling', Local::DISALLOW_LINKS); $permissions = array_get($config, 'permissions', []); return new Local($path, $writeFlags, $linkHandling, $permissions); }
php
protected function getAdapter(array $config) { // Pull parameters from config and set defaults for optional values $path = $config['path']; $writeFlags = array_get($config, 'write_flags', LOCK_EX); $linkHandling = array_get($config, 'link_handling', Local::DISALLOW_LINKS); $permissions = array_get($config, 'permissions', []); return new Local($path, $writeFlags, $linkHandling, $permissions); }
[ "protected", "function", "getAdapter", "(", "array", "$", "config", ")", "{", "// Pull parameters from config and set defaults for optional values", "$", "path", "=", "$", "config", "[", "'path'", "]", ";", "$", "writeFlags", "=", "array_get", "(", "$", "config", ...
Get the local adapter. @param string[] $config @return \League\Flysystem\Adapter\Local
[ "Get", "the", "local", "adapter", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/LocalConnector.php#L66-L75
GrahamCampbell/Laravel-Flysystem
src/Adapters/GridFSConnector.php
GridFSConnector.getAdapter
protected function getAdapter(MongoClient $client, array $config) { $fs = $client->selectDB($config['database'])->getGridFS(); return new GridFSAdapter($fs); }
php
protected function getAdapter(MongoClient $client, array $config) { $fs = $client->selectDB($config['database'])->getGridFS(); return new GridFSAdapter($fs); }
[ "protected", "function", "getAdapter", "(", "MongoClient", "$", "client", ",", "array", "$", "config", ")", "{", "$", "fs", "=", "$", "client", "->", "selectDB", "(", "$", "config", "[", "'database'", "]", ")", "->", "getGridFS", "(", ")", ";", "return...
Get the gridfs adapter. @param \MongoClient $client @param string[] $config @return \League\Flysystem\GridFS\GridFSAdapter
[ "Get", "the", "gridfs", "adapter", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/GridFSConnector.php#L98-L103
GrahamCampbell/Laravel-Flysystem
src/Cache/ConnectionFactory.php
ConnectionFactory.make
public function make(array $config, FlysystemManager $manager) { return $this->createConnector($config, $manager)->connect($config); }
php
public function make(array $config, FlysystemManager $manager) { return $this->createConnector($config, $manager)->connect($config); }
[ "public", "function", "make", "(", "array", "$", "config", ",", "FlysystemManager", "$", "manager", ")", "{", "return", "$", "this", "->", "createConnector", "(", "$", "config", ",", "$", "manager", ")", "->", "connect", "(", "$", "config", ")", ";", "...
Establish a cache connection. @param array $config @param \GrahamCampbell\Flysystem\FlysystemManager $manager @return \League\Flysystem\Cached\CacheInterface
[ "Establish", "a", "cache", "connection", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/ConnectionFactory.php#L54-L57
GrahamCampbell/Laravel-Flysystem
src/Cache/ConnectionFactory.php
ConnectionFactory.createConnector
public function createConnector(array $config, FlysystemManager $manager) { if (!isset($config['driver'])) { throw new InvalidArgumentException('A driver must be specified.'); } switch ($config['driver']) { case 'illuminate': return new IlluminateConnector($this->cache); case 'adapter': return new AdapterConnector($manager); } throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."); }
php
public function createConnector(array $config, FlysystemManager $manager) { if (!isset($config['driver'])) { throw new InvalidArgumentException('A driver must be specified.'); } switch ($config['driver']) { case 'illuminate': return new IlluminateConnector($this->cache); case 'adapter': return new AdapterConnector($manager); } throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."); }
[ "public", "function", "createConnector", "(", "array", "$", "config", ",", "FlysystemManager", "$", "manager", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'driver'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'A ...
Create a connector instance based on the configuration. @param array $config @param \GrahamCampbell\Flysystem\FlysystemManager $manager @throws \InvalidArgumentException @return \GrahamCampbell\Manager\ConnectorInterface
[ "Create", "a", "connector", "instance", "based", "on", "the", "configuration", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/ConnectionFactory.php#L69-L83
GrahamCampbell/Laravel-Flysystem
src/Cache/IlluminateCache.php
IlluminateCache.load
public function load() { $contents = $this->client->get($this->key); if ($contents !== null) { $this->setFromStorage($contents); } }
php
public function load() { $contents = $this->client->get($this->key); if ($contents !== null) { $this->setFromStorage($contents); } }
[ "public", "function", "load", "(", ")", "{", "$", "contents", "=", "$", "this", "->", "client", "->", "get", "(", "$", "this", "->", "key", ")", ";", "if", "(", "$", "contents", "!==", "null", ")", "{", "$", "this", "->", "setFromStorage", "(", "...
Load the cache. @return void
[ "Load", "the", "cache", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/IlluminateCache.php#L69-L76
GrahamCampbell/Laravel-Flysystem
src/Cache/IlluminateCache.php
IlluminateCache.save
public function save() { $contents = $this->getForStorage(); if ($this->ttl !== null) { $this->client->put($this->key, $contents, $this->ttl); } else { $this->client->forever($this->key, $contents); } }
php
public function save() { $contents = $this->getForStorage(); if ($this->ttl !== null) { $this->client->put($this->key, $contents, $this->ttl); } else { $this->client->forever($this->key, $contents); } }
[ "public", "function", "save", "(", ")", "{", "$", "contents", "=", "$", "this", "->", "getForStorage", "(", ")", ";", "if", "(", "$", "this", "->", "ttl", "!==", "null", ")", "{", "$", "this", "->", "client", "->", "put", "(", "$", "this", "->", ...
Store the cache. @return void
[ "Store", "the", "cache", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Cache/IlluminateCache.php#L83-L92
GrahamCampbell/Laravel-Flysystem
src/FlysystemServiceProvider.php
FlysystemServiceProvider.register
public function register() { $this->registerAdapterFactory(); $this->registerCacheFactory(); $this->registerFlysystemFactory(); $this->registerManager(); $this->registerBindings(); }
php
public function register() { $this->registerAdapterFactory(); $this->registerCacheFactory(); $this->registerFlysystemFactory(); $this->registerManager(); $this->registerBindings(); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "registerAdapterFactory", "(", ")", ";", "$", "this", "->", "registerCacheFactory", "(", ")", ";", "$", "this", "->", "registerFlysystemFactory", "(", ")", ";", "$", "this", "->", "registe...
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemServiceProvider.php#L65-L72
GrahamCampbell/Laravel-Flysystem
src/FlysystemServiceProvider.php
FlysystemServiceProvider.registerCacheFactory
protected function registerCacheFactory() { $this->app->singleton('flysystem.cachefactory', function (Container $app) { $cache = $app['cache']; return new CacheFactory($cache); }); $this->app->alias('flysystem.cachefactory', CacheFactory::class); }
php
protected function registerCacheFactory() { $this->app->singleton('flysystem.cachefactory', function (Container $app) { $cache = $app['cache']; return new CacheFactory($cache); }); $this->app->alias('flysystem.cachefactory', CacheFactory::class); }
[ "protected", "function", "registerCacheFactory", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'flysystem.cachefactory'", ",", "function", "(", "Container", "$", "app", ")", "{", "$", "cache", "=", "$", "app", "[", "'cache'", "]", ";", ...
Register the cache factory class. @return void
[ "Register", "the", "cache", "factory", "class", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemServiceProvider.php#L93-L102
GrahamCampbell/Laravel-Flysystem
src/FlysystemServiceProvider.php
FlysystemServiceProvider.registerFlysystemFactory
protected function registerFlysystemFactory() { $this->app->singleton('flysystem.factory', function (Container $app) { $adapter = $app['flysystem.adapterfactory']; $cache = $app['flysystem.cachefactory']; return new FlysystemFactory($adapter, $cache); }); $this->app->alias('flysystem.factory', FlysystemFactory::class); }
php
protected function registerFlysystemFactory() { $this->app->singleton('flysystem.factory', function (Container $app) { $adapter = $app['flysystem.adapterfactory']; $cache = $app['flysystem.cachefactory']; return new FlysystemFactory($adapter, $cache); }); $this->app->alias('flysystem.factory', FlysystemFactory::class); }
[ "protected", "function", "registerFlysystemFactory", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'flysystem.factory'", ",", "function", "(", "Container", "$", "app", ")", "{", "$", "adapter", "=", "$", "app", "[", "'flysystem.adapterfacto...
Register the flysystem factory class. @return void
[ "Register", "the", "flysystem", "factory", "class", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemServiceProvider.php#L109-L119
GrahamCampbell/Laravel-Flysystem
src/FlysystemServiceProvider.php
FlysystemServiceProvider.registerManager
protected function registerManager() { $this->app->singleton('flysystem', function (Container $app) { $config = $app['config']; $factory = $app['flysystem.factory']; return new FlysystemManager($config, $factory); }); $this->app->alias('flysystem', FlysystemManager::class); }
php
protected function registerManager() { $this->app->singleton('flysystem', function (Container $app) { $config = $app['config']; $factory = $app['flysystem.factory']; return new FlysystemManager($config, $factory); }); $this->app->alias('flysystem', FlysystemManager::class); }
[ "protected", "function", "registerManager", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'flysystem'", ",", "function", "(", "Container", "$", "app", ")", "{", "$", "config", "=", "$", "app", "[", "'config'", "]", ";", "$", "factor...
Register the manager class. @return void
[ "Register", "the", "manager", "class", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemServiceProvider.php#L126-L136
GrahamCampbell/Laravel-Flysystem
src/FlysystemServiceProvider.php
FlysystemServiceProvider.registerBindings
protected function registerBindings() { $this->app->bind('flysystem.connection', function (Container $app) { $manager = $app['flysystem']; return $manager->connection(); }); $this->app->alias('flysystem.connection', Filesystem::class); $this->app->alias('flysystem.connection', FilesystemInterface::class); }
php
protected function registerBindings() { $this->app->bind('flysystem.connection', function (Container $app) { $manager = $app['flysystem']; return $manager->connection(); }); $this->app->alias('flysystem.connection', Filesystem::class); $this->app->alias('flysystem.connection', FilesystemInterface::class); }
[ "protected", "function", "registerBindings", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'flysystem.connection'", ",", "function", "(", "Container", "$", "app", ")", "{", "$", "manager", "=", "$", "app", "[", "'flysystem'", "]", ";", "re...
Register the bindings. @return void
[ "Register", "the", "bindings", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemServiceProvider.php#L143-L153
GrahamCampbell/Laravel-Flysystem
src/Adapters/ConnectionFactory.php
ConnectionFactory.createConnector
public function createConnector(array $config) { if (!isset($config['driver'])) { throw new InvalidArgumentException('A driver must be specified.'); } switch ($config['driver']) { case 'awss3': return new AwsS3Connector(); case 'azure': return new AzureConnector(); case 'dropbox': return new DropboxConnector(); case 'ftp': return new FtpConnector(); case 'gridfs': return new GridFSConnector(); case 'local': return new LocalConnector(); case 'null': return new NullConnector(); case 'rackspace': return new RackspaceConnector(); case 'sftp': return new SftpConnector(); case 'webdav': return new WebDavConnector(); case 'zip': return new ZipConnector(); } throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."); }
php
public function createConnector(array $config) { if (!isset($config['driver'])) { throw new InvalidArgumentException('A driver must be specified.'); } switch ($config['driver']) { case 'awss3': return new AwsS3Connector(); case 'azure': return new AzureConnector(); case 'dropbox': return new DropboxConnector(); case 'ftp': return new FtpConnector(); case 'gridfs': return new GridFSConnector(); case 'local': return new LocalConnector(); case 'null': return new NullConnector(); case 'rackspace': return new RackspaceConnector(); case 'sftp': return new SftpConnector(); case 'webdav': return new WebDavConnector(); case 'zip': return new ZipConnector(); } throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."); }
[ "public", "function", "createConnector", "(", "array", "$", "config", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'driver'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'A driver must be specified.'", ")", ";", "}",...
Create a connector instance based on the configuration. @param array $config @throws \InvalidArgumentException @return \GrahamCampbell\Manager\ConnectorInterface
[ "Create", "a", "connector", "instance", "based", "on", "the", "configuration", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/Adapters/ConnectionFactory.php#L46-L78
GrahamCampbell/Laravel-Flysystem
src/FlysystemFactory.php
FlysystemFactory.make
public function make(array $config, FlysystemManager $manager) { $adapter = $this->createAdapter($config); if (is_array($cache = array_get($config, 'cache', false))) { $adapter = new CachedAdapter($adapter, $this->createCache($cache, $manager)); } $options = $this->getOptions($config); if (array_get($config, 'eventable', false)) { return new EventableFilesystem($adapter, $options); } return new Filesystem($adapter, $options); }
php
public function make(array $config, FlysystemManager $manager) { $adapter = $this->createAdapter($config); if (is_array($cache = array_get($config, 'cache', false))) { $adapter = new CachedAdapter($adapter, $this->createCache($cache, $manager)); } $options = $this->getOptions($config); if (array_get($config, 'eventable', false)) { return new EventableFilesystem($adapter, $options); } return new Filesystem($adapter, $options); }
[ "public", "function", "make", "(", "array", "$", "config", ",", "FlysystemManager", "$", "manager", ")", "{", "$", "adapter", "=", "$", "this", "->", "createAdapter", "(", "$", "config", ")", ";", "if", "(", "is_array", "(", "$", "cache", "=", "array_g...
Make a new flysystem instance. @param array $config @param \GrahamCampbell\Flysystem\FlysystemManager $manager @return \League\Flysystem\FilesystemInterface
[ "Make", "a", "new", "flysystem", "instance", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemFactory.php#L65-L80
GrahamCampbell/Laravel-Flysystem
src/FlysystemFactory.php
FlysystemFactory.getOptions
protected function getOptions(array $config) { $options = []; if ($visibility = array_get($config, 'visibility')) { $options['visibility'] = $visibility; } if ($pirate = array_get($config, 'pirate')) { $options['disable_asserts'] = $pirate; } return $options; }
php
protected function getOptions(array $config) { $options = []; if ($visibility = array_get($config, 'visibility')) { $options['visibility'] = $visibility; } if ($pirate = array_get($config, 'pirate')) { $options['disable_asserts'] = $pirate; } return $options; }
[ "protected", "function", "getOptions", "(", "array", "$", "config", ")", "{", "$", "options", "=", "[", "]", ";", "if", "(", "$", "visibility", "=", "array_get", "(", "$", "config", ",", "'visibility'", ")", ")", "{", "$", "options", "[", "'visibility'...
Get the flysystem options. @param array $config @return array|null
[ "Get", "the", "flysystem", "options", "." ]
train
https://github.com/GrahamCampbell/Laravel-Flysystem/blob/7de7061ee335fd8d345c50c23cf20287b3314e22/src/FlysystemFactory.php#L116-L129
object-calisthenics/phpcs-calisthenics-rules
src/ObjectCalisthenics/Sniffs/CodeAnalysis/OneObjectOperatorPerLineSniff.php
OneObjectOperatorPerLineSniff.computeLastCallOfAnyFrom
private function computeLastCallOfAnyFrom(array $methods): int { $calls = array_filter($this->callerTokens, function (array $token) use ($methods) { return in_array($token['token']['content'], $methods, true); }); if (count($calls) > 0) { return (int) array_search(end($calls), $this->callerTokens, true); } return -2; }
php
private function computeLastCallOfAnyFrom(array $methods): int { $calls = array_filter($this->callerTokens, function (array $token) use ($methods) { return in_array($token['token']['content'], $methods, true); }); if (count($calls) > 0) { return (int) array_search(end($calls), $this->callerTokens, true); } return -2; }
[ "private", "function", "computeLastCallOfAnyFrom", "(", "array", "$", "methods", ")", ":", "int", "{", "$", "calls", "=", "array_filter", "(", "$", "this", "->", "callerTokens", ",", "function", "(", "array", "$", "token", ")", "use", "(", "$", "methods", ...
@param string[] $methods @return int The last position of the method calls within the callerTokens or -2 if none of the methods has been called
[ "@param", "string", "[]", "$methods" ]
train
https://github.com/object-calisthenics/phpcs-calisthenics-rules/blob/6319ec7f3bb4f5f87775e15d013f9579678c8ef7/src/ObjectCalisthenics/Sniffs/CodeAnalysis/OneObjectOperatorPerLineSniff.php#L187-L197
bvanhoekelen/performance
src/Performance.php
Performance.point
public static function point($label = null, $isMultiplePoint = false) { if( ! static::enableTool() ) return; // Run static::$performance->point($label, $isMultiplePoint); }
php
public static function point($label = null, $isMultiplePoint = false) { if( ! static::enableTool() ) return; // Run static::$performance->point($label, $isMultiplePoint); }
[ "public", "static", "function", "point", "(", "$", "label", "=", "null", ",", "$", "isMultiplePoint", "=", "false", ")", "{", "if", "(", "!", "static", "::", "enableTool", "(", ")", ")", "return", ";", "// Run", "static", "::", "$", "performance", "->"...
Set measuring point X @param string|null $label @param string|null $isMultiplePoint @return void
[ "Set", "measuring", "point", "X" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Performance.php#L45-L52
bvanhoekelen/performance
src/Performance.php
Performance.message
public static function message($message = null, $newLine = true) { if( ! static::enableTool() or ! $message) return; // Run static::$performance->message($message, $newLine); }
php
public static function message($message = null, $newLine = true) { if( ! static::enableTool() or ! $message) return; // Run static::$performance->message($message, $newLine); }
[ "public", "static", "function", "message", "(", "$", "message", "=", "null", ",", "$", "newLine", "=", "true", ")", "{", "if", "(", "!", "static", "::", "enableTool", "(", ")", "or", "!", "$", "message", ")", "return", ";", "// Run", "static", "::", ...
Set a message associated with the point @param string|null $message @param boolean|null $newLine @return void
[ "Set", "a", "message", "associated", "with", "the", "point" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Performance.php#L61-L68
bvanhoekelen/performance
src/Lib/Presenters/Formatter.php
Formatter.memoryToHuman
public function memoryToHuman($bytes, $unit = "", $decimals = 2) { if($bytes <= 0) return '0.00 KB'; $units = [ 'B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8 ]; $value = 0; if ($bytes > 0) { // Generate automatic prefix by bytes // If wrong prefix given if ( ! array_key_exists($unit, $units)) { $pow = floor(log($bytes) / log(1024)); $unit = array_search($pow, $units); } // Calculate byte value by prefix $value = ($bytes / pow(1024, floor($units[$unit]))); } // If decimals is not numeric or decimals is less than 0 if ( ! is_numeric($decimals) || $decimals < 0) $decimals = 2; // Format output return sprintf('%.' . $decimals . 'f ' . $unit, $value); }
php
public function memoryToHuman($bytes, $unit = "", $decimals = 2) { if($bytes <= 0) return '0.00 KB'; $units = [ 'B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8 ]; $value = 0; if ($bytes > 0) { // Generate automatic prefix by bytes // If wrong prefix given if ( ! array_key_exists($unit, $units)) { $pow = floor(log($bytes) / log(1024)); $unit = array_search($pow, $units); } // Calculate byte value by prefix $value = ($bytes / pow(1024, floor($units[$unit]))); } // If decimals is not numeric or decimals is less than 0 if ( ! is_numeric($decimals) || $decimals < 0) $decimals = 2; // Format output return sprintf('%.' . $decimals . 'f ' . $unit, $value); }
[ "public", "function", "memoryToHuman", "(", "$", "bytes", ",", "$", "unit", "=", "\"\"", ",", "$", "decimals", "=", "2", ")", "{", "if", "(", "$", "bytes", "<=", "0", ")", "return", "'0.00 KB'", ";", "$", "units", "=", "[", "'B'", "=>", "0", ",",...
Creatis to cam-gists/memoryuse.php !!
[ "Creatis", "to", "cam", "-", "gists", "/", "memoryuse", ".", "php", "!!" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Presenters/Formatter.php#L43-L81
bvanhoekelen/performance
src/Lib/Presenters/Formatter.php
Formatter.stringPad
public function stringPad($input, $pad_length, $pad_string = ' ') { $count = strlen($input); // Fix μ issues if(strpos($input, 'μ')) $count--; $space = $pad_length - $count; return str_repeat($pad_string, $space) . $input; }
php
public function stringPad($input, $pad_length, $pad_string = ' ') { $count = strlen($input); // Fix μ issues if(strpos($input, 'μ')) $count--; $space = $pad_length - $count; return str_repeat($pad_string, $space) . $input; }
[ "public", "function", "stringPad", "(", "$", "input", ",", "$", "pad_length", ",", "$", "pad_string", "=", "' '", ")", "{", "$", "count", "=", "strlen", "(", "$", "input", ")", ";", "// Fix μ issues", "if", "(", "strpos", "(", "$", "input", ",", "'μ'...
Fix problem 'μs'
[ "Fix", "problem", "μs" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Presenters/Formatter.php#L86-L97
bvanhoekelen/performance
src/Lib/Point.php
Point.finish
public function finish() { $this->setActive(false); $this->setStopTimeIfNotExists(); $this->setStopMemoryUsage(); $this->setMemoryPeak(); $this->setDifferenceTime(); $this->setDifferenceMemory(); }
php
public function finish() { $this->setActive(false); $this->setStopTimeIfNotExists(); $this->setStopMemoryUsage(); $this->setMemoryPeak(); $this->setDifferenceTime(); $this->setDifferenceMemory(); }
[ "public", "function", "finish", "(", ")", "{", "$", "this", "->", "setActive", "(", "false", ")", ";", "$", "this", "->", "setStopTimeIfNotExists", "(", ")", ";", "$", "this", "->", "setStopMemoryUsage", "(", ")", ";", "$", "this", "->", "setMemoryPeak",...
Finish point return void
[ "Finish", "point" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Point.php#L57-L65
bvanhoekelen/performance
src/Lib/Presenters/Calculate.php
Calculate.totalTimeAndMemory
public function totalTimeAndMemory($pointStack) { $max_time = 0; $max_memory = 0; foreach (array_slice($pointStack, 2) as $point) { $max_time += $point->getDifferenceTime(); $max_memory += $point->getDifferenceMemory(); } return new CalculateTotalHolder($max_time, $max_memory, memory_get_peak_usage(true)); }
php
public function totalTimeAndMemory($pointStack) { $max_time = 0; $max_memory = 0; foreach (array_slice($pointStack, 2) as $point) { $max_time += $point->getDifferenceTime(); $max_memory += $point->getDifferenceMemory(); } return new CalculateTotalHolder($max_time, $max_memory, memory_get_peak_usage(true)); }
[ "public", "function", "totalTimeAndMemory", "(", "$", "pointStack", ")", "{", "$", "max_time", "=", "0", ";", "$", "max_memory", "=", "0", ";", "foreach", "(", "array_slice", "(", "$", "pointStack", ",", "2", ")", "as", "$", "point", ")", "{", "$", "...
Calculate total memory return Performance\Lib\Holders\CalculateTotalHolder;
[ "Calculate", "total", "memory" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Presenters/Calculate.php#L12-L24
bvanhoekelen/performance
src/Lib/Presenters/Calculate.php
Calculate.calculatePercentage
public function calculatePercentage($pointDifference, $total) { $upCount = 1000000; if($pointDifference > 0 and $total > 0) return round((100 * $pointDifference * $upCount ) / ($total * $upCount)) ; else return '0'; }
php
public function calculatePercentage($pointDifference, $total) { $upCount = 1000000; if($pointDifference > 0 and $total > 0) return round((100 * $pointDifference * $upCount ) / ($total * $upCount)) ; else return '0'; }
[ "public", "function", "calculatePercentage", "(", "$", "pointDifference", ",", "$", "total", ")", "{", "$", "upCount", "=", "1000000", ";", "if", "(", "$", "pointDifference", ">", "0", "and", "$", "total", ">", "0", ")", "return", "round", "(", "(", "1...
Calculate percentage
[ "Calculate", "percentage" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Presenters/Calculate.php#L29-L37
bvanhoekelen/performance
src/Lib/Holders/QueryLogHolder.php
QueryLogHolder.checkQueryType
protected function checkQueryType() { if(strtolower(substr($this->query, 0, 6)) == 'select') $this->queryType = 'select'; elseif(strtolower(substr($this->query, 0, 6)) == 'insert') $this->queryType = 'insert'; elseif(strtolower(substr($this->query, 0, 6)) == 'delete') $this->queryType = 'delete'; elseif(strtolower(substr($this->query, 0, 6)) == 'update') $this->queryType = 'update'; else $this->queryType = 'unknown'; }
php
protected function checkQueryType() { if(strtolower(substr($this->query, 0, 6)) == 'select') $this->queryType = 'select'; elseif(strtolower(substr($this->query, 0, 6)) == 'insert') $this->queryType = 'insert'; elseif(strtolower(substr($this->query, 0, 6)) == 'delete') $this->queryType = 'delete'; elseif(strtolower(substr($this->query, 0, 6)) == 'update') $this->queryType = 'update'; else $this->queryType = 'unknown'; }
[ "protected", "function", "checkQueryType", "(", ")", "{", "if", "(", "strtolower", "(", "substr", "(", "$", "this", "->", "query", ",", "0", ",", "6", ")", ")", "==", "'select'", ")", "$", "this", "->", "queryType", "=", "'select'", ";", "elseif", "(...
Set query type
[ "Set", "query", "type" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Holders/QueryLogHolder.php#L45-L57
bvanhoekelen/performance
src/Lib/Presenters/WebPresenter.php
WebPresenter.displayForWebAsConsole
protected function displayForWebAsConsole() { $data = []; $data['config'] = $this->config->export(); foreach ($this->pointStack as $point) { $data[] = [ 'label' => $point->getLabel(), 'time' => $this->formatter->timeToHuman( $point->getDifferenceTime() ), 'memory_usage' => $this->formatter->memoryToHuman( $point->getDifferenceMemory() ), 'memory_peak' => $this->formatter->memoryToHuman( $point->getStopMemoryUsage() ), 'raw' => $point->export() ]; } echo "<script>console.log(" . json_encode($data) .")</script>"; }
php
protected function displayForWebAsConsole() { $data = []; $data['config'] = $this->config->export(); foreach ($this->pointStack as $point) { $data[] = [ 'label' => $point->getLabel(), 'time' => $this->formatter->timeToHuman( $point->getDifferenceTime() ), 'memory_usage' => $this->formatter->memoryToHuman( $point->getDifferenceMemory() ), 'memory_peak' => $this->formatter->memoryToHuman( $point->getStopMemoryUsage() ), 'raw' => $point->export() ]; } echo "<script>console.log(" . json_encode($data) .")</script>"; }
[ "protected", "function", "displayForWebAsConsole", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "data", "[", "'config'", "]", "=", "$", "this", "->", "config", "->", "export", "(", ")", ";", "foreach", "(", "$", "this", "->", "pointStack", "a...
Private
[ "Private" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Presenters/WebPresenter.php#L21-L37
bvanhoekelen/performance
src/Lib/Handlers/ConfigHandler.php
ConfigHandler.setDefaultPresenter
protected function setDefaultPresenter() { if (php_sapi_name() == "cli") $this->setPresenter(Presenter::PRESENTER_CONSOLE); else $this->setPresenter(Presenter::PRESENTER_WEB); }
php
protected function setDefaultPresenter() { if (php_sapi_name() == "cli") $this->setPresenter(Presenter::PRESENTER_CONSOLE); else $this->setPresenter(Presenter::PRESENTER_WEB); }
[ "protected", "function", "setDefaultPresenter", "(", ")", "{", "if", "(", "php_sapi_name", "(", ")", "==", "\"cli\"", ")", "$", "this", "->", "setPresenter", "(", "Presenter", "::", "PRESENTER_CONSOLE", ")", ";", "else", "$", "this", "->", "setPresenter", "(...
Print format
[ "Print", "format" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/ConfigHandler.php#L60-L66
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.point
public function point($label = null, $isMultiplePoint = false) { // Check if point already exists if( ! $isMultiplePoint) $this->finishLastPoint(); // Check sub point $this->checkIfPointLabelExists($label, $isMultiplePoint); // Set label if(is_null($label)) $label = 'Task ' . (count($this->pointStack) - 1); // Create point $point = new Point($this->config, $label, $isMultiplePoint); // Create and add point to stack if($isMultiplePoint) { $this->multiPointStack[$label] = $point; $this->message('Start multiple point ' . $label); } else $this->currentPoint = $point; // Start point $point->start(); }
php
public function point($label = null, $isMultiplePoint = false) { // Check if point already exists if( ! $isMultiplePoint) $this->finishLastPoint(); // Check sub point $this->checkIfPointLabelExists($label, $isMultiplePoint); // Set label if(is_null($label)) $label = 'Task ' . (count($this->pointStack) - 1); // Create point $point = new Point($this->config, $label, $isMultiplePoint); // Create and add point to stack if($isMultiplePoint) { $this->multiPointStack[$label] = $point; $this->message('Start multiple point ' . $label); } else $this->currentPoint = $point; // Start point $point->start(); }
[ "public", "function", "point", "(", "$", "label", "=", "null", ",", "$", "isMultiplePoint", "=", "false", ")", "{", "// Check if point already exists", "if", "(", "!", "$", "isMultiplePoint", ")", "$", "this", "->", "finishLastPoint", "(", ")", ";", "// Chec...
Set measuring point X @param string|null $label @param string|null $isMultiplePoint @return void
[ "Set", "measuring", "point", "X" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L75-L102
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.message
public function message($message, $newLine = true) { $point = $this->currentPoint; // Skip if( ! $point or ! $point->isActive()) return; if($newLine) $point->addNewLineMessage($message); else $this->messageToLabel .= $message; }
php
public function message($message, $newLine = true) { $point = $this->currentPoint; // Skip if( ! $point or ! $point->isActive()) return; if($newLine) $point->addNewLineMessage($message); else $this->messageToLabel .= $message; }
[ "public", "function", "message", "(", "$", "message", ",", "$", "newLine", "=", "true", ")", "{", "$", "point", "=", "$", "this", "->", "currentPoint", ";", "// Skip", "if", "(", "!", "$", "point", "or", "!", "$", "point", "->", "isActive", "(", ")...
Set message @param string|null $message @param boolean|null $newLine @return void
[ "Set", "message" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L111-L123
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.finish
public function finish($multiplePointLabel = null) { $this->finishLastPoint(); if($multiplePointLabel) { if( ! isset($this->multiPointStack[$multiplePointLabel])) throw new \InvalidArgumentException("Can't finish multiple point '" . $multiplePointLabel . "'."); $point = $this->multiPointStack[$multiplePointLabel]; unset($this->multiPointStack[$multiplePointLabel]); if($point->isActive()) { // Finish point $point->finish(); // Trigger presenter listener $this->presenter->finishPointTrigger($point); } // $this->pointStack[] = $point; } }
php
public function finish($multiplePointLabel = null) { $this->finishLastPoint(); if($multiplePointLabel) { if( ! isset($this->multiPointStack[$multiplePointLabel])) throw new \InvalidArgumentException("Can't finish multiple point '" . $multiplePointLabel . "'."); $point = $this->multiPointStack[$multiplePointLabel]; unset($this->multiPointStack[$multiplePointLabel]); if($point->isActive()) { // Finish point $point->finish(); // Trigger presenter listener $this->presenter->finishPointTrigger($point); } // $this->pointStack[] = $point; } }
[ "public", "function", "finish", "(", "$", "multiplePointLabel", "=", "null", ")", "{", "$", "this", "->", "finishLastPoint", "(", ")", ";", "if", "(", "$", "multiplePointLabel", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "multiPointStack"...
Finish measuring point X @param string|null $multiplePointLabel @return void
[ "Finish", "measuring", "point", "X" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L131-L155
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.results
public function results() { // Finish all $this->finishLastPoint(); // Finish all multiple points $this->finishAllMultiplePoints(); // Add results to presenter $this->presenter->displayResultsTrigger($this->pointStack); // Return export return $this->export(); }
php
public function results() { // Finish all $this->finishLastPoint(); // Finish all multiple points $this->finishAllMultiplePoints(); // Add results to presenter $this->presenter->displayResultsTrigger($this->pointStack); // Return export return $this->export(); }
[ "public", "function", "results", "(", ")", "{", "// Finish all", "$", "this", "->", "finishLastPoint", "(", ")", ";", "// Finish all multiple points", "$", "this", "->", "finishAllMultiplePoints", "(", ")", ";", "// Add results to presenter", "$", "this", "->", "p...
Return test results @return Performance\Lib\Handlers\ExportHandler
[ "Return", "test", "results" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L162-L175
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.finishLastPoint
protected function finishLastPoint() { // Measurements are more accurate $stopTime = microtime(true); if($this->currentPoint) { // Get point $point = $this->currentPoint; if($point->isActive()) { // Set query log items $this->setQueryLogItemsToPoint($point); // Check if message in label text $this->checkAndSetMessageInToLabel($point); // Finish point $point->setStopTime($stopTime); $point->finish(); $this->pointStack[] = $point; // Trigger presenter listener $this->presenter->finishPointTrigger($point); } } }
php
protected function finishLastPoint() { // Measurements are more accurate $stopTime = microtime(true); if($this->currentPoint) { // Get point $point = $this->currentPoint; if($point->isActive()) { // Set query log items $this->setQueryLogItemsToPoint($point); // Check if message in label text $this->checkAndSetMessageInToLabel($point); // Finish point $point->setStopTime($stopTime); $point->finish(); $this->pointStack[] = $point; // Trigger presenter listener $this->presenter->finishPointTrigger($point); } } }
[ "protected", "function", "finishLastPoint", "(", ")", "{", "// Measurements are more accurate", "$", "stopTime", "=", "microtime", "(", "true", ")", ";", "if", "(", "$", "this", "->", "currentPoint", ")", "{", "// Get point", "$", "point", "=", "$", "this", ...
Finish all point in the stack @return void
[ "Finish", "all", "point", "in", "the", "stack" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L206-L234
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.checkIfPointLabelExists
protected function checkIfPointLabelExists($label, $isMultiPoint) { $labelExists = false; $stack = ($isMultiPoint) ? $this->multiPointStack : $this->pointStack; foreach ($stack as $point) { if($point->getLabel() == $label) { $labelExists = true; break; } } if($labelExists) throw new \InvalidArgumentException("label '" . $label . "' already exists, choose new point label."); }
php
protected function checkIfPointLabelExists($label, $isMultiPoint) { $labelExists = false; $stack = ($isMultiPoint) ? $this->multiPointStack : $this->pointStack; foreach ($stack as $point) { if($point->getLabel() == $label) { $labelExists = true; break; } } if($labelExists) throw new \InvalidArgumentException("label '" . $label . "' already exists, choose new point label."); }
[ "protected", "function", "checkIfPointLabelExists", "(", "$", "label", ",", "$", "isMultiPoint", ")", "{", "$", "labelExists", "=", "false", ";", "$", "stack", "=", "(", "$", "isMultiPoint", ")", "?", "$", "this", "->", "multiPointStack", ":", "$", "this",...
Check if label already exists
[ "Check", "if", "label", "already", "exists" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L258-L273
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.preload
protected function preload() { $this->point( Point::POINT_PRELOAD ); $this->point( Point::POINT_MULTIPLE_PRELOAD, true ); $this->finish(POINT::POINT_MULTIPLE_PRELOAD); // Needs! $this->point( Point::POINT_CALIBRATE ); }
php
protected function preload() { $this->point( Point::POINT_PRELOAD ); $this->point( Point::POINT_MULTIPLE_PRELOAD, true ); $this->finish(POINT::POINT_MULTIPLE_PRELOAD); // Needs! $this->point( Point::POINT_CALIBRATE ); }
[ "protected", "function", "preload", "(", ")", "{", "$", "this", "->", "point", "(", "Point", "::", "POINT_PRELOAD", ")", ";", "$", "this", "->", "point", "(", "Point", "::", "POINT_MULTIPLE_PRELOAD", ",", "true", ")", ";", "$", "this", "->", "finish", ...
Preload wil setup te point class
[ "Preload", "wil", "setup", "te", "point", "class" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L278-L284
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.setConfigQueryLogState
protected function setConfigQueryLogState() { // Check if state is set if( ! is_null($this->config->queryLogState)) return; // Set check query log state if($this->config->isQueryLog()) { $this->config->queryLogState = false; // Check if DB class exists if( ! class_exists('\Illuminate\Support\Facades\DB')) return; // Resister listener try { \Illuminate\Support\Facades\DB::listen(function ($sql) {$this->queryLogStack[] = new QueryLogHolder($sql);}); $this->config->queryLogState = true; } catch (\RuntimeException $e) { try { \Illuminate\Database\Capsule\Manager::listen(function ($sql) {$this->queryLogStack[] = new QueryLogHolder($sql);}); $this->config->queryLogState = true; } catch (\RuntimeException $e) { $this->config->queryLogState = false; } } } }
php
protected function setConfigQueryLogState() { // Check if state is set if( ! is_null($this->config->queryLogState)) return; // Set check query log state if($this->config->isQueryLog()) { $this->config->queryLogState = false; // Check if DB class exists if( ! class_exists('\Illuminate\Support\Facades\DB')) return; // Resister listener try { \Illuminate\Support\Facades\DB::listen(function ($sql) {$this->queryLogStack[] = new QueryLogHolder($sql);}); $this->config->queryLogState = true; } catch (\RuntimeException $e) { try { \Illuminate\Database\Capsule\Manager::listen(function ($sql) {$this->queryLogStack[] = new QueryLogHolder($sql);}); $this->config->queryLogState = true; } catch (\RuntimeException $e) { $this->config->queryLogState = false; } } } }
[ "protected", "function", "setConfigQueryLogState", "(", ")", "{", "// Check if state is set", "if", "(", "!", "is_null", "(", "$", "this", "->", "config", "->", "queryLogState", ")", ")", "return", ";", "// Set check query log state", "if", "(", "$", "this", "->...
Check if query log is possible
[ "Check", "if", "query", "log", "is", "possible" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L289-L324
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.setQueryLogItemsToPoint
protected function setQueryLogItemsToPoint(Point $point) { // Skip if query log is disabled if($this->config->queryLogState !== true) return; $point->setQueryLog($this->queryLogStack); $this->queryLogStack = []; }
php
protected function setQueryLogItemsToPoint(Point $point) { // Skip if query log is disabled if($this->config->queryLogState !== true) return; $point->setQueryLog($this->queryLogStack); $this->queryLogStack = []; }
[ "protected", "function", "setQueryLogItemsToPoint", "(", "Point", "$", "point", ")", "{", "// Skip if query log is disabled", "if", "(", "$", "this", "->", "config", "->", "queryLogState", "!==", "true", ")", "return", ";", "$", "point", "->", "setQueryLog", "("...
Move query log items to point
[ "Move", "query", "log", "items", "to", "point" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L329-L337
bvanhoekelen/performance
src/Lib/Handlers/PerformanceHandler.php
PerformanceHandler.checkAndSetMessageInToLabel
protected function checkAndSetMessageInToLabel(Point $point) { if( ! $this->messageToLabel) return; // Update label $point->setLabel( $point->getLabel() . " - " . $this->messageToLabel); // Reset $this->messageToLabel = ''; }
php
protected function checkAndSetMessageInToLabel(Point $point) { if( ! $this->messageToLabel) return; // Update label $point->setLabel( $point->getLabel() . " - " . $this->messageToLabel); // Reset $this->messageToLabel = ''; }
[ "protected", "function", "checkAndSetMessageInToLabel", "(", "Point", "$", "point", ")", "{", "if", "(", "!", "$", "this", "->", "messageToLabel", ")", "return", ";", "// Update label", "$", "point", "->", "setLabel", "(", "$", "point", "->", "getLabel", "("...
Update point label with message
[ "Update", "point", "label", "with", "message" ]
train
https://github.com/bvanhoekelen/performance/blob/597003c45bda39af79e8fc767eaabb6aa3784408/src/Lib/Handlers/PerformanceHandler.php#L342-L352
PHPIDS/PHPIDS
lib/IDS/Caching/FileCache.php
FileCache.getInstance
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new FileCache($type, $init); } return self::$cachingInstance; }
php
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new FileCache($type, $init); } return self::$cachingInstance; }
[ "public", "static", "function", "getInstance", "(", "$", "type", ",", "$", "init", ")", "{", "if", "(", "!", "self", "::", "$", "cachingInstance", ")", "{", "self", "::", "$", "cachingInstance", "=", "new", "FileCache", "(", "$", "type", ",", "$", "i...
Returns an instance of this class @param string $type caching type @param object $init the IDS_Init object @return object $this
[ "Returns", "an", "instance", "of", "this", "class" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/FileCache.php#L113-L120
PHPIDS/PHPIDS
lib/IDS/Caching/FileCache.php
FileCache.setCache
public function setCache(array $data) { if (!is_writable(preg_replace('/[\/][^\/]+\.[^\/]++$/', null, $this->path))) { throw new \Exception( 'Temp directory ' . htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') . ' seems not writable' ); } if (!$this->isValidFile($this->path)) { $handle = @fopen($this->path, 'w+'); if (!$handle) { throw new \Exception("Cache file couldn't be created"); } $serialized = @serialize($data); if (!$serialized) { throw new \Exception("Cache data couldn't be serialized"); } fwrite($handle, $serialized); fclose($handle); } return $this; }
php
public function setCache(array $data) { if (!is_writable(preg_replace('/[\/][^\/]+\.[^\/]++$/', null, $this->path))) { throw new \Exception( 'Temp directory ' . htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') . ' seems not writable' ); } if (!$this->isValidFile($this->path)) { $handle = @fopen($this->path, 'w+'); if (!$handle) { throw new \Exception("Cache file couldn't be created"); } $serialized = @serialize($data); if (!$serialized) { throw new \Exception("Cache data couldn't be serialized"); } fwrite($handle, $serialized); fclose($handle); } return $this; }
[ "public", "function", "setCache", "(", "array", "$", "data", ")", "{", "if", "(", "!", "is_writable", "(", "preg_replace", "(", "'/[\\/][^\\/]+\\.[^\\/]++$/'", ",", "null", ",", "$", "this", "->", "path", ")", ")", ")", "{", "throw", "new", "\\", "Except...
Writes cache data into the file @param array $data the cache data @throws Exception if cache file couldn't be created @return object $this
[ "Writes", "cache", "data", "into", "the", "file" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/FileCache.php#L130-L157
PHPIDS/PHPIDS
lib/IDS/Caching/FileCache.php
FileCache.getCache
public function getCache() { // make sure filters are parsed again if cache expired if (!$this->isValidFile($this->path)) { return false; } $data = unserialize(file_get_contents($this->path)); return $data; }
php
public function getCache() { // make sure filters are parsed again if cache expired if (!$this->isValidFile($this->path)) { return false; } $data = unserialize(file_get_contents($this->path)); return $data; }
[ "public", "function", "getCache", "(", ")", "{", "// make sure filters are parsed again if cache expired", "if", "(", "!", "$", "this", "->", "isValidFile", "(", "$", "this", "->", "path", ")", ")", "{", "return", "false", ";", "}", "$", "data", "=", "unseri...
Returns the cached data Note that this method returns false if either type or file cache is not set @return mixed cache data or false
[ "Returns", "the", "cached", "data" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/FileCache.php#L167-L177
PHPIDS/PHPIDS
lib/IDS/Caching/MemcachedCache.php
MemcachedCache.getInstance
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new MemcachedCache($type, $init); } return self::$cachingInstance; }
php
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new MemcachedCache($type, $init); } return self::$cachingInstance; }
[ "public", "static", "function", "getInstance", "(", "$", "type", ",", "$", "init", ")", "{", "if", "(", "!", "self", "::", "$", "cachingInstance", ")", "{", "self", "::", "$", "cachingInstance", "=", "new", "MemcachedCache", "(", "$", "type", ",", "$",...
Returns an instance of this class @param string $type caching type @param object $init the IDS_Init object @return object $this
[ "Returns", "an", "instance", "of", "this", "class" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/MemcachedCache.php#L111-L118
PHPIDS/PHPIDS
lib/IDS/Caching/MemcachedCache.php
MemcachedCache.setCache
public function setCache(array $data) { if (!$this->isCached) { $this->memcache->set( $this->config['key_prefix'] . '.storage', $data, false, $this->config['expiration_time'] ); } return $this; }
php
public function setCache(array $data) { if (!$this->isCached) { $this->memcache->set( $this->config['key_prefix'] . '.storage', $data, false, $this->config['expiration_time'] ); } return $this; }
[ "public", "function", "setCache", "(", "array", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "isCached", ")", "{", "$", "this", "->", "memcache", "->", "set", "(", "$", "this", "->", "config", "[", "'key_prefix'", "]", ".", "'.storage'",...
Writes cache data @param array $data the caching data @return object $this
[ "Writes", "cache", "data" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/MemcachedCache.php#L127-L139
PHPIDS/PHPIDS
lib/IDS/Caching/MemcachedCache.php
MemcachedCache.getCache
public function getCache() { $data = $this->memcache->get( $this->config['key_prefix'] . '.storage' ); $this->isCached = !empty($data); return $data; }
php
public function getCache() { $data = $this->memcache->get( $this->config['key_prefix'] . '.storage' ); $this->isCached = !empty($data); return $data; }
[ "public", "function", "getCache", "(", ")", "{", "$", "data", "=", "$", "this", "->", "memcache", "->", "get", "(", "$", "this", "->", "config", "[", "'key_prefix'", "]", ".", "'.storage'", ")", ";", "$", "this", "->", "isCached", "=", "!", "empty", ...
Returns the cached data Note that this method returns false if either type or file cache is not set @return mixed cache data or false
[ "Returns", "the", "cached", "data" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/MemcachedCache.php#L149-L158
PHPIDS/PHPIDS
lib/IDS/Caching/MemcachedCache.php
MemcachedCache.connect
private function connect() { if ($this->config['host'] && $this->config['port']) { // establish the memcache connection $this->memcache = new \Memcache; $this->memcache->pconnect( $this->config['host'], $this->config['port'] ); } else { throw new \Exception('Insufficient connection parameters'); } }
php
private function connect() { if ($this->config['host'] && $this->config['port']) { // establish the memcache connection $this->memcache = new \Memcache; $this->memcache->pconnect( $this->config['host'], $this->config['port'] ); } else { throw new \Exception('Insufficient connection parameters'); } }
[ "private", "function", "connect", "(", ")", "{", "if", "(", "$", "this", "->", "config", "[", "'host'", "]", "&&", "$", "this", "->", "config", "[", "'port'", "]", ")", "{", "// establish the memcache connection", "$", "this", "->", "memcache", "=", "new...
Connect to the memcached server @throws Exception if connection parameters are insufficient @return void
[ "Connect", "to", "the", "memcached", "server" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/MemcachedCache.php#L166-L180
PHPIDS/PHPIDS
lib/IDS/Filter.php
Filter.match
public function match($input) { if (!is_string($input)) { throw new \InvalidArgumentException( 'Invalid argument. Expected a string, received ' . gettype($input) ); } return (bool) preg_match('/' . $this->getRule() . '/ms', strtolower($input)); }
php
public function match($input) { if (!is_string($input)) { throw new \InvalidArgumentException( 'Invalid argument. Expected a string, received ' . gettype($input) ); } return (bool) preg_match('/' . $this->getRule() . '/ms', strtolower($input)); }
[ "public", "function", "match", "(", "$", "input", ")", "{", "if", "(", "!", "is_string", "(", "$", "input", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid argument. Expected a string, received '", ".", "gettype", "(", "$", "inp...
Matches a string against current filter Matches given string against the filter rule the specific object of this class represents @param string $input the string input to match @throws \InvalidArgumentException if argument is no string @return boolean
[ "Matches", "a", "string", "against", "current", "filter" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Filter.php#L112-L121
PHPIDS/PHPIDS
lib/IDS/Caching/DatabaseCache.php
DatabaseCache.getInstance
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new DatabaseCache($type, $init); } return self::$cachingInstance; }
php
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new DatabaseCache($type, $init); } return self::$cachingInstance; }
[ "public", "static", "function", "getInstance", "(", "$", "type", ",", "$", "init", ")", "{", "if", "(", "!", "self", "::", "$", "cachingInstance", ")", "{", "self", "::", "$", "cachingInstance", "=", "new", "DatabaseCache", "(", "$", "type", ",", "$", ...
Returns an instance of this class @static @param string $type caching type @param object $init the IDS_Init object @return object $this
[ "Returns", "an", "instance", "of", "this", "class" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/DatabaseCache.php#L128-L136
PHPIDS/PHPIDS
lib/IDS/Caching/DatabaseCache.php
DatabaseCache.setCache
public function setCache(array $data) { $handle = $this->handle; $rows = $handle->query('SELECT created FROM `' . $this->config['table'].'`'); if (!$rows || $rows->rowCount() === 0) { $this->write($handle, $data); } else { foreach ($rows as $row) { if ((time()-strtotime($row['created'])) > $this->config['expiration_time']) { $this->write($handle, $data); } } } return $this; }
php
public function setCache(array $data) { $handle = $this->handle; $rows = $handle->query('SELECT created FROM `' . $this->config['table'].'`'); if (!$rows || $rows->rowCount() === 0) { $this->write($handle, $data); } else { foreach ($rows as $row) { if ((time()-strtotime($row['created'])) > $this->config['expiration_time']) { $this->write($handle, $data); } } } return $this; }
[ "public", "function", "setCache", "(", "array", "$", "data", ")", "{", "$", "handle", "=", "$", "this", "->", "handle", ";", "$", "rows", "=", "$", "handle", "->", "query", "(", "'SELECT created FROM `'", ".", "$", "this", "->", "config", "[", "'table'...
Writes cache data into the database @param array $data the caching data @throws PDOException if a db error occurred @return object $this
[ "Writes", "cache", "data", "into", "the", "database" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/DatabaseCache.php#L146-L168
PHPIDS/PHPIDS
lib/IDS/Caching/DatabaseCache.php
DatabaseCache.getCache
public function getCache() { try { $handle = $this->handle; $result = $handle->prepare( 'SELECT * FROM `' . $this->config['table'] . '` where type=?' ); $result->execute(array($this->type)); foreach ($result as $row) { return unserialize($row['data']); } } catch (\PDOException $e) { throw new \PDOException('PDOException: ' . $e->getMessage()); } return false; }
php
public function getCache() { try { $handle = $this->handle; $result = $handle->prepare( 'SELECT * FROM `' . $this->config['table'] . '` where type=?' ); $result->execute(array($this->type)); foreach ($result as $row) { return unserialize($row['data']); } } catch (\PDOException $e) { throw new \PDOException('PDOException: ' . $e->getMessage()); } return false; }
[ "public", "function", "getCache", "(", ")", "{", "try", "{", "$", "handle", "=", "$", "this", "->", "handle", ";", "$", "result", "=", "$", "handle", "->", "prepare", "(", "'SELECT * FROM `'", ".", "$", "this", "->", "config", "[", "'table'", "]", "....
Returns the cached data Note that this method returns false if either type or file cache is not set @throws PDOException if a db error occurred @return mixed cache data or false
[ "Returns", "the", "cached", "data" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/DatabaseCache.php#L179-L199
PHPIDS/PHPIDS
lib/IDS/Caching/DatabaseCache.php
DatabaseCache.connect
private function connect() { // validate connection parameters if (!$this->config['wrapper'] || !$this->config['user'] || !$this->config['password'] || !$this->config['table']) { throw new \Exception('Insufficient connection parameters'); } // try to connect try { $handle = new \PDO( $this->config['wrapper'], $this->config['user'], $this->config['password'] ); $handle->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } catch (\PDOException $e) { throw new \PDOException('PDOException: ' . $e->getMessage()); } return $handle; }
php
private function connect() { // validate connection parameters if (!$this->config['wrapper'] || !$this->config['user'] || !$this->config['password'] || !$this->config['table']) { throw new \Exception('Insufficient connection parameters'); } // try to connect try { $handle = new \PDO( $this->config['wrapper'], $this->config['user'], $this->config['password'] ); $handle->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } catch (\PDOException $e) { throw new \PDOException('PDOException: ' . $e->getMessage()); } return $handle; }
[ "private", "function", "connect", "(", ")", "{", "// validate connection parameters", "if", "(", "!", "$", "this", "->", "config", "[", "'wrapper'", "]", "||", "!", "$", "this", "->", "config", "[", "'user'", "]", "||", "!", "$", "this", "->", "config", ...
Connect to database and return a handle @return object PDO @throws Exception if connection parameters are faulty @throws PDOException if a db error occurred
[ "Connect", "to", "database", "and", "return", "a", "handle" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/DatabaseCache.php#L208-L233
PHPIDS/PHPIDS
lib/IDS/Caching/DatabaseCache.php
DatabaseCache.write
private function write($handle, $data) { try { $handle->query('TRUNCATE ' . $this->config['table'].''); $statement = $handle->prepare( 'INSERT INTO `' . $this->config['table'].'` ( type, data, created, modified ) VALUES ( :type, :data, now(), now() )' ); $statement->bindValue( 'type', $handle->quote($this->type) ); $statement->bindValue('data', serialize($data)); if (!$statement->execute()) { throw new \PDOException($statement->errorCode()); } } catch (\PDOException $e) { throw new \PDOException('PDOException: ' . $e->getMessage()); } }
php
private function write($handle, $data) { try { $handle->query('TRUNCATE ' . $this->config['table'].''); $statement = $handle->prepare( 'INSERT INTO `' . $this->config['table'].'` ( type, data, created, modified ) VALUES ( :type, :data, now(), now() )' ); $statement->bindValue( 'type', $handle->quote($this->type) ); $statement->bindValue('data', serialize($data)); if (!$statement->execute()) { throw new \PDOException($statement->errorCode()); } } catch (\PDOException $e) { throw new \PDOException('PDOException: ' . $e->getMessage()); } }
[ "private", "function", "write", "(", "$", "handle", ",", "$", "data", ")", "{", "try", "{", "$", "handle", "->", "query", "(", "'TRUNCATE '", ".", "$", "this", "->", "config", "[", "'table'", "]", ".", "''", ")", ";", "$", "statement", "=", "$", ...
Write the cache data to the table @param object $handle the database handle @param array $data the caching data @return object PDO @throws PDOException if a db error occurred
[ "Write", "the", "cache", "data", "to", "the", "table" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/DatabaseCache.php#L244-L276
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.run
public function run(array $request) { $report = new Report; foreach ($request as $key => $value) { $report = $this->iterate($key, $value, $report); } return $report; }
php
public function run(array $request) { $report = new Report; foreach ($request as $key => $value) { $report = $this->iterate($key, $value, $report); } return $report; }
[ "public", "function", "run", "(", "array", "$", "request", ")", "{", "$", "report", "=", "new", "Report", ";", "foreach", "(", "$", "request", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "report", "=", "$", "this", "->", "iterate", "(", ...
Starts the scan mechanism @param array $request @return Report
[ "Starts", "the", "scan", "mechanism" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L169-L176
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.iterate
private function iterate($key, $value, Report $report) { if (is_array($value)) { foreach ($value as $subKey => $subValue) { $this->iterate("$key.$subKey", $subValue, $report); } } elseif (is_string($value)) { if ($filter = $this->detect($key, $value)) { $report->addEvent(new Event($key, $value, $filter)); } } return $report; }
php
private function iterate($key, $value, Report $report) { if (is_array($value)) { foreach ($value as $subKey => $subValue) { $this->iterate("$key.$subKey", $subValue, $report); } } elseif (is_string($value)) { if ($filter = $this->detect($key, $value)) { $report->addEvent(new Event($key, $value, $filter)); } } return $report; }
[ "private", "function", "iterate", "(", "$", "key", ",", "$", "value", ",", "Report", "$", "report", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "subKey", "=>", "$", "subValue", ")", ...
Iterates through given data and delegates it to IDS_Monitor::_detect() in order to check for malicious appearing fragments @param string $key the former array key @param array|string $value the former array value @param Report $report @return Report
[ "Iterates", "through", "given", "data", "and", "delegates", "it", "to", "IDS_Monitor", "::", "_detect", "()", "in", "order", "to", "check", "for", "malicious", "appearing", "fragments" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L187-L199
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.detect
private function detect($key, $value) { // define the pre-filter $preFilter = '([^\w\s/@!?\.]+|(?:\./)|(?:@@\w+)|(?:\+ADw)|(?:union\s+select))i'; // to increase performance, only start detection if value isn't alphanumeric if ((!$this->scanKeys || !$key || !preg_match($preFilter, $key)) && (!$value || !preg_match($preFilter, $value))) { return array(); } // check if this field is part of the exceptions foreach ($this->exceptions as $exception) { $matches = array(); if (($exception === $key) || preg_match('((/.*/[^eE]*)$)', $exception, $matches) && isset($matches[1]) && preg_match($matches[1], $key)) { return array(); } } // check for magic quotes and remove them if necessary if (function_exists('get_magic_quotes_gpc') && !get_magic_quotes_gpc()) { $value = preg_replace('(\\\(["\'/]))im', '$1', $value); } // if html monitoring is enabled for this field - then do it! if (is_array($this->html) && in_array($key, $this->html, true)) { list($key, $value) = $this->purifyValues($key, $value); } // check if json monitoring is enabled for this field if (is_array($this->json) && in_array($key, $this->json, true)) { list($key, $value) = $this->jsonDecodeValues($key, $value); } // use the converter $value = Converter::runAll($value); $value = Converter::runCentrifuge($value, $this); // scan keys if activated via config $key = $this->scanKeys ? Converter::runAll($key) : $key; $key = $this->scanKeys ? Converter::runCentrifuge($key, $this) : $key; $filterSet = $this->storage->getFilterSet(); if ($tags = $this->tags) { $filterSet = array_filter( $filterSet, function (Filter $filter) use ($tags) { return (bool) array_intersect($tags, $filter->getTags()); } ); } $scanKeys = $this->scanKeys; $filterSet = array_filter( $filterSet, function (Filter $filter) use ($key, $value, $scanKeys) { return $filter->match($value) || $scanKeys && $filter->match($key); } ); return $filterSet; }
php
private function detect($key, $value) { // define the pre-filter $preFilter = '([^\w\s/@!?\.]+|(?:\./)|(?:@@\w+)|(?:\+ADw)|(?:union\s+select))i'; // to increase performance, only start detection if value isn't alphanumeric if ((!$this->scanKeys || !$key || !preg_match($preFilter, $key)) && (!$value || !preg_match($preFilter, $value))) { return array(); } // check if this field is part of the exceptions foreach ($this->exceptions as $exception) { $matches = array(); if (($exception === $key) || preg_match('((/.*/[^eE]*)$)', $exception, $matches) && isset($matches[1]) && preg_match($matches[1], $key)) { return array(); } } // check for magic quotes and remove them if necessary if (function_exists('get_magic_quotes_gpc') && !get_magic_quotes_gpc()) { $value = preg_replace('(\\\(["\'/]))im', '$1', $value); } // if html monitoring is enabled for this field - then do it! if (is_array($this->html) && in_array($key, $this->html, true)) { list($key, $value) = $this->purifyValues($key, $value); } // check if json monitoring is enabled for this field if (is_array($this->json) && in_array($key, $this->json, true)) { list($key, $value) = $this->jsonDecodeValues($key, $value); } // use the converter $value = Converter::runAll($value); $value = Converter::runCentrifuge($value, $this); // scan keys if activated via config $key = $this->scanKeys ? Converter::runAll($key) : $key; $key = $this->scanKeys ? Converter::runCentrifuge($key, $this) : $key; $filterSet = $this->storage->getFilterSet(); if ($tags = $this->tags) { $filterSet = array_filter( $filterSet, function (Filter $filter) use ($tags) { return (bool) array_intersect($tags, $filter->getTags()); } ); } $scanKeys = $this->scanKeys; $filterSet = array_filter( $filterSet, function (Filter $filter) use ($key, $value, $scanKeys) { return $filter->match($value) || $scanKeys && $filter->match($key); } ); return $filterSet; }
[ "private", "function", "detect", "(", "$", "key", ",", "$", "value", ")", "{", "// define the pre-filter", "$", "preFilter", "=", "'([^\\w\\s/@!?\\.]+|(?:\\./)|(?:@@\\w+)|(?:\\+ADw)|(?:union\\s+select))i'", ";", "// to increase performance, only start detection if value isn't alpha...
Checks whether given value matches any of the supplied filter patterns @param mixed $key the key of the value to scan @param mixed $value the value to scan @return Filter[] array of filter(s) that matched the value
[ "Checks", "whether", "given", "value", "matches", "any", "of", "the", "supplied", "filter", "patterns" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L209-L270
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.purifyValues
private function purifyValues($key, $value) { /* * Perform a pre-check if string is valid for purification */ if ($this->purifierPreCheck($key, $value)) { if (!is_writeable($this->HTMLPurifierCache)) { throw new \Exception($this->HTMLPurifierCache . ' must be writeable'); } /** @var $config \HTMLPurifier_Config */ $config = \HTMLPurifier_Config::createDefault(); $config->set('Attr.EnableID', true); $config->set('Cache.SerializerPath', $this->HTMLPurifierCache); $config->set('Output.Newline', "\n"); $this->htmlPurifier = new \HTMLPurifier($config); $value = preg_replace('([\x0b-\x0c])', ' ', $value); $key = preg_replace('([\x0b-\x0c])', ' ', $key); $purifiedValue = $this->htmlPurifier->purify($value); $purifiedKey = $this->htmlPurifier->purify($key); $plainValue = strip_tags($value); $plainKey = strip_tags($key); $value = $value != $purifiedValue || $plainValue ? $this->diff($value, $purifiedValue, $plainValue) : null; $key = $key != $purifiedKey ? $this->diff($key, $purifiedKey, $plainKey) : null; } return array($key, $value); }
php
private function purifyValues($key, $value) { /* * Perform a pre-check if string is valid for purification */ if ($this->purifierPreCheck($key, $value)) { if (!is_writeable($this->HTMLPurifierCache)) { throw new \Exception($this->HTMLPurifierCache . ' must be writeable'); } /** @var $config \HTMLPurifier_Config */ $config = \HTMLPurifier_Config::createDefault(); $config->set('Attr.EnableID', true); $config->set('Cache.SerializerPath', $this->HTMLPurifierCache); $config->set('Output.Newline', "\n"); $this->htmlPurifier = new \HTMLPurifier($config); $value = preg_replace('([\x0b-\x0c])', ' ', $value); $key = preg_replace('([\x0b-\x0c])', ' ', $key); $purifiedValue = $this->htmlPurifier->purify($value); $purifiedKey = $this->htmlPurifier->purify($key); $plainValue = strip_tags($value); $plainKey = strip_tags($key); $value = $value != $purifiedValue || $plainValue ? $this->diff($value, $purifiedValue, $plainValue) : null; $key = $key != $purifiedKey ? $this->diff($key, $purifiedKey, $plainKey) : null; } return array($key, $value); }
[ "private", "function", "purifyValues", "(", "$", "key", ",", "$", "value", ")", "{", "/*\n * Perform a pre-check if string is valid for purification\n */", "if", "(", "$", "this", "->", "purifierPreCheck", "(", "$", "key", ",", "$", "value", ")", ")"...
Purifies given key and value variables using HTMLPurifier This function is needed whenever there is variables for which HTML might be allowed like e.g. WYSIWYG post bodies. It will detect malicious code fragments and leaves harmless parts untouched. @param mixed $key @param mixed $value @since 0.5 @throws \Exception @return array tuple [key,value]
[ "Purifies", "given", "key", "and", "value", "variables", "using", "HTMLPurifier" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L287-L317
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.purifierPreCheck
private function purifierPreCheck($key = '', $value = '') { /* * Remove control chars before pre-check */ $tmpValue = preg_replace('/\p{C}/', null, $value); $tmpKey = preg_replace('/\p{C}/', null, $key); $preCheck = '/<(script|iframe|applet|object)\W/i'; return !(preg_match($preCheck, $tmpKey) || preg_match($preCheck, $tmpValue)); }
php
private function purifierPreCheck($key = '', $value = '') { /* * Remove control chars before pre-check */ $tmpValue = preg_replace('/\p{C}/', null, $value); $tmpKey = preg_replace('/\p{C}/', null, $key); $preCheck = '/<(script|iframe|applet|object)\W/i'; return !(preg_match($preCheck, $tmpKey) || preg_match($preCheck, $tmpValue)); }
[ "private", "function", "purifierPreCheck", "(", "$", "key", "=", "''", ",", "$", "value", "=", "''", ")", "{", "/*\n * Remove control chars before pre-check\n */", "$", "tmpValue", "=", "preg_replace", "(", "'/\\p{C}/'", ",", "null", ",", "$", "val...
This method makes sure no dangerous markup can be smuggled in attributes when HTML mode is switched on. If the precheck considers the string too dangerous for purification false is being returned. @param string $key @param string $value @since 0.6 @return boolean
[ "This", "method", "makes", "sure", "no", "dangerous", "markup", "can", "be", "smuggled", "in", "attributes", "when", "HTML", "mode", "is", "switched", "on", "." ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L332-L342
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.diff
private function diff($original, $purified, $plain) { /* * deal with over-sensitive alt-attribute addition of the purifier * and other common html formatting problems */ $purified = preg_replace('/\s+alt="[^"]*"/m', null, $purified); $purified = preg_replace('/=?\s*"\s*"/m', null, $purified); $original = preg_replace('/\s+alt="[^"]*"/m', null, $original); $original = preg_replace('/=?\s*"\s*"/m', null, $original); $original = preg_replace('/style\s*=\s*([^"])/m', 'style = "$1', $original); # deal with oversensitive CSS normalization $original = preg_replace('/(?:([\w\-]+:)+\s*([^;]+;\s*))/m', '$1$2', $original); # strip whitespace between tags $original = trim(preg_replace('/>\s*</m', '><', $original)); $purified = trim(preg_replace('/>\s*</m', '><', $purified)); $original = preg_replace('/(=\s*(["\'`])[^>"\'`]*>[^>"\'`]*["\'`])/m', 'alt$1', $original); // no purified html is left if (!$purified) { return $original; } // calculate the diff length $length = mb_strlen($original) - mb_strlen($purified); /* * Calculate the difference between the original html input * and the purified string. */ $array1 = preg_split('/(?<!^)(?!$)/u', html_entity_decode(urldecode($original))); $array2 = preg_split('/(?<!^)(?!$)/u', $purified); // create an array containing the single character differences $differences = array_diff_assoc($array1, $array2); // return the diff - ready to hit the converter and the rules $differences = trim(implode('', $differences)); $diff = $length <= 10 ? $differences : mb_substr($differences, 0, strlen($original)); // clean up spaces between tag delimiters $diff = preg_replace('/>\s*</m', '><', $diff); // correct over-sensitively stripped bad html elements $diff = preg_replace('/[^<](iframe|script|embed|object|applet|base|img|style)/m', '<$1', $diff ); return mb_strlen($diff) >= 4 ? $diff . $plain : null; }
php
private function diff($original, $purified, $plain) { /* * deal with over-sensitive alt-attribute addition of the purifier * and other common html formatting problems */ $purified = preg_replace('/\s+alt="[^"]*"/m', null, $purified); $purified = preg_replace('/=?\s*"\s*"/m', null, $purified); $original = preg_replace('/\s+alt="[^"]*"/m', null, $original); $original = preg_replace('/=?\s*"\s*"/m', null, $original); $original = preg_replace('/style\s*=\s*([^"])/m', 'style = "$1', $original); # deal with oversensitive CSS normalization $original = preg_replace('/(?:([\w\-]+:)+\s*([^;]+;\s*))/m', '$1$2', $original); # strip whitespace between tags $original = trim(preg_replace('/>\s*</m', '><', $original)); $purified = trim(preg_replace('/>\s*</m', '><', $purified)); $original = preg_replace('/(=\s*(["\'`])[^>"\'`]*>[^>"\'`]*["\'`])/m', 'alt$1', $original); // no purified html is left if (!$purified) { return $original; } // calculate the diff length $length = mb_strlen($original) - mb_strlen($purified); /* * Calculate the difference between the original html input * and the purified string. */ $array1 = preg_split('/(?<!^)(?!$)/u', html_entity_decode(urldecode($original))); $array2 = preg_split('/(?<!^)(?!$)/u', $purified); // create an array containing the single character differences $differences = array_diff_assoc($array1, $array2); // return the diff - ready to hit the converter and the rules $differences = trim(implode('', $differences)); $diff = $length <= 10 ? $differences : mb_substr($differences, 0, strlen($original)); // clean up spaces between tag delimiters $diff = preg_replace('/>\s*</m', '><', $diff); // correct over-sensitively stripped bad html elements $diff = preg_replace('/[^<](iframe|script|embed|object|applet|base|img|style)/m', '<$1', $diff ); return mb_strlen($diff) >= 4 ? $diff . $plain : null; }
[ "private", "function", "diff", "(", "$", "original", ",", "$", "purified", ",", "$", "plain", ")", "{", "/*\n * deal with over-sensitive alt-attribute addition of the purifier\n * and other common html formatting problems\n */", "$", "purified", "=", "preg...
This method calculates the difference between the original and the purified markup strings. @param string $original the original markup @param string $purified the purified markup @param string $plain the string without html @since 0.5 @return string the difference between the strings
[ "This", "method", "calculates", "the", "difference", "between", "the", "original", "and", "the", "purified", "markup", "strings", "." ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L355-L405
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.jsonDecodeValues
private function jsonDecodeValues($key, $value) { $decodedKey = json_decode($key); $decodedValue = json_decode($value); if ($decodedValue && is_array($decodedValue) || is_object($decodedValue)) { array_walk_recursive($decodedValue, array($this, 'jsonConcatContents')); $value = $this->tmpJsonString; } else { $this->tmpJsonString .= " " . $decodedValue . "\n"; } if ($decodedKey && is_array($decodedKey) || is_object($decodedKey)) { array_walk_recursive($decodedKey, array($this, 'jsonConcatContents')); $key = $this->tmpJsonString; } else { $this->tmpJsonString .= " " . $decodedKey . "\n"; } return array($key, $value); }
php
private function jsonDecodeValues($key, $value) { $decodedKey = json_decode($key); $decodedValue = json_decode($value); if ($decodedValue && is_array($decodedValue) || is_object($decodedValue)) { array_walk_recursive($decodedValue, array($this, 'jsonConcatContents')); $value = $this->tmpJsonString; } else { $this->tmpJsonString .= " " . $decodedValue . "\n"; } if ($decodedKey && is_array($decodedKey) || is_object($decodedKey)) { array_walk_recursive($decodedKey, array($this, 'jsonConcatContents')); $key = $this->tmpJsonString; } else { $this->tmpJsonString .= " " . $decodedKey . "\n"; } return array($key, $value); }
[ "private", "function", "jsonDecodeValues", "(", "$", "key", ",", "$", "value", ")", "{", "$", "decodedKey", "=", "json_decode", "(", "$", "key", ")", ";", "$", "decodedValue", "=", "json_decode", "(", "$", "value", ")", ";", "if", "(", "$", "decodedVal...
This method prepares incoming JSON data for the PHPIDS detection process. It utilizes _jsonConcatContents() as callback and returns a string version of the JSON data structures. @param string $key @param string $value @since 0.5.3 @return array tuple [key,value]
[ "This", "method", "prepares", "incoming", "JSON", "data", "for", "the", "PHPIDS", "detection", "process", ".", "It", "utilizes", "_jsonConcatContents", "()", "as", "callback", "and", "returns", "a", "string", "version", "of", "the", "JSON", "data", "structures",...
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L418-L438
PHPIDS/PHPIDS
lib/IDS/Monitor.php
Monitor.jsonConcatContents
private function jsonConcatContents($key, $value) { if (is_string($key) && is_string($value)) { $this->tmpJsonString .= $key . " " . $value . "\n"; } else { $this->jsonDecodeValues(json_encode($key), json_encode($value)); } }
php
private function jsonConcatContents($key, $value) { if (is_string($key) && is_string($value)) { $this->tmpJsonString .= $key . " " . $value . "\n"; } else { $this->jsonDecodeValues(json_encode($key), json_encode($value)); } }
[ "private", "function", "jsonConcatContents", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "key", ")", "&&", "is_string", "(", "$", "value", ")", ")", "{", "$", "this", "->", "tmpJsonString", ".=", "$", "key", ".", ...
This is the callback used in _jsonDecodeValues(). The method concatenates key and value and stores them in $this->tmpJsonString. @param mixed $key @param mixed $value @since 0.5.3 @return void
[ "This", "is", "the", "callback", "used", "in", "_jsonDecodeValues", "()", ".", "The", "method", "concatenates", "key", "and", "value", "and", "stores", "them", "in", "$this", "-", ">", "tmpJsonString", "." ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Monitor.php#L450-L457
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.update
public function update() { $ok = true; // perform updates... $ok = $this->updateFile(self::FILENAME_RULES); if ($ok) $ok = $this->updateFile(self::FILENAME_CONVERTER); return $ok; }
php
public function update() { $ok = true; // perform updates... $ok = $this->updateFile(self::FILENAME_RULES); if ($ok) $ok = $this->updateFile(self::FILENAME_CONVERTER); return $ok; }
[ "public", "function", "update", "(", ")", "{", "$", "ok", "=", "true", ";", "// perform updates...", "$", "ok", "=", "$", "this", "->", "updateFile", "(", "self", "::", "FILENAME_RULES", ")", ";", "if", "(", "$", "ok", ")", "$", "ok", "=", "$", "th...
Perform a Rule and Converter update if necessary @return boolean returns false if an error occured
[ "Perform", "a", "Rule", "and", "Converter", "update", "if", "necessary" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L95-L106
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.updateFile
private function updateFile($filename) { // fetch remote file: $file_contents = $this->fetchUrl(self::DOWNLOAD_BASE_URL.$filename); if ($file_contents === false) return false; if (sha1($file_contents) != $this->getCurrentFileHash($filename)) { try { throw new Exception("PHPIDS-Update: SHA1-hash of the downloaded file ($filename) is incorrect! (Download failed or Man-in-the-Middle). SHA1 of the file in the trunk: ".sha1($file_contents).", SHA1, provided by phpids.org: ".$this->getCurrentFileHash($filename)); } catch (Exception $e) { return false; } } if (strlen($file_contents) <= 100) { return false; } // overwrite file contents if (!file_put_contents($this->phpids_base.$filename, $file_contents)) { return false; } return true; }
php
private function updateFile($filename) { // fetch remote file: $file_contents = $this->fetchUrl(self::DOWNLOAD_BASE_URL.$filename); if ($file_contents === false) return false; if (sha1($file_contents) != $this->getCurrentFileHash($filename)) { try { throw new Exception("PHPIDS-Update: SHA1-hash of the downloaded file ($filename) is incorrect! (Download failed or Man-in-the-Middle). SHA1 of the file in the trunk: ".sha1($file_contents).", SHA1, provided by phpids.org: ".$this->getCurrentFileHash($filename)); } catch (Exception $e) { return false; } } if (strlen($file_contents) <= 100) { return false; } // overwrite file contents if (!file_put_contents($this->phpids_base.$filename, $file_contents)) { return false; } return true; }
[ "private", "function", "updateFile", "(", "$", "filename", ")", "{", "// fetch remote file:", "$", "file_contents", "=", "$", "this", "->", "fetchUrl", "(", "self", "::", "DOWNLOAD_BASE_URL", ".", "$", "filename", ")", ";", "if", "(", "$", "file_contents", "...
Download current file and replaces local @param string FILENAME_RULES or FILENAME_CONVERTER
[ "Download", "current", "file", "and", "replaces", "local" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L113-L138
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.getCurrentFileHash
private function getCurrentFileHash($filename) { if (!empty($hash_cache[$filename])) { return $hash_cache[$filename]; } $url = self::HASH_BASE_URL.$filename; $hash_response = $this->fetchUrl($url); if ($hash_response === false) return false; $hash = trim($hash_response); if (preg_match("/^[0-9a-f]{40}$/", $hash)) { $hash_cache[$filename] = $hash; return $hash; } else { return false; } }
php
private function getCurrentFileHash($filename) { if (!empty($hash_cache[$filename])) { return $hash_cache[$filename]; } $url = self::HASH_BASE_URL.$filename; $hash_response = $this->fetchUrl($url); if ($hash_response === false) return false; $hash = trim($hash_response); if (preg_match("/^[0-9a-f]{40}$/", $hash)) { $hash_cache[$filename] = $hash; return $hash; } else { return false; } }
[ "private", "function", "getCurrentFileHash", "(", "$", "filename", ")", "{", "if", "(", "!", "empty", "(", "$", "hash_cache", "[", "$", "filename", "]", ")", ")", "{", "return", "$", "hash_cache", "[", "$", "filename", "]", ";", "}", "$", "url", "=",...
Retreive current SHA-1 hash from php-ids.org @param string FILENAME_RULES or FILENAME_CONVERTER @return mixed SHA-1 hash or false if unavailible
[ "Retreive", "current", "SHA", "-", "1", "hash", "from", "php", "-", "ids", ".", "org" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L146-L165
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.getLocalFileHash
private function getLocalFileHash($filename) { $path = $this->phpids_base . $filename; if (file_exists($path)) { return sha1_file($path); } else { return false; } }
php
private function getLocalFileHash($filename) { $path = $this->phpids_base . $filename; if (file_exists($path)) { return sha1_file($path); } else { return false; } }
[ "private", "function", "getLocalFileHash", "(", "$", "filename", ")", "{", "$", "path", "=", "$", "this", "->", "phpids_base", ".", "$", "filename", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "return", "sha1_file", "(", "$", "path"...
Generate SHA-1 hash for local files @param string FILENAME_RULES or FILENAME_CONVERTER @return mixed SHA-1 hash of local file or false if file does not exists
[ "Generate", "SHA", "-", "1", "hash", "for", "local", "files" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L173-L181
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.isRulesUpdated
public function isRulesUpdated() { if ($this->getCurrentFileHash(self::FILENAME_RULES) == $this->getLocalFileHash(self::FILENAME_RULES)) { return true; } else { return false; } }
php
public function isRulesUpdated() { if ($this->getCurrentFileHash(self::FILENAME_RULES) == $this->getLocalFileHash(self::FILENAME_RULES)) { return true; } else { return false; } }
[ "public", "function", "isRulesUpdated", "(", ")", "{", "if", "(", "$", "this", "->", "getCurrentFileHash", "(", "self", "::", "FILENAME_RULES", ")", "==", "$", "this", "->", "getLocalFileHash", "(", "self", "::", "FILENAME_RULES", ")", ")", "{", "return", ...
Compare local and remote version of ids rules. @return boolean returns true if rules are uptodate.
[ "Compare", "local", "and", "remote", "version", "of", "ids", "rules", "." ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L188-L196
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.isConverterUpdated
public function isConverterUpdated() { if ($this->getCurrentFileHash(self::FILENAME_CONVERTER) == $this->getLocalFileHash(self::FILENAME_CONVERTER)) { return true; } else { return false; } }
php
public function isConverterUpdated() { if ($this->getCurrentFileHash(self::FILENAME_CONVERTER) == $this->getLocalFileHash(self::FILENAME_CONVERTER)) { return true; } else { return false; } }
[ "public", "function", "isConverterUpdated", "(", ")", "{", "if", "(", "$", "this", "->", "getCurrentFileHash", "(", "self", "::", "FILENAME_CONVERTER", ")", "==", "$", "this", "->", "getLocalFileHash", "(", "self", "::", "FILENAME_CONVERTER", ")", ")", "{", ...
Compare local and remote version of ids converter. @return boolean returns true if rules are uptodate.
[ "Compare", "local", "and", "remote", "version", "of", "ids", "converter", "." ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L203-L211
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.isWritable
public function isWritable() { if (file_exists($this->phpids_base.self::FILENAME_RULES) && is_writable($this->phpids_base.self::FILENAME_RULES) && file_exists($this->phpids_base.self::FILENAME_CONVERTER) && is_writable($this->phpids_base.self::FILENAME_CONVERTER)) { return true; } else { return false; } }
php
public function isWritable() { if (file_exists($this->phpids_base.self::FILENAME_RULES) && is_writable($this->phpids_base.self::FILENAME_RULES) && file_exists($this->phpids_base.self::FILENAME_CONVERTER) && is_writable($this->phpids_base.self::FILENAME_CONVERTER)) { return true; } else { return false; } }
[ "public", "function", "isWritable", "(", ")", "{", "if", "(", "file_exists", "(", "$", "this", "->", "phpids_base", ".", "self", "::", "FILENAME_RULES", ")", "&&", "is_writable", "(", "$", "this", "->", "phpids_base", ".", "self", "::", "FILENAME_RULES", "...
Check for existing rules and converter and for write permissions @return boolean returns true if both files are writable
[ "Check", "for", "existing", "rules", "and", "converter", "and", "for", "write", "permissions" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L218-L229
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.showVersionStatus
public function showVersionStatus() { $update_needed = false; $output = "<table class='tableBorder'>"; $output .= "<tr><td class='tableHead' colspan='2'>IDS Version</td></tr>"; $output .= "<tr><td class='tableCell' valign='top'>Filter:</td>\n<td class='tableCell'>"; if ($this->isRulesUpdated()) { $output .= "<span style='color: green;'>aktuell.</span>"; } else { $output .= "<span style='color: red;'>nicht aktuell.</span>"; $update_needed = true; } $output .= "<br />Letzte lokale &Auml;nderung: <strong>".$this->getLastRulesUpdate()."</strong><br />"; $output .= "Letzte &Auml;nderung auf php-ids.org: <strong>".$this->getLastFileUpdate(self::FILENAME_RULES)."</strong><br />"; $output .= "SHA-1 Hash: <br /> <code>".$this->getLocalFileHash(self::FILENAME_RULES)."</code>"; if (!$this->isRulesUpdated()) { $output .= "(local)<br /> <code>".$this->getCurrentFileHash(self::FILENAME_RULES)."</code>(remote)"; } $output .= "</td></tr>"; $output .= "<tr><td class='tableCell' valign='top'>Converter:</td>\n<td class='tableCell'>"; if ($this->isConverterUpdated()) { $output .= "<span style='color: green;'>aktuell.</span>"; } else { $output .= "<span style='color: red;'>nicht aktuell.</span>"; $update_needed = true; } $output .= "<br />Letzte lokale &Auml;nderung: <strong>".$this->getLastConverterUpdate()."</strong><br />"; $output .= "Letzte &Auml;nderung auf php-ids.org: <strong>".$this->getLastFileUpdate(self::FILENAME_CONVERTER)."</strong><br />"; $output .= "SHA-1 Hash: <br /> <code>".$this->getLocalFileHash(self::FILENAME_CONVERTER)."</code>"; if (!$this->isConverterUpdated()) { $output .= "(local)<br /> <code>".$this->getCurrentFileHash(self::FILENAME_CONVERTER)."</code>(remote)"; } $output .= "</td></tr>"; // is update possible? if (!$this->isRulesUpdated() || !$this->isConverterUpdated()) { $output .= "<tr><td class='tableCell'> </td>\n<td class='tableCell'>"; if ($this->isWritable() && function_exists("curl_init")) { $output .= "<form method='POST'>"; $output .= "<input type='submit' name='update_phpids' value='Automatisch Aktualisieren' />"; $output .= "</form>"; } else { $output .= "Kein automatisches Update verf&uuml;gbar. (Dateien beschreibbar/ Curl-Extension verf&uuml;gbar?)"; } $output .= "</td></tr>"; } $output .= "</table>"; return $output; }
php
public function showVersionStatus() { $update_needed = false; $output = "<table class='tableBorder'>"; $output .= "<tr><td class='tableHead' colspan='2'>IDS Version</td></tr>"; $output .= "<tr><td class='tableCell' valign='top'>Filter:</td>\n<td class='tableCell'>"; if ($this->isRulesUpdated()) { $output .= "<span style='color: green;'>aktuell.</span>"; } else { $output .= "<span style='color: red;'>nicht aktuell.</span>"; $update_needed = true; } $output .= "<br />Letzte lokale &Auml;nderung: <strong>".$this->getLastRulesUpdate()."</strong><br />"; $output .= "Letzte &Auml;nderung auf php-ids.org: <strong>".$this->getLastFileUpdate(self::FILENAME_RULES)."</strong><br />"; $output .= "SHA-1 Hash: <br /> <code>".$this->getLocalFileHash(self::FILENAME_RULES)."</code>"; if (!$this->isRulesUpdated()) { $output .= "(local)<br /> <code>".$this->getCurrentFileHash(self::FILENAME_RULES)."</code>(remote)"; } $output .= "</td></tr>"; $output .= "<tr><td class='tableCell' valign='top'>Converter:</td>\n<td class='tableCell'>"; if ($this->isConverterUpdated()) { $output .= "<span style='color: green;'>aktuell.</span>"; } else { $output .= "<span style='color: red;'>nicht aktuell.</span>"; $update_needed = true; } $output .= "<br />Letzte lokale &Auml;nderung: <strong>".$this->getLastConverterUpdate()."</strong><br />"; $output .= "Letzte &Auml;nderung auf php-ids.org: <strong>".$this->getLastFileUpdate(self::FILENAME_CONVERTER)."</strong><br />"; $output .= "SHA-1 Hash: <br /> <code>".$this->getLocalFileHash(self::FILENAME_CONVERTER)."</code>"; if (!$this->isConverterUpdated()) { $output .= "(local)<br /> <code>".$this->getCurrentFileHash(self::FILENAME_CONVERTER)."</code>(remote)"; } $output .= "</td></tr>"; // is update possible? if (!$this->isRulesUpdated() || !$this->isConverterUpdated()) { $output .= "<tr><td class='tableCell'> </td>\n<td class='tableCell'>"; if ($this->isWritable() && function_exists("curl_init")) { $output .= "<form method='POST'>"; $output .= "<input type='submit' name='update_phpids' value='Automatisch Aktualisieren' />"; $output .= "</form>"; } else { $output .= "Kein automatisches Update verf&uuml;gbar. (Dateien beschreibbar/ Curl-Extension verf&uuml;gbar?)"; } $output .= "</td></tr>"; } $output .= "</table>"; return $output; }
[ "public", "function", "showVersionStatus", "(", ")", "{", "$", "update_needed", "=", "false", ";", "$", "output", "=", "\"<table class='tableBorder'>\"", ";", "$", "output", ".=", "\"<tr><td class='tableHead' colspan='2'>IDS Version</td></tr>\"", ";", "$", "output", ".=...
Show version status table
[ "Show", "version", "status", "table" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L252-L305
PHPIDS/PHPIDS
docs/autoupdate/l_phpidsUpdate.php
l_phpidsUpdate.getLastFileUpdate
private function getLastFileUpdate($filename) { $feed_url = sprintf(self::FEED_BASE_URL, $filename); $content = $this->fetchUrl($feed_url); if (preg_match("/<pubDate>([^<]+)<\/pubDate>/", $content, $match)) { return date("d.m.Y H:i", strtotime($match[1])); } else { return false; } }
php
private function getLastFileUpdate($filename) { $feed_url = sprintf(self::FEED_BASE_URL, $filename); $content = $this->fetchUrl($feed_url); if (preg_match("/<pubDate>([^<]+)<\/pubDate>/", $content, $match)) { return date("d.m.Y H:i", strtotime($match[1])); } else { return false; } }
[ "private", "function", "getLastFileUpdate", "(", "$", "filename", ")", "{", "$", "feed_url", "=", "sprintf", "(", "self", "::", "FEED_BASE_URL", ",", "$", "filename", ")", ";", "$", "content", "=", "$", "this", "->", "fetchUrl", "(", "$", "feed_url", ")"...
Returns last @param string filename @return mixed date of last change or if an error occured, false
[ "Returns", "last" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/docs/autoupdate/l_phpidsUpdate.php#L313-L323
PHPIDS/PHPIDS
lib/IDS/Caching/ApcCache.php
ApcCache.getInstance
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new ApcCache($type, $init); } return self::$cachingInstance; }
php
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new ApcCache($type, $init); } return self::$cachingInstance; }
[ "public", "static", "function", "getInstance", "(", "$", "type", ",", "$", "init", ")", "{", "if", "(", "!", "self", "::", "$", "cachingInstance", ")", "{", "self", "::", "$", "cachingInstance", "=", "new", "ApcCache", "(", "$", "type", ",", "$", "in...
Returns an instance of this class @param string $type caching type @param object $init the IDS_Init object @return object $this
[ "Returns", "an", "instance", "of", "this", "class" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/ApcCache.php#L100-L107
PHPIDS/PHPIDS
lib/IDS/Caching/ApcCache.php
ApcCache.setCache
public function setCache(array $data) { if (!$this->isCached) { apc_store( $this->config['key_prefix'] . '.storage', $data, $this->config['expiration_time'] ); } return $this; }
php
public function setCache(array $data) { if (!$this->isCached) { apc_store( $this->config['key_prefix'] . '.storage', $data, $this->config['expiration_time'] ); } return $this; }
[ "public", "function", "setCache", "(", "array", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "isCached", ")", "{", "apc_store", "(", "$", "this", "->", "config", "[", "'key_prefix'", "]", ".", "'.storage'", ",", "$", "data", ",", "$", ...
Writes cache data @param array $data the caching data @return object $this
[ "Writes", "cache", "data" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/ApcCache.php#L116-L127
PHPIDS/PHPIDS
lib/IDS/Caching/ApcCache.php
ApcCache.getCache
public function getCache() { $data = apc_fetch($this->config['key_prefix'] . '.storage'); $this->isCached = !empty($data); return $data; }
php
public function getCache() { $data = apc_fetch($this->config['key_prefix'] . '.storage'); $this->isCached = !empty($data); return $data; }
[ "public", "function", "getCache", "(", ")", "{", "$", "data", "=", "apc_fetch", "(", "$", "this", "->", "config", "[", "'key_prefix'", "]", ".", "'.storage'", ")", ";", "$", "this", "->", "isCached", "=", "!", "empty", "(", "$", "data", ")", ";", "...
Returns the cached data Note that this method returns false if either type or file cache is not set @return mixed cache data or false
[ "Returns", "the", "cached", "data" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Caching/ApcCache.php#L137-L143
PHPIDS/PHPIDS
lib/IDS/Init.php
Init.init
public static function init($configPath = null) { if (!$configPath) { return new self(); } if (!isset(self::$instances[$configPath])) { if (!file_exists($configPath) || !is_readable($configPath)) { throw new \InvalidArgumentException("Invalid config path '$configPath'"); } self::$instances[$configPath] = new static(parse_ini_file($configPath, true)); } return self::$instances[$configPath]; }
php
public static function init($configPath = null) { if (!$configPath) { return new self(); } if (!isset(self::$instances[$configPath])) { if (!file_exists($configPath) || !is_readable($configPath)) { throw new \InvalidArgumentException("Invalid config path '$configPath'"); } self::$instances[$configPath] = new static(parse_ini_file($configPath, true)); } return self::$instances[$configPath]; }
[ "public", "static", "function", "init", "(", "$", "configPath", "=", "null", ")", "{", "if", "(", "!", "$", "configPath", ")", "{", "return", "new", "self", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$...
Returns an instance of this class. Also a PHP version check is being performed to avoid compatibility problems with PHP < 5.1.6 @param string|null $configPath the path to the config file @throws \InvalidArgumentException @return self
[ "Returns", "an", "instance", "of", "this", "class", ".", "Also", "a", "PHP", "version", "check", "is", "being", "performed", "to", "avoid", "compatibility", "problems", "with", "PHP", "<", "5", ".", "1", ".", "6" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Init.php#L90-L103
PHPIDS/PHPIDS
lib/IDS/Init.php
Init.getBasePath
public function getBasePath() { return (!empty($this->config['General']['base_path']) && !empty($this->config['General']['use_base_path'])) ? $this->config['General']['base_path'] : null; }
php
public function getBasePath() { return (!empty($this->config['General']['base_path']) && !empty($this->config['General']['use_base_path'])) ? $this->config['General']['base_path'] : null; }
[ "public", "function", "getBasePath", "(", ")", "{", "return", "(", "!", "empty", "(", "$", "this", "->", "config", "[", "'General'", "]", "[", "'base_path'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "config", "[", "'General'", "]", "[", ...
This method checks if a base path is given and usage is set to true. If all that tests succeed the base path will be returned as a string - else null will be returned. @return string|null the base path or null
[ "This", "method", "checks", "if", "a", "base", "path", "is", "given", "and", "usage", "is", "set", "to", "true", ".", "If", "all", "that", "tests", "succeed", "the", "base", "path", "will", "be", "returned", "as", "a", "string", "-", "else", "null", ...
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Init.php#L112-L117
PHPIDS/PHPIDS
lib/IDS/Init.php
Init.setConfig
public function setConfig(array $config, $overwrite = false) { if ($overwrite) { $this->config = $this->mergeConfig($this->config, $config); } else { $this->config = $this->mergeConfig($config, $this->config); } }
php
public function setConfig(array $config, $overwrite = false) { if ($overwrite) { $this->config = $this->mergeConfig($this->config, $config); } else { $this->config = $this->mergeConfig($config, $this->config); } }
[ "public", "function", "setConfig", "(", "array", "$", "config", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "$", "overwrite", ")", "{", "$", "this", "->", "config", "=", "$", "this", "->", "mergeConfig", "(", "$", "this", "->", "config"...
Merges new settings into the exsiting ones or overwrites them @param array $config the config array @param boolean $overwrite config overwrite flag @return void
[ "Merges", "new", "settings", "into", "the", "exsiting", "ones", "or", "overwrites", "them" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Init.php#L127-L134
PHPIDS/PHPIDS
lib/IDS/Filter/Storage.php
Storage.isCached
private function isCached() { $filters = false; if ($this->cacheSettings) { if ($this->cache) { $filters = $this->cache->getCache(); } } return $filters; }
php
private function isCached() { $filters = false; if ($this->cacheSettings) { if ($this->cache) { $filters = $this->cache->getCache(); } } return $filters; }
[ "private", "function", "isCached", "(", ")", "{", "$", "filters", "=", "false", ";", "if", "(", "$", "this", "->", "cacheSettings", ")", "{", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "filters", "=", "$", "this", "->", "cache", "->", ...
Checks if any filters are cached @return mixed $filters cached filters or false
[ "Checks", "if", "any", "filters", "are", "cached" ]
train
https://github.com/PHPIDS/PHPIDS/blob/dfc1476e4ffe9f1dde72c0954912411082a17597/lib/IDS/Filter/Storage.php#L163-L174