1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-02-18 04:07:15 +01:00

Add D++ library.

This commit is contained in:
Sandu Liviu Catalin
2023-03-23 20:20:44 +02:00
parent b08a024298
commit cbd8f8b028
568 changed files with 131250 additions and 0 deletions

139
vendor/DPP/buildtools/changelog.php vendored Normal file
View File

@@ -0,0 +1,139 @@
<?php
// D++ changelog generator, saves 15 minutes for each release :-)
// Pattern list
$categories = [
'break' => '💣 Breaking Changes',
'breaking' => '💣 Breaking Changes',
'feat' => '✨ New Features',
'feature' => '✨ New Features',
'add' => '✨ New Features',
'added' => '✨ New Features',
'fix' => '🐞 Bug Fixes',
'bug' => '🐞 Bug Fixes',
'bugfix' => '🐞 Bug Fixes',
'fixed' => '🐞 Bug Fixes',
'fixes' => '🐞 Bug Fixes',
'perf' => '🚀 Performance Improvements',
'performance' => '🚀 Performance Improvements',
'impro' => '♻️ Refactoring',
'improved' => '♻️ Refactoring',
'improvement' => '♻️ Refactoring',
'refactor' => '♻️ Refactoring',
'refactored' => '♻️ Refactoring',
'deprecated' => '♻️ Refactoring',
'deprecate' => '♻️ Refactoring',
'remove' => '♻️ Refactoring',
'change' => '♻️ Refactoring',
'changed' => '♻️ Refactoring',
'test' => '🚨 Testing',
'tests' => '🚨 Testing',
'testing' => '🚨 Testing',
'ci' => '👷 Build/CI',
'build' => '👷 Build/CI',
'docs' => '📚 Documentation',
'documentation' => '📚 Documentation',
'style' => '💎 Style Changes',
'chore' => '🔧 Chore',
'misc' => '📜 Miscellaneous Changes',
'update' => '📜 Miscellaneous Changes',
'updated' => '📜 Miscellaneous Changes',
];
$catgroup = [];
$changelog = [];
$githubstyle = true;
if (count($argv) > 2 && $argv[1] == '--discord') {
$githubstyle = false;
}
// Magic sauce
exec("git log --format=\"%s\" $(git log --no-walk --tags | head -n1 | cut -d ' ' -f 2)..HEAD | grep -v '^Merge '", $changelog);
// Leadin
if ($githubstyle) {
echo "The changelog is listed below:\n\nRelease Changelog\n===========\n";
} else {
echo "The changelog is listed below:\n\n__**Release Changelog**__\n";
}
// Case insensitive removal of duplicates
$changelog = array_intersect_key($changelog, array_unique(array_map("strtolower", $changelog)));
// remove duplicates where two entries are the same but one ends with a GitHub pull request link
foreach ($changelog as $item) {
$entryWithoutPrLink = preg_replace('/( \(#\d+\))$/', '', $item);
if ($entryWithoutPrLink === $item) {
continue;
}
// if $item ends with (#123)
foreach ($changelog as $key => $change) {
if ($entryWithoutPrLink === $change) {
unset($changelog[$key]);
break;
}
}
}
foreach ($changelog as $change) {
// Wrap anything that looks like a symbol name in backticks
$change = preg_replace('/([a-zA-Z][\w_\/\-]+\.\w+|\S+\(\)|\w+::\w+|dpp::\w+|utility::\w+|(\w+_\w+)+)/', '`$1`', $change);
$change = preg_replace("/vs(\d+)/", "Visual Studio $1", $change);
$change = preg_replace("/\bfaq\b/", "FAQ", $change);
$change = preg_replace("/\bdiscord\b/", "Discord", $change);
$change = preg_replace("/\bmicrosoft\b/", "Microsoft", $change);
$change = preg_replace("/\bwindows\b/", "Windows", $change);
$change = preg_replace("/\blinux\b/", "Linux", $change);
$change = preg_replace("/\sarm(\d+)\s/i", ' ARM$1 ', $change);
$change = preg_replace("/\b(was|is|wo)nt\b/i", '$1n\'t', $change);
$change = preg_replace("/\bfreebsd\b/", 'FreeBSD', $change);
$change = preg_replace("/``/", "`", $change);
// Match keywords against categories
$matched = false;
foreach ($categories as $cat => $header) {
// Purposefully ignored: comments that are one word, merge commits, and version bumps
if (strpos($change, ' ') === false || preg_match("/^Merge (branch|pull request|remote-tracking branch) /", $change) || preg_match("/version bump/i", $change)) {
$matched = true;
continue;
}
// Groupings
if ((preg_match("/^" . $cat . ":/i", $change)) || (preg_match("/^\[" . $cat . "\//i", $change)) || (preg_match("/^\[" . $cat . "\]/i", $change)) || (preg_match("/^\[" . $cat . ":/i", $change)) || (preg_match("/^" . $cat . "\//i", $change)) || (preg_match("/^" . $cat . ":/i", $change))) {
if (!isset($catgroup[$header])) {
$catgroup[$header] = [];
}
$matched = true;
$catgroup[$header][] = preg_replace("/^\S+\s+/", "", $change);
break;
} else if (preg_match("/^" . $cat . " /i", $change)) {
if (!isset($catgroup[$header])) {
$catgroup[$header] = [];
}
$matched = true;
$catgroup[$header][] = $change;
break;
}
}
}
// Output tidy formatting
foreach ($catgroup as $cat => $list) {
echo "\n" . ($githubstyle ? '## ' : '__**') . $cat . ($githubstyle ? '' : '**__') . "\n";
foreach ($list as $item) {
// Exclude bad commit messages like 'typo fix', 'test push' etc by pattern
if (!preg_match("/^(typo|test|fix)\s\w+$/", $item) && strpos($item, ' ') !== false) {
echo ($githubstyle ? '-' : '•') . ' ' . ucfirst(str_replace('@', '', $item)) . "\n";
}
}
}
// Leadout
echo "\n\n**Thank you for using D++!**\n\n";
if (!$githubstyle) {
$version = $argv[2];
echo 'The ' . $version . ' download can be found here: <https://dl.dpp.dev/' . $version . '>';
echo "\n";
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Dpp\Generator;
use Dpp\StructGeneratorInterface;
/**
* Generate header and .cpp file for coroutine calls (starting with 'co_')
*/
class CoroGenerator implements StructGeneratorInterface
{
/**
* @inheritDoc
*/
public function generateHeaderStart(): string
{
return <<<EOT
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2022 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
/* Auto @generated by buildtools/make_coro_struct.php.
*
* DO NOT EDIT BY HAND!
*
* To re-generate this header file re-run the script!
*/
EOT;
}
/**
* @inheritDoc
*/
public function generateCppStart(): string
{
return $this->generateHeaderStart() . <<<EOT
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/cluster.h>
#include <dpp/coro.h>
namespace dpp {
EOT;
}
/**
* @inheritDoc
*/
public function checkForChanges(): bool
{
/* Check if we need to re-generate by comparing modification times */
$us = file_exists('include/dpp/cluster_coro_calls.h') ? filemtime('include/dpp/cluster_coro_calls.h') : 0;
$them = filemtime('include/dpp/cluster.h');
if ($them <= $us) {
echo "-- No change required.\n";
return false;
}
echo "-- Autogenerating include/dpp/cluster_coro_calls.h\n";
return true;
}
/**
* @inheritDoc
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
{
$parameterNames = preg_replace('/^, /', '', $parameterNames);
if (!empty($parameterNames)) {
$parameterNames .= ', ';
}
return "auto inline co_{$currentFunction}($noDefaults) {\n\treturn dpp::awaitable(this, [&] (auto cc) { this->$currentFunction({$parameterNames}cc); }); \n}\n\n";
}
/**
* @inheritDoc
*/
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
{
return '';
}
/**
* @inheritDoc
*/
public function getCommentArray(): array
{
return [" * \memberof dpp::cluster"];
}
/**
* @inheritDoc
*/
public function saveHeader(string $content): void
{
$content .= "auto inline co_request(const std::string &url, http_method method, const std::string &postdata = \"\", const std::string &mimetype = \"text/plain\", const std::multimap<std::string, std::string> &headers = {}) {\n\treturn dpp::awaitable(this, [&] (auto cc) { this->request(url, method, cc, mimetype, headers); }); \n}\n\n";
file_put_contents('include/dpp/cluster_coro_calls.h', $content);
}
/**
* @inheritDoc
*/
public function saveCpp(string $cppcontent): void
{
/* No cpp file to save, code is all inline */
}
}

View File

@@ -0,0 +1,130 @@
<?php
namespace Dpp\Generator;
use Dpp\StructGeneratorInterface;
/**
* Generate header and .cpp file for synchronous calls (ending in '_sync')
*/
class SyncGenerator implements StructGeneratorInterface
{
/**
* @inheritDoc
*/
public function generateHeaderStart(): string
{
return <<<EOT
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2022 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
/* Auto @generated by buildtools/make_sync_struct.php.
*
* DO NOT EDIT BY HAND!
*
* To re-generate this header file re-run the script!
*/
EOT;
}
/**
* @inheritDoc
*/
public function generateCppStart(): string
{
return $this->generateHeaderStart() . <<<EOT
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/cluster.h>
namespace dpp {
EOT;
}
/**
* @inheritDoc
*/
public function checkForChanges(): bool
{
/* Check if we need to re-generate by comparing modification times */
$us = file_exists('include/dpp/cluster_sync_calls.h') ? filemtime('include/dpp/cluster_sync_calls.h') : 0;
$them = filemtime('include/dpp/cluster.h');
if ($them <= $us) {
echo "-- No change required.\n";
return false;
}
echo "-- Autogenerating include/dpp/cluster_sync_calls.h\n";
echo "-- Autogenerating src/dpp/cluster_sync_calls.cpp\n";
return true;
}
/**
* @inheritDoc
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
{
return "$returnType {$currentFunction}_sync($parameters);\n\n";
}
/**
* @inheritDoc
*/
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
{
return "$returnType cluster::{$currentFunction}_sync($noDefaults) {\n\treturn dpp::sync<$returnType>(this, &cluster::$currentFunction$parameterNames);\n}\n\n";
}
/**
* @inheritDoc
*/
public function getCommentArray(): array
{
return [
" * \memberof dpp::cluster",
" * @throw dpp::rest_exception upon failure to execute REST function",
" * @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.",
" * Avoid direct use of this function inside an event handler.",
];
}
/**
* @inheritDoc
*/
public function saveHeader(string $content): void
{
file_put_contents('include/dpp/cluster_sync_calls.h', $content);
}
/**
* @inheritDoc
*/
public function saveCpp(string $cppcontent): void
{
file_put_contents('src/dpp/cluster_sync_calls.cpp', $cppcontent);
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Dpp;
/**
* Represents a header/cpp generator used to auto-generate cpp/.h files.
*/
interface StructGeneratorInterface
{
/**
* Generate the start of the header file
*
* @return string header content
*/
public function generateHeaderStart(): string;
/**
* Generate the start of the cpp file
*
* @return string cpp content
*/
public function generateCppStart(): string;
/**
* Check if the script should run and re-generate content or not
*
* @return string true if the script should run, false to exit
*/
public function checkForchanges(): bool;
/**
* Generate header definition for a function
*
* @param string $returnType Return type of function
* @param string $currentFunction Current function name
* @param string $parameters Current function parameters with default values
* @param string $noDefaults Current function parameters without default values
* @param string $parameterNames Parameter names only
* @return string header content to append
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string;
/**
* Generate cpp definition for a function
*
* @param string $returnType Return type of function
* @param string $currentFunction Current function name
* @param string $parameters Current function parameters with default values
* @param string $noDefaults Current function parameters without default values
* @param string $parameterNames Parameter names only
* @return string cpp content to append
*/
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string;
/**
* Return comment lines to add to each header definition
*
* @return array Comment lines to add
*/
public function getCommentArray(): array;
/**
* Save the .h file
*
* @param string $content Content to save
*/
public function saveHeader(string $content): void;
/**
* Save the .cpp file
*
* @param string $cppcontent Content to save
*/
public function saveCpp(string $cppcontent): void;
};

View File

@@ -0,0 +1,31 @@
<?php
// Comment on and close all PRs targeted at master branch
// Magic sauce
exec("gh pr list --base master | sed 's/\|/ /' |awk '{print $1}'", $master_prs);
foreach ($master_prs as $pr) {
$pr = (int)$pr;
if ($pr > 0) {
system("gh pr comment $pr -b \"You have opened a PR against the master branch. PRs must target the \`dev\` branch, as such this PR has been automatically closed. Please re-target your PR against the dev branch if you reopen it. Thank you for your contribution.\"");
system("gh pr close $pr");
}
}
// Tidy up the workflow run list so it isn't littered with these
exec("gh run list -w \"Close master-targeted PRs\"", $runs);
$runindex = 0;
foreach ($runs as $run) {
$run = preg_replace('/ /', ' ', $run);
$data = preg_split('/\s+/', $run);
$id = $data[sizeof($data) - 3];
$id = (int)$id;
if ($id > 0 && $runindex > 0) {
// Delete all but the first completed workflow run and this one
// (the first is the currently executing one!)
exec("gh api repos/brainboxdotcc/DPP/actions/runs/$id -X DELETE");
sleep(1);
}
$runindex++;
}

17
vendor/DPP/buildtools/composer.json vendored Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "brainboxdotcc/dpp",
"description": "DPP Build Tools",
"type": "project",
"license": "Apache 2.0",
"autoload": {
"psr-4": {
"Dpp\\": "classes/"
}
},
"authors": [
{
"name": "brain"
}
],
"require": {}
}

185
vendor/DPP/buildtools/make_struct.php vendored Normal file
View File

@@ -0,0 +1,185 @@
<?php
chdir('buildtools');
require __DIR__ . '/vendor/autoload.php';
use Dpp\StructGeneratorInterface;
if (count($argv) < 2) {
die("You must specify a generator type\n");
} else {
$generatorName = $argv[1];
$generator = new $generatorName();
}
chdir('..');
/* Get the content of all cluster source files into an array */
exec("cat src/dpp/cluster/*.cpp", $clustercpp);
/* These methods have signatures incompatible with this script */
$blacklist = [
'channel_edit_permissions',
'message_add_reaction',
'message_delete_reaction',
'message_delete_reaction_emoji',
'message_delete_all_reactions',
'message_delete_own_reaction',
'message_get_reactions',
'channel_typing',
'application_role_connection_get', // TODO: rest_request_vector
'application_role_connection_update',
];
/* The script cannot determine the correct return type of these methods,
* so we specify it by hand here.
*/
$forcedReturn = [
'direct_message_create' => 'message',
'guild_get_members' => 'guild_member_map',
'guild_search_members' => 'guild_member_map',
'message_create' => 'message',
'message_edit' => 'message',
'thread_create_in_forum' => 'thread',
];
/* Get the contents of cluster.h into an array */
$header = explode("\n", file_get_contents('include/dpp/cluster.h'));
/* Finite state machine state constants */
const STATE_SEARCH_FOR_FUNCTION = 0;
const STATE_IN_FUNCTION = 1;
const STATE_END_OF_FUNCTION = 2;
$state = STATE_SEARCH_FOR_FUNCTION;
$currentFunction = $parameters = $returnType = '';
$content = $generator->generateHeaderStart();
$cppcontent = $generator->generatecppStart();
if (!$generator->checkForChanges()) {
exit(0);
}
/* Scan every line of the C++ source */
foreach ($clustercpp as $cpp) {
/* Look for declaration of function body */
if ($state == STATE_SEARCH_FOR_FUNCTION &&
preg_match('/^\s*void\s+cluster::([^(]+)\s*\((.*)command_completion_event_t\s*callback\s*\)/', $cpp, $matches)) {
$currentFunction = $matches[1];
$parameters = preg_replace('/,\s*$/', '', $matches[2]);
if (!in_array($currentFunction, $blacklist)) {
$state = STATE_IN_FUNCTION;
}
/* Scan function body */
} elseif ($state == STATE_IN_FUNCTION) {
/* End of function */
if (preg_match('/^\}\s*$/', $cpp)) {
$state = STATE_END_OF_FUNCTION;
/* look for the return type of the method */
} elseif (preg_match('/rest_request<([^>]+)>/', $cpp, $matches)) {
/* rest_request<T> */
$returnType = $matches[1];
} elseif (preg_match('/rest_request_list<([^>]+)>/', $cpp, $matches)) {
/* rest_request_list<T> */
$returnType = $matches[1] . '_map';
} elseif (preg_match('/callback\(confirmation_callback_t\(\w+, ([^(]+)\(.*, \w+\)\)/', $cpp, $matches)) {
/* confirmation_callback_t */
$returnType = $matches[1];
} elseif (!empty($forcedReturn[$currentFunction])) {
/* Forced return type */
$returnType = $forcedReturn[$currentFunction];
}
}
/* Completed parsing of function body */
if ($state == STATE_END_OF_FUNCTION && !empty($currentFunction) && !empty($returnType)) {
if (!in_array($currentFunction, $blacklist)) {
$parameterList = explode(',', $parameters);
$parameterNames = [];
foreach ($parameterList as $parameter) {
$parts = explode(' ', trim($parameter));
$parameterNames[] = trim(preg_replace('/[\s\*\&]+/', '', $parts[count($parts) - 1]));
}
$content .= getComments($generator, $currentFunction, $returnType, $parameterNames) . "\n";
$fullParameters = getFullParameters($currentFunction, $parameterNames);
$parameterNames = trim(join(', ', $parameterNames));
if (!empty($parameterNames)) {
$parameterNames = ', ' . $parameterNames;
}
$noDefaults = $parameters;
$parameters = !empty($fullParameters) ? $fullParameters : $parameters;
$content .= $generator->generateHeaderDef($returnType, $currentFunction, $parameters, $noDefaults, $parameterNames);
$cppcontent .= $generator->generateCppDef($returnType, $currentFunction, $parameters, $noDefaults, $parameterNames);
}
$currentFunction = $parameters = $returnType = '';
$state = STATE_SEARCH_FOR_FUNCTION;
}
}
$content .= <<<EOT
/* End of auto-generated definitions */
EOT;
$cppcontent .= <<<EOT
};
/* End of auto-generated definitions */
EOT;
/**
* @brief Get parameters of a function with defaults
* @param string $currentFunction Current function name
* @param array $parameters Parameter names
* @return string Parameter list
*/
function getFullParameters(string $currentFunction, array $parameters): string
{
global $header;
foreach ($header as $line) {
if (preg_match('/^\s*void\s+' . $currentFunction . '\s*\((.*' . join('.*', $parameters) . '.*)command_completion_event_t\s*callback\s*/', $line, $matches)) {
return preg_replace('/,\s*$/', '', $matches[1]);
}
}
return '';
}
/**
* @brief Get the comment block of a function.
* Adds see/return doxygen tags
* @param string $currentFunction function name
* @param string $returnType Return type of function
* @param array $parameters Parameter names
* @return string Comment block
*/
function getComments(StructGeneratorInterface $generator, string $currentFunction, string $returnType, array $parameters): string
{
global $header;
/* First find the function */
foreach ($header as $i => $line) {
if (preg_match('/^\s*void\s+' . $currentFunction . '\s*\(.*' . join('.*', $parameters) . '.*command_completion_event_t\s*callback\s*/', $line)) {
/* Backpeddle */
$lineIndex = 1;
for ($n = $i; $n != 0; --$n, $lineIndex++) {
$header[$n] = preg_replace('/^\t+/', '', $header[$n]);
$header[$n] = preg_replace('/@see (.+?)$/', '@see dpp::cluster::' . $currentFunction . "\n * @see \\1", $header[$n]);
$header[$n] = preg_replace('/@param callback .*$/', '@return ' . $returnType . ' returned object on completion', $header[$n]);
if (preg_match('/\s*\* On success /i', $header[$n])) {
$header[$n] = "";
}
if (preg_match('/\s*\/\*\*\s*$/', $header[$n])) {
$part = array_slice($header, $n, $lineIndex - 1);
array_splice($part, count($part) - 1, 0, $generator->getCommentArray());
return str_replace("\n\n", "\n", join("\n", $part));
}
}
return '';
}
}
return '';
}
/* Finished parsing, output autogenerated files */
$generator->saveHeader($content);
$generator->savecpp($cppcontent);

View File

@@ -0,0 +1,12 @@
<?php
// autoload.php @generated by Composer
if (PHP_VERSION_ID < 50600) {
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
exit(1);
}
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit0e8415491642f27914717986db49b1db::getLoader();

View File

@@ -0,0 +1,572 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var ?string */
private $vendorDir;
// PSR-4
/**
* @var array[]
* @psalm-var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, array<int, string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* @var array[]
* @psalm-var array<string, array<string, string[]>>
*/
private $prefixesPsr0 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var string[]
* @psalm-var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var bool[]
* @psalm-var array<string, bool>
*/
private $missingClasses = array();
/** @var ?string */
private $apcuPrefix;
/**
* @var self[]
*/
private static $registeredLoaders = array();
/**
* @param ?string $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}
/**
* @return string[]
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array[]
* @psalm-return array<string, array<int, string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return string[] Array of classname => path
* @psalm-return array<string, string>
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param string[] $classMap Class to filename map
* @psalm-param array<string, string> $classMap
*
* @return void
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
* @private
*/
function includeFile($file)
{
include $file;
}

View File

@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,10 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,10 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Dpp\\' => array($baseDir . '/classes'),
);

View File

@@ -0,0 +1,36 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0e8415491642f27914717986db49b1db
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit0e8415491642f27914717986db49b1db', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit0e8415491642f27914717986db49b1db', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit0e8415491642f27914717986db49b1db::getInitializer($loader));
$loader->register(true);
return $loader;
}
}

View File

@@ -0,0 +1,36 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInit0e8415491642f27914717986db49b1db
{
public static $prefixLengthsPsr4 = array (
'D' =>
array (
'Dpp\\' => 4,
),
);
public static $prefixDirsPsr4 = array (
'Dpp\\' =>
array (
0 => __DIR__ . '/../..' . '/classes',
),
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0e8415491642f27914717986db49b1db::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0e8415491642f27914717986db49b1db::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0e8415491642f27914717986db49b1db::$classMap;
}, null, ClassLoader::class);
}
}