code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function setData($data): void { $this->data = $data; }
@param bool|float|int|string $data
setData
php
concretecms/concretecms
concrete/src/Summary/Data/Field/DataFieldData.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Summary/Data/Field/DataFieldData.php
MIT
public function getTemplates(string $categoryHandle, Collection $collection) { // First, retrieve the category entity $return = []; $category = $this->entityManager->getRepository(Category::class) ->findOneByHandle($categoryHandle); if ($category) { // Now, get templates assigned to this category $templates = $this->entityManager->getRepository(Template::class) ->findByCategory($category); if ($templates) { foreach($templates as $template) { $include = true; $fields = $template->getFields(); if ($fields) { foreach ($fields as $field) { $templateField = $field->getField(); if ($field->isRequired() && !$collection->containsField($templateField)) { $include = false; } } } if ($include) { $return[] = $template; } } } } return $return; }
@param string $categoryHandle @param Collection $collection @return Template[]
getTemplates
php
concretecms/concretecms
concrete/src/Summary/Template/Filterer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Summary/Template/Filterer.php
MIT
protected function summaryObjectSupportsTemplate($summaryObjectFields, Template $template) { $summaryObjectFieldIdentifiers = []; $templateRequiredFieldIdentifiers = []; foreach($summaryObjectFields as $identifier => $summaryObjectField) { $summaryObjectFieldIdentifiers[] = $identifier; } foreach($template->getRequiredFields() as $requiredField) { $templateRequiredFieldIdentifiers[] = $requiredField->getFieldIdentifier(); } foreach($templateRequiredFieldIdentifiers as $templateRequiredFieldIdentifier) { if (!in_array($templateRequiredFieldIdentifier, $summaryObjectFieldIdentifiers)) { return false; } } return true; }
@param array $summaryObjectFields @param Template $template
summaryObjectSupportsTemplate
php
concretecms/concretecms
concrete/src/Summary/Template/Renderer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Summary/Template/Renderer.php
MIT
public function getFileToRender(Template $template) { $site = $this->siteService->getSite(); if ($site) { $theme = $site->getSiteHomePageObject()->getCollectionThemeObject(); if ($theme) { $handle = $template->getHandle(); if ($handle) { $filename = DIRNAME_ELEMENTS . '/' . DIRNAME_SUMMARY . '/' . DIRNAME_SUMMARY_TEMPLATES . '/' . $handle . '.php'; $this->themeLocation->setTheme($theme); $this->fileLocator->addLocation($this->themeLocation); if ($template->getPackageHandle()) { $this->fileLocator->addPackageLocation($template->getPackageHandle()); } $record = $this->fileLocator->getRecord($filename); if ($record->exists()) { return $record->getFile(); } } } } return null; }
@param Page $page @param Template $template @return string file
getFileToRender
php
concretecms/concretecms
concrete/src/Summary/Template/TemplateLocator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Summary/Template/TemplateLocator.php
MIT
public function getDefaultDriver() { if ($this->defaultDriver) { return $this->defaultDriver; } return null; }
Get the default driver name. @return string
getDefaultDriver
php
concretecms/concretecms
concrete/src/Support/Manager.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Manager.php
MIT
public function expandCode($code, $expandShortEcho) { if (!is_string($code)) { throw new InvalidArgumentException(); } $result = ''; $tokens = token_get_all($code); $numTokens = count($tokens); $translationMap = [ T_OPEN_TAG => '<?php', ]; if ($expandShortEcho) { $translationMap = [ T_OPEN_TAG_WITH_ECHO => '<?php echo', ]; } $changed = false; $matches = null; foreach ($tokens as $tokenIndex => $token) { if (!is_array($token)) { $result .= $token; continue; } if (!isset($translationMap[$token[0]])) { $result .= $token[1]; continue; } $changed = true; $expanded = $translationMap[$token[0]]; $result .= $expanded; // Let's see if we have to add some white space after the expanded token if (preg_match('/(\s+)$/', $token[1], $matches)) { $result .= $matches[1]; } elseif ($tokenIndex < $numTokens - 1) { $nextToken = $tokens[$tokenIndex + 1]; if (!is_array($nextToken) || $nextToken[0] !== T_WHITESPACE) { $result .= ' '; } } } return $changed ? $result : null; }
Replace the short PHP open tags to long tags (`<?` to `<?php`) and optionally the short echo tags (`<?=` to `<?php echo `). @param string $code the code to be expanded @param bool $expandShortEcho expand @throws \InvalidArgumentException if $code is not a string @return string|null return NULL if code didn't changed, the expanded code otherwise
expandCode
php
concretecms/concretecms
concrete/src/Support/ShortTagExpander.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/ShortTagExpander.php
MIT
public function __construct($maxTrailingUnchangedLines = 3) { $this->maxTrailingUnchangedLines = max(0, (int) $maxTrailingUnchangedLines); $this->differ = new SBDiffer(); }
Initialize the instance. @param int $maxTrailingUnchangedLines the maximum number of unchanged trailing lines to be kept
__construct
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Differ.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Differ.php
MIT
public function diff($old, $new) { $diff = $this->differ->diff($old, $new); $lines = explode("\n", rtrim($diff, "\n")); $trailingUnchangedLines = $this->countTrailingUnchangedLines($lines); $trailingLinesToRemove = $trailingUnchangedLines - $this->maxTrailingUnchangedLines; if ($trailingLinesToRemove <= 0) { return $diff; } array_splice($lines, count($lines) - $trailingLinesToRemove); return implode("\n", $lines) . "\n"; }
{@inheritdoc} @see \PhpCsFixer\Differ\DifferInterface::diff()
diff
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Differ.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Differ.php
MIT
protected function countTrailingUnchangedLines(array &$lines) { $count = 0; for ($index = count($lines) - 1; $index >= 0; --$index) { if ($lines[$index] === '' || $lines[$index][0] !== ' ') { break; } ++$count; } return $count; }
Count the number of unchanged trailing lines. @param string[] $lines @return string
countTrailingUnchangedLines
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Differ.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Differ.php
MIT
public function __construct(PhpFixerOptions $options, PhpFixerRuleResolver $ruleResolver, PhpFixerRunner $runner) { $this->options = $options; $this->ruleResolver = $ruleResolver; $this->runner = $runner; }
Initialize the instance. @param \Concrete\Core\Support\CodingStyle\PhpFixerOptions $options @param \Concrete\Core\Support\CodingStyle\PhpFixerRuleResolver $ruleResolver @param \Concrete\Core\Support\CodingStyle\PhpFixerRunner $runner
__construct
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixer.php
MIT
public function getOptions() { return $this->options; }
Get the fixer options. @return \Concrete\Core\Support\CodingStyle\PhpFixerOptions
getOptions
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixer.php
MIT
public function fix(InputInterface $input, OutputInterface $output, array $paths, $dryRun = false) { $pathRuleList = []; foreach ($paths as $path) { $pathRuleList = $this->mergePathAndFlags($pathRuleList, $this->splitPathToPathAndFlags($path)); } $this->runner->resetSteps(); foreach ($pathRuleList as $flags => $paths) { $this->runner->addStep($this->options, $paths, $flags); } $progressOutput = new ProcessOutput($output, $this->runner->getEventDispatcher()->getEventDispatcher(), null, $this->runner->calculateNumberOfFiles()); $counters = []; $counter = function (FixerFileProcessedEvent $e) use (&$counters) { $status = $e->getStatus(); if (isset($counters[$status])) { ++$counters[$status]; } else { $counters[$status] = 1; } }; $this->runner->getEventDispatcher()->addListener(FixerFileProcessedEvent::NAME, $counter); try { $progressOutput->printLegend(); $changes = $this->runner->apply($dryRun); $output->writeln(''); } finally { $this->runner->getEventDispatcher()->removeListener(FixerFileProcessedEvent::NAME, $counter); } return [$counters, $changes, clone $this->runner->getErrorManager()]; }
@param \Symfony\Component\Console\Input\InputInterface $input @param \Symfony\Component\Console\Output\OutputInterface $output @param \SplFileInfo[] $paths with absolute paths @param bool $dryRun @return array
fix
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixer.php
MIT
protected function splitPathToPathAndFlags(SplFileInfo $path) { if ($path->isFile()) { return $this->splitFileToPathAndFlags($path); } if ($path->isDir()) { return $this->splitDirectoryToPathAndFlags($path); } throw new RuntimeException(t('Failed to find the file/directory %s', $path->getPathname())); }
@param \SplFileInfo $path @throws \RuntimeException if $path could not be found @return array
splitPathToPathAndFlags
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixer.php
MIT
protected function mergePathAndFlags($list1, $list2) { foreach ($list2 as $key => $paths) { if (isset($list1[$key])) { $list1[$key] = array_values(array_merge($list1[$key], $paths)); } else { $list1[$key] = $paths; } } return $list1; }
@param array $list1 @param array $list2 @return array
mergePathAndFlags
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixer.php
MIT
public function __construct(Repository $config) { $this->config = $config; }
Initialize the instance. @param \Concrete\Core\Config\Repository\Repository $config
__construct
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function normalizePath($path, $isDir, $isRelative) { $result = str_replace(DIRECTORY_SEPARATOR, '/', $path); if ($isRelative) { $result = ltrim($result, '/'); } if ($isDir) { $result = rtrim($result, '/') . '/'; } return $result; }
Normalize a path. @param string $path the path to be normalized @param bool $isDir is $path a directory? @param bool $isRelative is $path relative to the webroot? @return string
normalizePath
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public static function getDefaultWebRoot() { return DIR_BASE; }
Get the default absolute path to the web root directory. @return string
getDefaultWebRoot
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getWebRoot() { if ($this->webRoot === null) { $this->setWebRoot(static::getDefaultWebRoot()); } return $this->webRoot; }
Get the absolute path to the web root directory. @return string
getWebRoot
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setWebRoot($value) { $absPath = is_string($value) && $value !== '' ? realpath($value) : false; if ($absPath === false || !is_dir($absPath)) { throw new RuntimeException(t('Unable to find the directory %s', $value)); } $this->webRoot = $this->normalizePath($absPath, true, false); return $this; }
Set the absolute path to the web root directory. @param string|mixed $value @throws \RuntimeException if $value is not a valid directory path @return $this
setWebRoot
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getFilterByExtensions() { if ($this->filterByExtensions === null) { $this->setFilterByExtensions(preg_split('/\s+/', $this->config->get('coding_style.php.filter.extensions'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->filterByExtensions; }
Get the list of file extensions to be parsed. @return string[] always lower case, without leading dots
getFilterByExtensions
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setFilterByExtensions(array $value) { $filterByExtensions = []; foreach ($value as $extension) { $filterByExtensions[] = mb_strtolower(ltrim($extension, '.')); } $this->filterByExtensions = $filterByExtensions; return $this; }
Set the list of file extensions to be parsed. @param string[] $value @return $this
setFilterByExtensions
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getFilterIncludeFiles() { if ($this->filterIncludeFiles === null) { $this->setFilterIncludeFiles(preg_split('/\s+/', $this->config->get('coding_style.php.filter.include'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->filterIncludeFiles; }
Get the list of additional files (relative to the webroot) to be parsed. @return string[]
getFilterIncludeFiles
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setFilterIncludeFiles($value) { $filterIncludeFiles = []; foreach ($value as $path) { $filterIncludeFiles[] = $this->normalizePath($path, false, true); } $this->filterIncludeFiles = $filterIncludeFiles; return $this; }
Set the list of additional files (relative to the webroot) to be parsed. @param string[] $value @return $this
setFilterIncludeFiles
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getIgnoredDirectoriesByName() { if ($this->ignoredDirectoriesByName === null) { $this->setIgnoredDirectoriesByName(preg_split('/\s+/', $this->config->get('coding_style.php.ignore_directories.by_name'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->ignoredDirectoriesByName; }
Get the directory names that should not be parsed. @return string[]
getIgnoredDirectoriesByName
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setIgnoredDirectoriesByName(array $value) { $this->ignoredDirectoriesByName = $value; return $this; }
Set the directory names that should not be parsed. @param string[] $value @return $this
setIgnoredDirectoriesByName
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getIgnoredDirectoriesByPath() { if ($this->ignoredDirectoriesByPath === null) { $this->setIgnoredDirectoriesByPath(preg_split('/\s+/', $this->config->get('coding_style.php.ignore_directories.by_path'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->ignoredDirectoriesByPath; }
Get the directory paths (relative to the webroot) that should not be parsed (allowed placeholders: <HANDLE>). @return string[]
getIgnoredDirectoriesByPath
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setIgnoredDirectoriesByPath(array $value) { $ignoredDirectoriesByPath = []; foreach ($value as $path) { $ignoredDirectoriesByPath[] = $this->normalizePath($path, true, true); } $this->directoriesWithMixedContentsRegex = null; $this->ignoredDirectoriesByPath = $ignoredDirectoriesByPath; return $this; }
Set the directory paths (relative to the webroot) that should not be parsed (allowed placeholders: <HANDLE>). @param string[] $value @return $this
setIgnoredDirectoriesByPath
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getBootstrapFiles() { if ($this->bootstrapFiles === null) { $this->setBootstrapFiles(preg_split('/\s+/', $this->config->get('coding_style.php.bootstrap_files'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->bootstrapFiles; }
Get the file paths (relative to the webroot) that are executed before checking the PHP version. @return string[]
getBootstrapFiles
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setBootstrapFiles(array $value) { $bootstrapFiles = []; foreach ($value as $path) { $bootstrapFiles[] = $this->normalizePath($path, false, true); } $this->directoriesWithMixedContentsRegex = null; $this->bootstrapFiles = $bootstrapFiles; return $this; }
Set the file paths (relative to the webroot) that are executed before checking the PHP version. @param string[] $value @return $this
setBootstrapFiles
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getPhpOnlyNonPsr4Files() { if ($this->phpOnlyNonPsr4Files === null) { $this->setPhpOnlyNonPsr4Files(preg_split('/\s+/', $this->config->get('coding_style.php.php_only.non_psr4.files'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->phpOnlyNonPsr4Files; }
Get the file paths (relative to the webroot) that only contain PHP and that don't follow PSR-4 class names (allowed placeholders: <HANDLE>). @return string[]
getPhpOnlyNonPsr4Files
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setPhpOnlyNonPsr4Files(array $value) { $phpOnlyNonPsr4Files = []; foreach ($value as $path) { $phpOnlyNonPsr4Files[] = $this->normalizePath($path, false, true); } $this->directoriesWithMixedContentsRegex = null; $this->phpOnlyNonPsr4Regexes = null; $this->phpOnlyNonPsr4Files = $phpOnlyNonPsr4Files; return $this; }
Set the file paths (relative to the webroot) that only contain PHP and that don't follow PSR-4 class names (allowed placeholders: <HANDLE>). @param string[] $value @return $this
setPhpOnlyNonPsr4Files
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getPhpOnlyNonPsr4Directories() { if ($this->phpOnlyNonPsr4Directories === null) { $this->setPhpOnlyNonPsr4Directories(preg_split('/\s+/', $this->config->get('coding_style.php.php_only.non_psr4.directories'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->phpOnlyNonPsr4Directories; }
Get the directory paths (relative to the webroot) that contain PHP-only files that don't follow PSR-4 class names (allowed placeholders: <HANDLE>). @return string[]
getPhpOnlyNonPsr4Directories
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setPhpOnlyNonPsr4Directories(array $value) { $phpOnlyNonPsr4Directories = []; foreach ($value as $path) { $phpOnlyNonPsr4Directories[] = $this->normalizePath($path, true, true); } $this->directoriesWithMixedContentsRegex = null; $this->phpOnlyNonPsr4Regexes = null; $this->phpOnlyNonPsr4Directories = $phpOnlyNonPsr4Directories; return $this; }
Set the directory paths (relative to the webroot) that contain PHP-only files that don't follow PSR-4 class names (allowed placeholders: <HANDLE>). @param string[] $value @return $this
setPhpOnlyNonPsr4Directories
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getPhpOnlyNonPsr4Regexes() { if ($this->phpOnlyNonPsr4Regexes === null) { $phpOnlyNonPsr4Regexes = []; foreach ($this->getPhpOnlyNonPsr4Files() as $pattern) { $phpOnlyNonPsr4Regexes[] = '/^' . str_replace('\<HANDLE\>', '\w+', preg_quote($pattern, '/')) . '$/'; } foreach ($this->getPhpOnlyNonPsr4Directories() as $pattern) { $phpOnlyNonPsr4Regexes[] = '/^' . str_replace('\<HANDLE\>', '\w+', preg_quote($pattern, '/')) . '/'; } $this->phpOnlyNonPsr4Regexes = $phpOnlyNonPsr4Regexes; } return $this->phpOnlyNonPsr4Regexes; }
Get the regular expressions describing the paths (relative to the web root) that contain PHP-only files that don't follow PSR-4 class names. @return string[]
getPhpOnlyNonPsr4Regexes
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getPhpOnlyPsr4Files() { if ($this->phpOnlyPsr4Files === null) { $this->setPhpOnlyPsr4Files(preg_split('/\s+/', $this->config->get('coding_style.php.php_only.psr4.files'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->phpOnlyPsr4Files; }
Get the file paths (relative to the webroot) that only contain PHP and that follow PSR-4 class names (allowed placeholders: <HANDLE>). @return string[]
getPhpOnlyPsr4Files
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setPhpOnlyPsr4Files(array $value) { $phpOnlyPsr4Files = []; foreach ($value as $path) { $phpOnlyPsr4Files[] = $this->normalizePath($path, false, true); } $this->directoriesWithMixedContentsRegex = null; $this->phpOnlyPsr4Regexes = null; $this->phpOnlyPsr4Files = $phpOnlyPsr4Files; return $this; }
Set the file paths (relative to the webroot) that only contain PHP and that follow PSR-4 class names (allowed placeholders: <HANDLE>). @param string[] $value @return $this
setPhpOnlyPsr4Files
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getPhpOnlyPsr4Directories() { if ($this->phpOnlyPsr4Directories === null) { $this->setPhpOnlyPsr4Directories(preg_split('/\s+/', $this->config->get('coding_style.php.php_only.psr4.directories'), -1, PREG_SPLIT_NO_EMPTY)); } return $this->phpOnlyPsr4Directories; }
Get the directory paths (relative to the webroot) that contain PHP-only files that follow PSR-4 class names (allowed placeholders: <HANDLE>). @return string[]
getPhpOnlyPsr4Directories
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setPhpOnlyPsr4Directories(array $value) { $phpOnlyPsr4Directories = []; foreach ($value as $path) { $phpOnlyPsr4Directories[] = $this->normalizePath($path, true, true); } $this->directoriesWithMixedContentsRegex = null; $this->phpOnlyPsr4Regexes = null; $this->phpOnlyPsr4Directories = $phpOnlyPsr4Directories; return $this; }
Set the directory paths (relative to the webroot) that contain PHP-only files that follow PSR-4 class names (allowed placeholders: <HANDLE>). @param string[] $value @return $this
setPhpOnlyPsr4Directories
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getPhpOnlyPsr4Regexes() { if ($this->phpOnlyPsr4Regexes === null) { $phpOnlyPsr4Regexes = []; foreach ($this->getPhpOnlyPsr4Files() as $pattern) { $phpOnlyPsr4Regexes[] = '/^' . str_replace('\<HANDLE\>', '\w+', preg_quote($pattern, '/')) . '$/'; } foreach ($this->getPhpOnlyPsr4Directories() as $pattern) { $phpOnlyPsr4Regexes[] = '/^' . str_replace('\<HANDLE\>', '\w+', preg_quote($pattern, '/')) . '/'; } $this->phpOnlyPsr4Regexes = $phpOnlyPsr4Regexes; } return $this->phpOnlyPsr4Regexes; }
Get the regular expressions describing the paths (relative to the web root) that contain PHP-only files that don't follow PSR-4 class names. @return string[]
getPhpOnlyPsr4Regexes
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function isCacheDisabled() { return $this->isCacheDisabled; }
Is the fixers cache disabled. @return bool
isCacheDisabled
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setIsCacheDisabled($value) { $this->isCacheDisabled = (bool) $value; return $this; }
Is the fixers cache disabled. @param bool $value @return $this
setIsCacheDisabled
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function getMinimumPhpVersion() { return $this->minimumPhpVersion; }
Get the minimum PHP version. @return string empty string if the default one
getMinimumPhpVersion
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function setMinimumPhpVersion($value) { $this->minimumPhpVersion = (string) $value; return $this; }
Set the minimum PHP version. @param string $value empty string if the default one @return $this
setMinimumPhpVersion
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function isDirectoryWithMixedContents($path) { foreach ($this->getDirectoriesWithMixedContentsRegex() as $rx) { if (preg_match($rx, $path)) { return true; } } return false; }
Check if a directory contains PHP files with mixed flags. @param string $path the normalized relative path of the directory @return bool
isDirectoryWithMixedContents
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
protected function getDirectoriesWithMixedContentsRegex() { if ($this->directoriesWithMixedContentsRegex === null) { $directoriesWithMixedContentsRegex = []; foreach ($this->getFilterIncludeFiles() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } foreach ($this->getIgnoredDirectoriesByPath() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } foreach ($this->getBootstrapFiles() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } foreach ($this->getPhpOnlyNonPsr4Files() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } foreach ($this->getPhpOnlyNonPsr4Directories() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } foreach ($this->getPhpOnlyPsr4Files() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } foreach ($this->getPhpOnlyPsr4Directories() as $path) { $this->addDirectoriesWithMixedContentsRegex($path, $directoriesWithMixedContentsRegex); } $this->directoriesWithMixedContentsRegex = $directoriesWithMixedContentsRegex; } return $this->directoriesWithMixedContentsRegex; }
Get the list of regular expressions that should be used to check if a directory contains files with mixed flags. @return string[]
getDirectoriesWithMixedContentsRegex
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
protected function addDirectoriesWithMixedContentsRegex($path, array &$directoriesWithMixedContentsRegex) { // Remove the trailing slash (for directories) $pathWithoutLeadingSlash = rtrim($path, '/'); // Remove the last name $lastSlashPosition = strrpos($pathWithoutLeadingSlash, '/'); $containingDirectoryPath = $lastSlashPosition === false ? '' : substr($pathWithoutLeadingSlash, 0, $lastSlashPosition); $regexes = ['/^\/$/']; if ($containingDirectoryPath !== '') { $relativePath = ''; $dirnames = explode('/', $containingDirectoryPath); for (; ;) { $dirname = array_shift($dirnames); if ($dirname === null) { break; } $relativePath .= $dirname . '/'; $regexes[] = '/^' . str_replace('\<HANDLE\>', '\w+', preg_quote($relativePath, '/')) . '$/'; } } foreach ($regexes as $regex) { if (!in_array($regex, $directoriesWithMixedContentsRegex, true)) { $directoriesWithMixedContentsRegex[] = $regex; } } }
Add items to the list of regular expressions that should be used to check if a directory contains files with mixed flags. @param string $path the normalized relative path @param array $directoriesWithMixedContentsRegex
addDirectoriesWithMixedContentsRegex
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerOptions.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerOptions.php
MIT
public function describeFlags($flags) { $flags = (int) $flags; if (($flags & PhpFixer::FLAG_PSR4CLASS) === PhpFixer::FLAG_PSR4CLASS) { $result = 'PHP-only files with the same name as the class it implements'; } elseif (($flags & PhpFixer::FLAG_BOOTSTRAP) === PhpFixer::FLAG_BOOTSTRAP) { $result = 'PHP-only files with syntax compatible with old PHP versions'; } elseif ($flags === 0) { $result = 'files with mixed contents'; } else { $words = []; if (($flags & PhpFixer::FLAG_OLDPHP) === PhpFixer::FLAG_OLDPHP) { $words[] = 'files with syntax compatible with old PHP versions'; } if (($flags & PhpFixer::FLAG_PHPONLY) === PhpFixer::FLAG_PHPONLY) { $words[] = 'PHP-only files'; } $result = implode(', ', $words); } return $result; }
Get a description of the specified flags. @param int $flags A combination of CodingStyle::FLAG_... flags. @return string
describeFlags
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRuleResolver.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRuleResolver.php
MIT
public function getRules($flags, $onlyAvailableOnes, $minimumPhpVersion = '') { $flags = (int) $flags; $hasFlag = function ($flag) use ($flags) { return ($flags & $flag) === $flag; }; $rules = [ // PHP arrays should be declared using the configured syntax. 'array_syntax' => [ 'syntax' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '5.4') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? 'long' : 'short', ], // Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line. 'blank_line_after_opening_tag' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? true : false, // The body of each structure MUST be enclosed by braces. // Braces should be properly placed. // Body of braces should be properly indented. 'braces' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? ['allow_single_line_closure' => true] : false, // Replace multiple nested calls of `dirname` by only one call with second `$level` parameter. Requires PHP >= 7.0. 'combine_nested_dirname' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '7.0') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? false : true, // Replaces `dirname(__FILE__)` expression with equivalent `__DIR__` constant. 'dir_constant' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '5.3') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? false : true, // Replaces short-echo `<?=` with long format `<?php echo`/`<?php print` syntax, or vice-versa. 'echo_tag_syntax' => [ 'format' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '5.4') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? 'long' : 'short', 'long_function' => 'echo', ], // Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0. 'explicit_indirect_variable' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '7.0') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? false : true, // Code MUST use configured indentation type. 'indentation_type' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? true : false, // Ensure there is no code on the same line as the PHP open tag. 'linebreak_after_opening_tag' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? true : false, // List (`array` destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1. 'list_syntax' => [ 'syntax' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '7.1') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? 'long' : 'short', ], // There should not be blank lines between docblock and the documented element. 'no_blank_lines_after_phpdoc' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? true : false, // Replace short-echo `<?=` with long format `<?php echo` syntax. 'no_short_echo_tag' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '5.4') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? true : false, // Adds or removes `?` before type declarations for parameters with a default `null` value. 'nullable_type_declaration_for_default_null_value' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '7.1') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? false : true, // `@var` and `@type` annotations should not contain the variable name. 'phpdoc_var_without_name' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? true : false, // Converts `pow` to the `**` operator. 'pow_to_exponentiation' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '5.6') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? false : true, // Class names should match the file name. 'psr4' => $hasFlag(PhpFixer::FLAG_PSR4CLASS) ? true : false, // Instructions must be terminated with a semicolon. 'semicolon_after_instruction' => $hasFlag(PhpFixer::FLAG_PHPONLY) ? true : false, // Use `null` coalescing operator `??` where possible. Requires PHP >= 7.0. 'ternary_to_null_coalescing' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '7.0') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? false : true, // Visibility MUST be declared on all properties and methods; `abstract` and `final` MUST be declared before the visibility; `static` MUST be declared after the visibility. 'visibility_required' => ['elements' => ($minimumPhpVersion !== '' && version_compare($minimumPhpVersion, '7.1') < 0) || $hasFlag(PhpFixer::FLAG_OLDPHP) ? ['property', 'method'] : ['const', 'property', 'method']], ] + static::INVARIANT_RULES; if ($onlyAvailableOnes) { $fixerFactory = $this->getFixerFactory(); foreach (array_keys($rules) as $ruleName) { if ($ruleName[0] !== '@' && !$fixerFactory->hasRule($ruleName)) { unset($rules[$ruleName]); } } } return $rules; }
Get the rules associated to specific flags. @param int $flags A combination of PhpFixer::FLAG_... flags. @param bool $onlyAvailableOnes return only the available rules @param string $minimumPhpVersion the minimum PHP version that the files to be checked/fixed must be compatible with @return array
getRules
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRuleResolver.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRuleResolver.php
MIT
public function getFixers(array $rules) { return $this->getFixerFactory() ->useRuleSet(new RuleSet($rules)) ->setWhitespacesConfig(new WhitespacesFixerConfig()) ->getFixers() ; }
Resolve the fixers associated to the rules. @param array $rules the list of the rules (as returned by the getRules method) @return \PhpCsFixer\Fixer\FixerInterface[]
getFixers
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRuleResolver.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRuleResolver.php
MIT
public function __construct(PhpFixerRuleResolver $ruleResolver, EventDispatcher $eventDispatcher) { $this->ruleResolver = $ruleResolver; $this->eventDispatcher = $eventDispatcher; $this->resetSteps(); $this->resetErrors(); }
@param \Concrete\Core\Support\CodingStyle\PhpFixerRuleResolver $ruleResolver @param EventDispatcher $eventDispatcher
__construct
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRunner.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRunner.php
MIT
public function addStep(PhpFixerOptions $options, array $paths, $flags) { $this->steps[] = [ 'options' => $options, 'finder' => $this->createFinder($options, $paths), 'flags' => $flags, ]; return $this; }
@param \Concrete\Core\Support\CodingStyle\PhpFixerOptions $options @param array $paths @param int $flags @return $this
addStep
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRunner.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRunner.php
MIT
protected function applyStep(PhpFixerOptions $options, Traversable $finder, $flags, $dryRun) { $rules = $this->ruleResolver->getRules($flags, true, $options->getMinimumPhpVersion()); $fixers = $this->ruleResolver->getFixers($rules); $linter = new Linter(); $runner = new Runner( $finder, $fixers, new Differ(), $this->eventDispatcher->getEventDispatcher(), $this->errorManager, $linter, $dryRun, $this->createCacheManager($options, $flags, $dryRun, $rules), null, false ); $changes = []; $fixResult = $runner->fix(); foreach ($fixResult as $file => &$data) { $file = str_replace(DIRECTORY_SEPARATOR, '/', $file); if (strpos($file, $options->getWebRoot()) === 0) { $file = substr($file, strlen($options->getWebRoot())); } $changes[$file] = $data; } return $changes; }
@param \Concrete\Core\Support\CodingStyle\PhpFixerOptions $options @param \Symfony\Component\Finder\Finder|\ArrayObject $finder @param int $flags @param bool $dryRun @return array|void[]|NULL[]|string[][]|string[][][]
applyStep
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRunner.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRunner.php
MIT
protected function createFinder(PhpFixerOptions $options, array $paths) { $pathsByType = ['dir' => [], 'file' => []]; foreach ($paths as $path) { if (substr($path, -1) === '/') { $pathsByType['dir'][] = $path === '/' ? DIRECTORY_SEPARATOR : str_replace('/', DIRECTORY_SEPARATOR, rtrim($path, '/')); } else { $pathsByType['file'][] = str_replace('/', DIRECTORY_SEPARATOR, $path); } } $finder = Finder::create() ->files() ->ignoreDotFiles(true) ->ignoreVCS(true) ->exclude([]) ->in($pathsByType['dir']) ->append($pathsByType['file']) ; foreach ($options->getFilterByExtensions() as $extension) { $finder->name('*.' . $extension); } foreach ($options->getIgnoredDirectoriesByName() as $notName) { $finder->notPath('#(^|/)' . preg_quote($notName, '#') . '(/|$)#'); } return $finder; }
@param \Concrete\Core\Support\CodingStyle\PhpFixerOptions $options @param array $paths @return \Symfony\Component\Finder\Finder
createFinder
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRunner.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRunner.php
MIT
protected function createCacheManager(PhpFixerOptions $options, $flags, $dryRun, array $rules) { if ($options->isCacheDisabled()) { return new NullCacheManager(); } return new FileCacheManager( new FileHandler($this->getCacheFilename($options, $flags)), new Signature( PHP_VERSION, $this->getPhpCSFixerVersion(), ' ', "\n", $rules ), $dryRun, new Directory($options->getWebRoot()) ); }
@param \Concrete\Core\Support\CodingStyle\PhpFixerOptions $options @param int $flags @param bool $dryRun @param array $rules @return \PhpCsFixer\Cache\CacheManagerInterface
createCacheManager
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRunner.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRunner.php
MIT
protected function getCacheFilename(PhpFixerOptions $options, $flags) { return $options->getWebRoot() . '/.php_cs.cache.' . $flags . '@' . trim(preg_replace('/[^\w\.\@]+/', '_', PHP_VERSION), '_'); }
@param \Concrete\Core\Support\CodingStyle\PhpFixerOptions $options @param int $flags @return string
getCacheFilename
php
concretecms/concretecms
concrete/src/Support/CodingStyle/PhpFixerRunner.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/PhpFixerRunner.php
MIT
public function getDefinition() { $sample = <<<'EOT' <?=1?> <?= 1 ?> <?= 1 ?> <?=2;?> <?= 2; ?> <?= 2; ?> <?=3 ;?> <?= 3 ;?> <?=3 ;?> <?= 3 ; ?> <?php echo 4 ; ?> EOT ; return new FixerDefinition( 'Changes spaces and semicolons in inline PHP tags.', [ new CodeSample($sample), new CodeSample($sample, [self::OPTION_SPACEBEFORE => self::SPACE_KEEP]), new CodeSample($sample, [self::OPTION_SPACEBEFORE => self::SPACE_MINIMUM]), new CodeSample($sample, [self::OPTION_SPACEAFTER => self::SPACE_KEEP]), new CodeSample($sample, [self::OPTION_SPACEAFTER => self::SPACE_MINIMUM]), new CodeSample($sample, [self::OPTION_SEMICOLON => null]), new CodeSample($sample, [self::OPTION_SEMICOLON => true]), ], null ); }
{@inheritdoc} @see \PhpCsFixer\Fixer\DefinedFixerInterface::getDefinition()
getDefinition
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
public function isCandidate(Tokens $tokens) { if ( $this->configuration[self::OPTION_SPACEBEFORE] === self::SPACE_KEEP && $this->configuration[self::OPTION_SPACEAFTER] === self::SPACE_KEEP && $this->configuration[self::OPTION_SEMICOLON] === null ) { return false; } return $this->findApplicableRange($tokens) !== null; }
{@inheritdoc} @see \PhpCsFixer\Fixer\FixerInterface::isCandidate()
isCandidate
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
private function findApplicableRange(Tokens $tokens, int &$start = 0): ?array { $maxIndex = $tokens->count() - 1; for (; $start < $maxIndex; $start++) { $token = $tokens[$start]; /** @var \PhpCsFixer\Tokenizer\Token $token */ if (!$token->isGivenKind([T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { continue; } if (strpos($token->getContent(), "\n") !== false) { continue; } $result = [$token]; for ($nextIndex = $start + 1; $nextIndex <= $maxIndex; $nextIndex++) { $token = $tokens[$nextIndex]; /** @var \PhpCsFixer\Tokenizer\Token $token */ if ($token->isGivenKind(T_CLOSE_TAG)) { $result[] = $token; return $result; } if (strpos($token->getContent(), "\n") !== false) { break; } $result[] = $token; } $start = $nextIndex; } return null; }
Find the next range of tokens that should be fixes. @return \PhpCsFixer\Tokenizer\Token[]|null
findApplicableRange
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
private function fixRange(array $tokens): array { $start = $this->fixStart($tokens); $end = $this->fixEnd($tokens); return array_merge($start, $tokens, $end); }
@param \PhpCsFixer\Tokenizer\Token[] $tokens @return \PhpCsFixer\Tokenizer\Token[]
fixRange
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
private function fixStart(array &$tokens): array { $token = array_shift($tokens); $spaceBefore = $this->configuration[self::OPTION_SPACEBEFORE]; if ($spaceBefore === self::SPACE_KEEP) { return [$token]; } // Let's remove the extra whitespaces while ($tokens[0]->isWhitespace()) { array_shift($tokens); } if ($token->getId() !== T_OPEN_TAG_WITH_ECHO) { return [new Token([$token->getId(), rtrim($token->getContent()) . ' '])]; } $result = [new Token([T_OPEN_TAG_WITH_ECHO, '<?='])]; if ($spaceBefore === self::SPACE_ONE) { $result[] = new Token([T_WHITESPACE, ' ']); } return $result; }
@param \PhpCsFixer\Tokenizer\Token[] $tokens @return \PhpCsFixer\Tokenizer\Token[]
fixStart
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
private function fixEnd(array &$tokens): array { $spaceAfter = $this->configuration[self::OPTION_SPACEAFTER]; $semicolon = $this->configuration[self::OPTION_SEMICOLON]; if ($spaceAfter === self::SPACE_KEEP && $semicolon === null) { return []; } $token = array_pop($tokens); if ($spaceAfter === self::SPACE_KEEP) { $closing = [$token]; } else { $closing = [new Token([$token->getId(), ltrim($token->getContent())])]; if ($spaceAfter === self::SPACE_ONE) { array_unshift($closing, new Token([T_WHITESPACE, ' '])); } } $spacesAfterSemicolons = $this->popWhitespacesAndSemicolons($tokens, false, true); $semicolons = $this->popWhitespacesAndSemicolons($tokens, true, false); $spacesBeforeSemicolons = $this->popWhitespacesAndSemicolons($tokens, false, true); if ($tokens === [] && $this->configuration[self::OPTION_SPACEBEFORE] === self::SPACE_KEEP) { $tokens = $spacesBeforeSemicolons; $spacesBeforeSemicolons = []; } if ($spaceAfter !== self::SPACE_KEEP) { $spacesBeforeSemicolons = []; $spacesAfterSemicolons = []; } if ($semicolon === false) { $semicolons = []; } elseif ($semicolon === true) { $semicolons = $this->needsSemicolonAfter($tokens) ? [new Token(';')] : []; } return array_merge($spacesBeforeSemicolons, $semicolons, $spacesAfterSemicolons, $closing); }
@param \PhpCsFixer\Tokenizer\Token[] $tokens @return \PhpCsFixer\Tokenizer\Token[]
fixEnd
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
private function popWhitespacesAndSemicolons(array &$tokens, bool $semicolons, bool $whitespaces): array { $result = []; for (;;) { $token = array_pop($tokens); if ($token === null) { break; } if ($semicolons && $token->getContent() === ';' || $whitespaces && $token->isWhitespace()) { array_unshift($result, $token); continue; } $tokens[] = $token; break; } return $result; }
@param \PhpCsFixer\Tokenizer\Token[] $tokens @return \PhpCsFixer\Tokenizer\Token[]
popWhitespacesAndSemicolons
php
concretecms/concretecms
concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/CodingStyle/Fixer/InlineTagFixer.php
MIT
public static function __callStatic($method, $args) { $instance = static::resolveFacadeInstance(static::getFacadeAccessor()); switch (count($args)) { case 0: return $instance->$method(); case 1: return $instance->$method($args[0]); case 2: return $instance->$method($args[0], $args[1]); case 3: return $instance->$method($args[0], $args[1], $args[2]); case 4: return $instance->$method($args[0], $args[1], $args[2], $args[3]); default: return call_user_func_array(array($instance, $method), $args); } }
This is overridden to allow passthru to `DatabaseManager`'s __call. @param string $method @param array $args @return mixed @throws \Exception
__callStatic
php
concretecms/concretecms
concrete/src/Support/Facade/Database.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Database.php
MIT
public static function fire($eventName, $event = null) { $app = Facade::getFacadeApplication(); $args = func_get_args(); $app['director']->dispatch($eventName, $event); }
@deprecated @param $eventName @param null $event
fire
php
concretecms/concretecms
concrete/src/Support/Facade/Events.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Events.php
MIT
public static function getFacadeRoot() { return static::resolveFacadeInstance(static::getFacadeAccessor()); }
Get the root object behind the facade. @return mixed
getFacadeRoot
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
protected static function resolveFacadeInstance($name) { if (is_object($name)) { return $name; } if (isset(static::$resolvedInstance[$name])) { return static::$resolvedInstance[$name]; } return static::$resolvedInstance[$name] = static::$app[$name]; }
Resolve the facade root instance from the container. @param string $name @return mixed
resolveFacadeInstance
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
protected static function getFacadeAccessor() { throw new \RuntimeException("Facade does not implement getFacadeAccessor method."); }
Get the registered name of the component. @return string @throws \RuntimeException
getFacadeAccessor
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
public static function clearResolvedInstance($name) { unset(static::$resolvedInstance[$name]); }
Clear a resolved facade instance. @param string $name
clearResolvedInstance
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
public static function clearResolvedInstances() { static::$resolvedInstance = array(); }
Clear all of the resolved instances.
clearResolvedInstances
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
public static function getFacadeApplication() { return static::$app; }
Get the application instance behind the facade. @return \Concrete\Core\Application\Application
getFacadeApplication
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
public static function setFacadeApplication($app) { static::$app = $app; }
Set the application instance. @param \Concrete\Core\Application\Application $app
setFacadeApplication
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
public static function __callStatic($method, $args) { $instance = static::resolveFacadeInstance(static::getFacadeAccessor()); if (!method_exists($instance, $method) && !method_exists($instance, '__call')) { throw new \Exception(t('Invalid Method on class %s: %s.', get_class($instance), $method)); } switch (count($args)) { case 0: return $instance->$method(); case 1: return $instance->$method($args[0]); case 2: return $instance->$method($args[0], $args[1]); case 3: return $instance->$method($args[0], $args[1], $args[2]); case 4: return $instance->$method($args[0], $args[1], $args[2], $args[3]); default: return call_user_func_array(array($instance, $method), $args); } }
Handle dynamic, static calls to the object. @param string $method @param array $args @return mixed
__callStatic
php
concretecms/concretecms
concrete/src/Support/Facade/Facade.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Facade.php
MIT
public static function getFacadeRoot() { return parent::getFacadeRoot(); }
@return \Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface
getFacadeRoot
php
concretecms/concretecms
concrete/src/Support/Facade/Url.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Url.php
MIT
public static function to(/* ... */) { return static::getFacadeRoot()->resolve(func_get_args()); }
Resolve a URL from data. Working core examples for example.com: \Url::to('/some/path', 'some_action', $some_variable = 2) http://example.com/some/path/some_action/2/ \Url::to($page_object = \Page::getByPath('blog'), 'action') http://example.com/blog/action/ @return \League\Url\UrlInterface
to
php
concretecms/concretecms
concrete/src/Support/Facade/Url.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Url.php
MIT
public static function route($data) { $arguments = array_slice(func_get_args(), 1); if (!$arguments) { $arguments = array(); } $route = static::getFacadeApplication()->make(\Router::class)->route($data); array_unshift($arguments, $route); return static::getFacadeRoot()->resolve($arguments); }
This method is only here as a legacy decorator, use url::to. @return \League\Url\UrlInterface @deprecated
route
php
concretecms/concretecms
concrete/src/Support/Facade/Url.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Url.php
MIT
public static function page() { return static::getFacadeRoot()->resolve(func_get_args()); }
This method is only here as a legacy decorator, use `\URL::to($page)`. @return \League\Url\UrlInterface @deprecated
page
php
concretecms/concretecms
concrete/src/Support/Facade/Url.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Facade/Url.php
MIT
public function getCustomEntityRepositories() { $result = []; $app = ApplicationFacade::getFacadeApplication(); $pev = new PackageEntitiesEvent(); $app->make('director')->dispatch('on_list_package_entities', $pev); $entityManagers = array_merge([$app->make(EntityManagerInterface::class)], $pev->getEntityManagers()); foreach ($entityManagers as $entityManager) { /* @var EntityManagerInterface $entityManager */ $metadataFactory = $entityManager->getMetadataFactory(); foreach ($metadataFactory->getAllMetadata() as $metadata) { /* @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata */ $entityClassName = $metadata->getName(); $entityRepository = $entityManager->getRepository($entityClassName); $entityRepositoryClassName = get_class($entityRepository); switch ($entityRepositoryClassName) { case \Doctrine\ORM\EntityRepository::class: break; default: $result[$entityClassName] = $entityRepositoryClassName; break; } } } return $result; }
Return the list of custom entity manager repositories. @return array array keys are the entity fully-qualified class names, values are the custom repository fully-qualified class names
getCustomEntityRepositories
php
concretecms/concretecms
concrete/src/Support/Symbol/MetadataGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/MetadataGenerator.php
MIT
private function resolveAbstractToClassName(Application $app, $abstract) { $result = null; try { $instance = $app->make($abstract); if (is_object($instance)) { $className = get_class($instance); if (ltrim($abstract, '\\') !== $className) { $result = $className; } } } catch (Exception $e) { } catch (Throwable $e) { } return $result; }
@param Application $app @param string $abstract @return string|null
resolveAbstractToClassName
php
concretecms/concretecms
concrete/src/Support/Symbol/MetadataGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/MetadataGenerator.php
MIT
public function isInsideNamespace() { return $this->insideNamespace; }
Are we generating PHPDoc to be placed inside a namespace? @return bool
isInsideNamespace
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function setIsInsideNamespace($value) { $this->insideNamespace = (bool) $value; return $this; }
Are we generating PHPDoc to be placed inside a namespace? @param bool $value @return $this
setIsInsideNamespace
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function setIndentation($value) { $this->indentation = (string) $value; return $this; }
Set the indentation. @param string $value @return $this
setIndentation
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function isSingleDocBlock() { return $this->singleDocBlock; }
Insert the variable definitions in the same PHPDoc block? @return bool
isSingleDocBlock
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function setIsSingleDocBlock($value) { $this->singleDocBlock = (bool) $value; return $this; }
Insert the variable definitions in the same PHPDoc block? @param bool $value @return $this
setIsSingleDocBlock
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function describeVar($name, $value) { return $this->indentation . '/** ' . $this->describeVarUncommented($name, $value) . " */\n"; }
Generate the PHPDoc to describe a variable. @param string $name The variable name @param mixed $value The variable value @return string
describeVar
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function describeVars(array $vars, $sortByName = true) { $count = count($vars); if ($count === 0) { return ''; } if ($sortByName) { ksort($vars, SORT_NATURAL); } if ($count === 1 || $this->isSingleDocBlock() === false) { $result = ''; foreach ($vars as $name => $value) { $result .= $this->describeVar($name, $value); } return $result; } $result = $this->indentation . "/**\n"; foreach ($vars as $name => $value) { $result .= $this->indentation . ' * ' . $this->describeVarUncommented($name, $value) . "\n"; } return $result . $this->indentation . " */\n"; }
Generate the PHPDoc to describe a list of variables. @param array $vars @param bool $sortByName @return string
describeVars
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
protected function describeVarUncommented($name, $value) { return '@var ' . $this->getVarType($value) . ' ' . ($name[0] === '$' ? '' : '$') . $name; }
Generate the PHPDoc content to describe a variable (without opening/closing comments). @param string $name The variable name @param mixed $value The variable value @return string
describeVarUncommented
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
protected function getVarType($var, $arrayLevel = 0) { $phpType = gettype($var); switch ($phpType) { case 'boolean': $result = 'bool'; break; case 'integer': $result = 'int'; break; case 'double': $result = 'float'; break; case 'string': $result = 'string'; break; case 'array': if ($arrayLevel > 1) { $result = 'array'; } else { $result = null; $first = true; foreach ($var as $item) { $itemType = $this->getVarType($item, $arrayLevel + 1); if ($first) { $result = $itemType; $commonObjectDescriptors = $this->getObjectDescriptors($item); $first = false; } else { if ($result !== $itemType) { $result = null; if (empty($commonObjectDescriptors)) { break; } if (!empty($commonObjectDescriptors)) { $commonObjectDescriptors = array_intersect($commonObjectDescriptors, $this->getObjectDescriptors($item)); } } } } if ($result !== null) { $result .= '[]'; } elseif (!empty($commonObjectDescriptors)) { $result = array_shift($commonObjectDescriptors) . '[]'; } else { $result = 'array'; } } break; case 'object': $result = get_class($var); if ($result === false) { $result = 'mixed'; } else { if ($this->insideNamespace) { $result = '\\' . $result; } } break; case 'resource': $result = 'resource'; break; case 'NULL': $result = 'null'; break; case 'unknown type': default: $result = 'mixed'; break; } return $result; }
Get the PHPDoc type name of a variable. @param mixed $var @param int $arrayLevel @return string
getVarType
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
protected function getObjectDescriptors($var) { $result = []; $className = is_object($var) ? get_class($var) : false; if ($className !== false) { $result[] = ($this->insideNamespace ? '\\' : '') . $className; $class = new ReflectionClass($className); for ($childClass = $class->getParentClass(); $childClass; $childClass = $childClass->getParentClass()) { $result[] = ($this->insideNamespace ? '\\' : '') . $childClass->getName(); } foreach ($class->getInterfaceNames() as $interfaceName) { $result[] = ($this->insideNamespace ? '\\' : '') . $interfaceName; } } return $result; }
Get all the names representing an object instance (class name, parent class names, interface names). @param mixed $var @return array
getObjectDescriptors
php
concretecms/concretecms
concrete/src/Support/Symbol/PhpDocGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/PhpDocGenerator.php
MIT
public function registerClass($alias, $class) { $classSymbol = new ClassSymbol($alias, $class); $this->classes[$alias] = $classSymbol; $aliasNamespace = $classSymbol->getAliasNamespace(); if (!in_array($aliasNamespace, $this->aliasNamespaces, true)) { $this->aliasNamespaces[] = $aliasNamespace; } }
Register a class alias, and store it in the classes array. @param $alias string @param $class string
registerClass
php
concretecms/concretecms
concrete/src/Support/Symbol/SymbolGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/SymbolGenerator.php
MIT
public function render($eol = "\n", $padding = ' ', $methodFilter = null) { $lines = []; $lines[] = '<?php'; $lines[] = ''; $lines[] = '// Generated on ' . date('c'); foreach ($this->aliasNamespaces as $namespace) { $lines[] = ''; $lines[] = rtrim("namespace {$namespace}"); $lines[] = '{'; $addNewline = false; if ($namespace === '') { $lines[] = "{$padding}die('Access Denied.');"; $addNewline = true; } foreach ($this->classes as $class) { if ($class->getAliasNamespace() === $namespace) { $rendered_class = $class->render($eol, $padding, $methodFilter); if ($rendered_class !== '') { if ($addNewline === true) { $lines[] = ''; } else { $addNewline = true; } $lines[] = $padding . str_replace($eol, $eol . $padding, rtrim($rendered_class)); } } } $lines[] = '}'; } $lines[] = ''; return implode($eol, $lines); }
Render the classes. @param string $eol @param string $padding @param callable|null $methodFilter @return mixed|string
render
php
concretecms/concretecms
concrete/src/Support/Symbol/SymbolGenerator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/SymbolGenerator.php
MIT
public function __construct($alias, $fqn, $facade = null) { $this->reflectionClass = new ReflectionClass($fqn); $this->fqn = ltrim($fqn, '\\'); $this->alias = ltrim($alias, '/'); $chunks = explode('\\', $this->alias); $this->aliasBasename = array_pop($chunks); $this->aliasNamespace = implode('\\', $chunks); $this->comment = $this->reflectionClass->getDocComment(); if ( $facade === true || ( $facade !== false && ( $this->reflectionClass->isSubclassOf('\Concrete\Core\Support\Facade\Facade') || $this->reflectionClass->isSubclassOf('\Illuminate\Support\Facades\Facade') ) ) ) { $obj = $fqn::getFacadeRoot(); $this->facade = $this->reflectionClass; $this->reflectionClass = new ReflectionClass($obj); $this->fqn = $this->reflectionClass->getName(); } else { $this->facade = null; } $this->resolveMethods(); }
@param $alias string Class Alias @param $fqn string Fully qualified Class name @param $facade bool Is this a facade
__construct
php
concretecms/concretecms
concrete/src/Support/Symbol/ClassSymbol/ClassSymbol.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/ClassSymbol/ClassSymbol.php
MIT
public function render($eol = "\n", $padding = ' ', $methodFilter = null) { $rendered = ''; $comment = $this->comment; if ($comment !== false) { $comment = trim($comment); if ($comment !== '') { $rendered .= str_replace($eol . '*', $eol . ' *', implode($eol, array_map('trim', explode("\n", $comment)))) . $eol; } } if ($this->reflectionClass->isAbstract()) { $rendered .= 'abstract '; } $rendered .= 'class ' . $this->aliasBasename . ' extends \\' . $this->fqn . "{$eol}{{$eol}"; $firstMethod = true; foreach ($this->methods as $method) { if (is_callable($methodFilter) && (call_user_func($methodFilter, $this, $method) === false)) { continue; } if ($firstMethod) { $firstMethod = false; if ($this->isFacade()) { $rendered .= $padding . '/**' . $eol . $padding . ' * @var ' . $this->fqn . $eol . $padding . ' */' . $eol; $rendered .= $padding . 'protected static $instance;' . $eol; } } $rendered_method = $method->render($eol, $padding); if ($rendered_method !== '') { $rendered .= $padding . rtrim(str_replace($eol, $eol . $padding, $rendered_method)) . $eol; } } $rendered .= "}{$eol}"; return $rendered; }
Render Class with methods. @param string $eol @param string $padding @param callable|null $methodFilter @return string
render
php
concretecms/concretecms
concrete/src/Support/Symbol/ClassSymbol/ClassSymbol.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/ClassSymbol/ClassSymbol.php
MIT
public function getAliasNamespace() { return $this->aliasNamespace; }
Get the namespace of the alias. @return string
getAliasNamespace
php
concretecms/concretecms
concrete/src/Support/Symbol/ClassSymbol/ClassSymbol.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/ClassSymbol/ClassSymbol.php
MIT
public function render($eol = "\n", $padding = ' ') { $method = $this->reflectionMethod; if ($method->isPrivate() || substr($method->getName(), 0, 2) === '__' || $method->isAbstract()) { return ''; } $rendered = ''; $comment = $method->getDocComment(); if ($comment !== false) { $comment = trim($comment); if ($comment !== '') { $rendered .= str_replace($eol . '*', $eol . ' *', implode($eol, array_map('trim', explode("\n", $comment)))) . $eol; } } $visibility = \Reflection::getModifierNames($method->getModifiers()); $isStatic = $method->isStatic(); if ((!$isStatic) && $this->classSymbol->isFacade()) { $visibility[] = 'static'; } $rendered .= implode(' ', array_unique($visibility)) . ' function ' . $this->handle . '('; $params = array(); $calling_params = array(); foreach ($this->parameters as $parameter) { $param = ''; if ($parameter->isArray()) { $param .= 'array '; } /*else if ($parameter->isCallable()) { // This should be enabled for php 5.4 $param .= 'callable '; } */ else { try { if (is_object($parameter->getClass())) { $param .= $parameter->getClass()->getName() . ' '; } } catch (\ReflectionException $e) { $class = $this->reflectionMethod->getDeclaringClass()->getName(); echo "Invalid type hint in {$class}::{$this->handle}\n"; } } if ($parameter->isPassedByReference()) { $param .= "&"; } $param .= '$' . $parameter->getName(); if ($parameter->isOptional()) { $defaultValue = null; if (method_exists($parameter, 'getDefaultValueConstantName')) { $defaultValue = $parameter->getDefaultValueConstantName(); } if ($defaultValue) { // Strip out wrong namespaces. if (preg_match('/.\\\\(\\w+)$/', $defaultValue, $matches) && defined($matches[1])) { $defaultValue = $matches[1]; } } else { $v = $parameter->getDefaultValue(); switch (gettype($v)) { case 'boolean': case 'integer': case 'double': case 'NULL': $defaultValue = json_encode($v); break; case 'string': $defaultValue = '"' . addslashes($v) . '"'; break; case 'array': if (count($v)) { $defaultValue = trim(var_export($v, true)); } else { $defaultValue = 'array()'; } break; case 'object': case 'resource': default: $defaultValue = trim(var_export($v, true)); break; } } $param .= ' = ' . $defaultValue; } $params[] = $param; $calling_params[] = '$' . $parameter->getName(); } $rendered .= implode(', ', $params) . "){$eol}{{$eol}"; $class_name = $method->getDeclaringClass()->getName(); $rendered .= $padding . 'return '; if ($isStatic) { $rendered .= $class_name . '::' . $method->getName(); } elseif ($this->classSymbol->isFacade()) { $rendered .= 'static::$instance->' . $method->getName(); } else { $rendered .= 'parent::' . $method->getName(); } $rendered .= '(' . implode(', ', $calling_params) . ');' . $eol; $rendered .= '}' . $eol; return $rendered; }
Render the Method. @param string $eol @param string $padding @return string
render
php
concretecms/concretecms
concrete/src/Support/Symbol/ClassSymbol/MethodSymbol/MethodSymbol.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Support/Symbol/ClassSymbol/MethodSymbol/MethodSymbol.php
MIT
public function __construct($temporaryDirectory) { $this->setTemporaryDirectory($temporaryDirectory); }
Initialize the instance. @param string $temporaryDirectory the path to the temporary directory
__construct
php
concretecms/concretecms
concrete/src/System/Mutex/FileLockMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/FileLockMutex.php
MIT
public static function isSupported(Application $app) { return true; }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::isSupported()
isSupported
php
concretecms/concretecms
concrete/src/System/Mutex/FileLockMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/FileLockMutex.php
MIT
public function acquire($key) { $filename = $this->getFilenameForMutexKey($key); if (isset($this->resources[$key])) { $fd = $this->resources[$key]; if (is_resource($fd)) { throw new MutexBusyException($key); } } @touch($filename); @chmod($filename, 0666); $fd = @fopen($filename, 'r+'); if (!is_resource($fd) || @flock($fd, LOCK_EX | LOCK_NB) !== true) { throw new MutexBusyException($key); } $this->resources[$key] = $fd; }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::acquire()
acquire
php
concretecms/concretecms
concrete/src/System/Mutex/FileLockMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/FileLockMutex.php
MIT
public function release($key) { if (isset($this->resources[$key])) { $fd = $this->resources[$key]; unset($this->resources[$key]); @flock($fd, LOCK_UN); @fclose($fd); try { @unlink($this->getFilenameForMutexKey($key)); } catch (Exception $x) { } } }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::release()
release
php
concretecms/concretecms
concrete/src/System/Mutex/FileLockMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/FileLockMutex.php
MIT
public function execute($key, callable $callback) { $this->acquire($key); try { $callback(); } finally { $this->release($key); } }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::execute()
execute
php
concretecms/concretecms
concrete/src/System/Mutex/FileLockMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/FileLockMutex.php
MIT
public function __construct($mutexKey) { $this->mutexKey = (string) $mutexKey; parent::__construct(t(/*i18n: A mutex is a system object that represents a system to run code; usually this word shouldn't be translated */'The mutex with key "%s" is not valid.', $this->mutexKey)); }
Initialize the instance. @param mixed $mutexKey The invalid mutex key
__construct
php
concretecms/concretecms
concrete/src/System/Mutex/InvalidMutexKeyException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/InvalidMutexKeyException.php
MIT