diff --git a/.env b/.env index 9ab7fbc1d8..47e1c7d4d8 100644 --- a/.env +++ b/.env @@ -29,5 +29,8 @@ APP_SECRET=6a9ac3a09c73230107373e8e0b71e0a3 # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8" # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml -DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7 +DATABASE_URL=postgresql://postgres:foobar@postgres:5432/social +#?serverVersion=11&charset=utf8 ###< doctrine/doctrine-bundle ### + +SHELL_VERBOSITY=3 \ No newline at end of file diff --git a/composer.json b/composer.json index c7db06f4a0..04aee3cfbd 100644 --- a/composer.json +++ b/composer.json @@ -4,13 +4,14 @@ "description": "Free software social networking platform.", "license": "AGPL-3.0-only", "require": { - "php": "^7.2.5", + "php": "^7.4", "ext-ctype": "*", "ext-iconv": "*", "sensio/framework-extra-bundle": "^5.1", "symfony/asset": "5.0.*", "symfony/console": "5.0.*", "symfony/dotenv": "^5.0", + "symfony/event-dispatcher": "5.0.*", "symfony/expression-language": "5.0.*", "symfony/flex": "^1.3.1", "symfony/form": "5.0.*", @@ -46,7 +47,7 @@ "autoload": { "psr-4": { "App\\": "src/" - } + } }, "autoload-dev": { "psr-4": { diff --git a/composer.lock b/composer.lock index 265d424ccc..013ece9f5f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8e75c2f59e6c9fc1461a56bc9188ad2e", + "content-hash": "a44927e48b5d624111b558f2a0e2b5c4", "packages": [ { "name": "doctrine/annotations", @@ -1257,177 +1257,6 @@ ], "time": "2014-01-12T16:20:24+00:00" }, - { - "name": "laminas/laminas-code", - "version": "3.4.1", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-code.git", - "reference": "1cb8f203389ab1482bf89c0e70a04849bacd7766" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-code/zipball/1cb8f203389ab1482bf89c0e70a04849bacd7766", - "reference": "1cb8f203389ab1482bf89c0e70a04849bacd7766", - "shasum": "" - }, - "require": { - "laminas/laminas-eventmanager": "^2.6 || ^3.0", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.1" - }, - "conflict": { - "phpspec/prophecy": "<1.9.0" - }, - "replace": { - "zendframework/zend-code": "self.version" - }, - "require-dev": { - "doctrine/annotations": "^1.7", - "ext-phar": "*", - "laminas/laminas-coding-standard": "^1.0", - "laminas/laminas-stdlib": "^2.7 || ^3.0", - "phpunit/phpunit": "^7.5.16 || ^8.4" - }, - "suggest": { - "doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features", - "laminas/laminas-stdlib": "Laminas\\Stdlib component" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4.x-dev", - "dev-develop": "3.5.x-dev", - "dev-dev-4.0": "4.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Laminas\\Code\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Extensions to the PHP Reflection API, static code scanning, and code generation", - "homepage": "https://laminas.dev", - "keywords": [ - "code", - "laminas" - ], - "time": "2019-12-31T16:28:24+00:00" - }, - { - "name": "laminas/laminas-eventmanager", - "version": "3.2.1", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-eventmanager.git", - "reference": "ce4dc0bdf3b14b7f9815775af9dfee80a63b4748" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-eventmanager/zipball/ce4dc0bdf3b14b7f9815775af9dfee80a63b4748", - "reference": "ce4dc0bdf3b14b7f9815775af9dfee80a63b4748", - "shasum": "" - }, - "require": { - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^5.6 || ^7.0" - }, - "replace": { - "zendframework/zend-eventmanager": "self.version" - }, - "require-dev": { - "athletic/athletic": "^0.1", - "container-interop/container-interop": "^1.1.0", - "laminas/laminas-coding-standard": "~1.0.0", - "laminas/laminas-stdlib": "^2.7.3 || ^3.0", - "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2" - }, - "suggest": { - "container-interop/container-interop": "^1.1.0, to use the lazy listeners feature", - "laminas/laminas-stdlib": "^2.7.3 || ^3.0, to use the FilterChain feature" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.2-dev", - "dev-develop": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Laminas\\EventManager\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Trigger and listen to events within a PHP application", - "homepage": "https://laminas.dev", - "keywords": [ - "event", - "eventmanager", - "events", - "laminas" - ], - "time": "2019-12-31T16:44:52+00:00" - }, - { - "name": "laminas/laminas-zendframework-bridge", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-zendframework-bridge.git", - "reference": "0fb9675b84a1666ab45182b6c5b29956921e818d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/0fb9675b84a1666ab45182b6c5b29956921e818d", - "reference": "0fb9675b84a1666ab45182b6c5b29956921e818d", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.1", - "squizlabs/php_codesniffer": "^3.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev", - "dev-develop": "1.1.x-dev" - }, - "laminas": { - "module": "Laminas\\ZendFrameworkBridge" - } - }, - "autoload": { - "files": [ - "src/autoload.php" - ], - "psr-4": { - "Laminas\\ZendFrameworkBridge\\": "src//" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Alias legacy ZF class names to Laminas Project equivalents.", - "keywords": [ - "ZendFramework", - "autoloading", - "laminas", - "zf" - ], - "time": "2020-01-07T22:58:31+00:00" - }, { "name": "monolog/monolog", "version": "2.0.2", @@ -1511,35 +1340,35 @@ }, { "name": "ocramius/package-versions", - "version": "1.7.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/Ocramius/PackageVersions.git", - "reference": "651c372efc914aea8223e049f85afaf65e09ba23" + "reference": "1d32342b8c1eb27353c8887c366147b4c2da673c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/651c372efc914aea8223e049f85afaf65e09ba23", - "reference": "651c372efc914aea8223e049f85afaf65e09ba23", + "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/1d32342b8c1eb27353c8887c366147b4c2da673c", + "reference": "1d32342b8c1eb27353c8887c366147b4c2da673c", "shasum": "" }, "require": { - "composer-plugin-api": "^1.1.0", - "php": "^7.4.0" + "composer-plugin-api": "^1.0.0", + "php": "^7.3.0" }, "require-dev": { - "composer/composer": "^1.9.3", - "doctrine/coding-standard": "^7.0.2", - "ext-zip": "^1.15.0", - "infection/infection": "^0.15.3", - "phpunit/phpunit": "^9.0.1", - "vimeo/psalm": "^3.9.3" + "composer/composer": "^1.8.6", + "doctrine/coding-standard": "^6.0.0", + "ext-zip": "*", + "infection/infection": "^0.13.4", + "phpunit/phpunit": "^8.2.5", + "vimeo/psalm": "^3.4.9" }, "type": "composer-plugin", "extra": { "class": "PackageVersions\\Installer", "branch-alias": { - "dev-master": "1.99.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -1558,49 +1387,44 @@ } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "time": "2020-03-06T11:34:16+00:00" + "time": "2019-07-17T15:49:50+00:00" }, { "name": "ocramius/proxy-manager", - "version": "2.7.0", + "version": "2.2.3", "source": { "type": "git", "url": "https://github.com/Ocramius/ProxyManager.git", - "reference": "e77928e8f11ea36b388f87e75c993d05f5da6bf1" + "reference": "4d154742e31c35137d5374c998e8f86b54db2e2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ocramius/ProxyManager/zipball/e77928e8f11ea36b388f87e75c993d05f5da6bf1", - "reference": "e77928e8f11ea36b388f87e75c993d05f5da6bf1", + "url": "https://api.github.com/repos/Ocramius/ProxyManager/zipball/4d154742e31c35137d5374c998e8f86b54db2e2f", + "reference": "4d154742e31c35137d5374c998e8f86b54db2e2f", "shasum": "" }, "require": { - "laminas/laminas-code": "^3.4.1", - "ocramius/package-versions": "^1.5.1", - "php": "7.4.*", - "webimpress/safe-writer": "^2.0" - }, - "conflict": { - "doctrine/annotations": "<1.6.1", - "laminas/laminas-stdlib": "<3.2.1", - "zendframework/zend-stdlib": "<3.2.1" + "ocramius/package-versions": "^1.1.3", + "php": "^7.2.0", + "zendframework/zend-code": "^3.3.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0.0", + "couscous/couscous": "^1.6.1", "ext-phar": "*", - "infection/infection": "^0.15.0", - "nikic/php-parser": "^4.3.0", - "phpbench/phpbench": "^0.17.0", - "phpunit/phpunit": "^8.5.2", - "slevomat/coding-standard": "^5.0.4", - "squizlabs/php_codesniffer": "^3.5.4", - "vimeo/psalm": "^3.8.5" + "humbug/humbug": "1.0.0-RC.0@RC", + "nikic/php-parser": "^3.1.1", + "padraic/phpunit-accelerator": "dev-master@DEV", + "phpbench/phpbench": "^0.12.2", + "phpstan/phpstan": "dev-master#856eb10a81c1d27c701a83f167dc870fd8f4236a as 0.9.999", + "phpstan/phpstan-phpunit": "dev-master#5629c0a1f4a9c417cb1077cf6693ad9753895761", + "phpunit/phpunit": "^6.4.3", + "squizlabs/php_codesniffer": "^2.9.1" }, "suggest": { - "laminas/laminas-json": "To have the JsonRpc adapter (Remote Object feature)", - "laminas/laminas-soap": "To have the Soap adapter (Remote Object feature)", - "laminas/laminas-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)", - "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects" + "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects", + "zendframework/zend-json": "To have the JsonRpc adapter (Remote Object feature)", + "zendframework/zend-soap": "To have the Soap adapter (Remote Object feature)", + "zendframework/zend-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)" }, "type": "library", "extra": { @@ -1609,8 +1433,8 @@ } }, "autoload": { - "psr-4": { - "ProxyManager\\": "src/ProxyManager" + "psr-0": { + "ProxyManager\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1633,7 +1457,7 @@ "proxy pattern", "service proxies" ], - "time": "2020-02-08T19:22:03+00:00" + "time": "2019-08-10T08:37:15+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -6127,54 +5951,6 @@ ], "time": "2020-02-11T15:33:47+00:00" }, - { - "name": "webimpress/safe-writer", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/webimpress/safe-writer.git", - "reference": "d03bea3b98abe1d4c8b24cbebf524361ffaafee4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webimpress/safe-writer/zipball/d03bea3b98abe1d4c8b24cbebf524361ffaafee4", - "reference": "d03bea3b98abe1d4c8b24cbebf524361ffaafee4", - "shasum": "" - }, - "require": { - "php": "^7.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.4.3", - "webimpress/coding-standard": "dev-develop" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev", - "dev-develop": "2.1.x-dev", - "dev-release-1.0": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Webimpress\\SafeWriter\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "Tool to write files safely, to avoid race conditions", - "keywords": [ - "concurrent write", - "file writer", - "race condition", - "safe writer", - "webimpress" - ], - "time": "2019-11-27T19:40:53+00:00" - }, { "name": "webmozart/assert", "version": "1.7.0", @@ -6222,6 +5998,119 @@ "validate" ], "time": "2020-02-14T12:15:55+00:00" + }, + { + "name": "zendframework/zend-code", + "version": "3.4.1", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-code.git", + "reference": "268040548f92c2bfcba164421c1add2ba43abaaa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-code/zipball/268040548f92c2bfcba164421c1add2ba43abaaa", + "reference": "268040548f92c2bfcba164421c1add2ba43abaaa", + "shasum": "" + }, + "require": { + "php": "^7.1", + "zendframework/zend-eventmanager": "^2.6 || ^3.0" + }, + "conflict": { + "phpspec/prophecy": "<1.9.0" + }, + "require-dev": { + "doctrine/annotations": "^1.7", + "ext-phar": "*", + "phpunit/phpunit": "^7.5.16 || ^8.4", + "zendframework/zend-coding-standard": "^1.0", + "zendframework/zend-stdlib": "^2.7 || ^3.0" + }, + "suggest": { + "doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features", + "zendframework/zend-stdlib": "Zend\\Stdlib component" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4.x-dev", + "dev-develop": "3.5.x-dev", + "dev-dev-4.0": "4.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Code\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Extensions to the PHP Reflection API, static code scanning, and code generation", + "keywords": [ + "ZendFramework", + "code", + "zf" + ], + "abandoned": "laminas/laminas-code", + "time": "2019-12-10T19:21:15+00:00" + }, + { + "name": "zendframework/zend-eventmanager", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-eventmanager.git", + "reference": "a5e2583a211f73604691586b8406ff7296a946dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-eventmanager/zipball/a5e2583a211f73604691586b8406ff7296a946dd", + "reference": "a5e2583a211f73604691586b8406ff7296a946dd", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "athletic/athletic": "^0.1", + "container-interop/container-interop": "^1.1.0", + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-stdlib": "^2.7.3 || ^3.0" + }, + "suggest": { + "container-interop/container-interop": "^1.1.0, to use the lazy listeners feature", + "zendframework/zend-stdlib": "^2.7.3 || ^3.0, to use the FilterChain feature" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev", + "dev-develop": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\EventManager\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Trigger and listen to events within a PHP application", + "homepage": "https://github.com/zendframework/zend-eventmanager", + "keywords": [ + "event", + "eventmanager", + "events", + "zf2" + ], + "abandoned": "laminas/laminas-eventmanager", + "time": "2018-04-25T15:33:34+00:00" } ], "packages-dev": [ diff --git a/config/routes.yaml b/config/routes.yaml deleted file mode 100644 index c3283aa2e3..0000000000 --- a/config/routes.yaml +++ /dev/null @@ -1,3 +0,0 @@ -#index: -# path: / -# controller: App\Controller\DefaultController::index diff --git a/config/services.yaml b/config/services.yaml index 5c4b41757c..fed3db4a75 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -15,7 +15,7 @@ services: # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/*' - exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' + exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,lib/*}' # controllers are imported separately to make sure services can be injected # as action arguments even if you don't extend any base controller class diff --git a/src/Controller/NetworkPublic.php b/src/Controller/NetworkPublic.php index 9579f3abf7..97ac7bd4a7 100644 --- a/src/Controller/NetworkPublic.php +++ b/src/Controller/NetworkPublic.php @@ -5,12 +5,13 @@ namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use App; +use App\Util\GSEvent; class NetworkPublic extends AbstractController { public function __invoke() { + GSEvent::handle('test', ['foobar']); return $this->render('network/public.html.twig', []); } } diff --git a/src/Kernel.php b/src/Kernel.php index 1cd05726a2..10e367d701 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -8,6 +8,8 @@ use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\RouteCollectionBuilder; +use function dirname; +use const PHP_VERSION_ID; class Kernel extends BaseKernel { @@ -27,13 +29,13 @@ class Kernel extends BaseKernel public function getProjectDir(): string { - return \dirname(__DIR__); + return dirname(__DIR__); } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); - $container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug); + $container->setParameter('container.dumper.inline_class_loader', PHP_VERSION_ID < 70400 || $this->debug); $container->setParameter('container.dumper.inline_factories', true); $confDir = $this->getProjectDir().'/config'; diff --git a/src/Util/Common.php b/src/Util/Common.php new file mode 100644 index 0000000000..e31b2c3eac --- /dev/null +++ b/src/Util/Common.php @@ -0,0 +1,48 @@ +. + +namespace App\Util; + +class Common +{ + public static function normalizePath(string $path): string + { + if (DIRECTORY_SEPARATOR !== '/') { + $path = strtr($path, DIRECTORY_SEPARATOR, '/'); + } + return $path; + } + + public static function pluginFromPath(string $path): ?string + { + $plug = strpos($path, '/plugins/'); + if ($plug === false) { + return null; + } else { + $cut = $plug + strlen('/plugins/'); + $cut2 = strpos($path, '/', $cut); + if ($cut2) { + $final = substr($path, $cut, $cut2 - $cut); + } else { + // We might be running directly from the plugins dir? + // If so, there's no place to store locale info. + Log::error("The GNU social install dir seems to contain a piece named plugin"); + return false; + } + } + return $final; + } +} diff --git a/src/Util/GNUsocial.php b/src/Util/GNUsocial.php new file mode 100644 index 0000000000..92b869c669 --- /dev/null +++ b/src/Util/GNUsocial.php @@ -0,0 +1,118 @@ +. + +/** + * Main GNU social entry point + * + * @package GNUsocial + * @category Framework + * @author Brenda Wallace + * @author Brion Vibber + * @author Brion Vibber + * @author Christopher Vollick + * @author CiaranG + * @author Craig Andrews + * @author Craig Andrews + * @author Evan Prodromou + * @author Evan Prodromou + * @author Evan Prodromou + * @author Evan Prodromou + * @author Gina Haeussge + * @author James Walker + * @author Jeffery To + * @author Jeffery To + * @author Mikael Nordfeldth + * @author Mike Cochrane + * @author Robin Millette + * @author Sarven Capadisli + * @author Sarven Capadisli + * @author Siebrand Mazeland + * @author Tom Adams + * @author Tom Adams + * @author Zach Copley + * @author Diogo Cordeiro + * @author Hugo Sales + * @copyright 2010, 2018-2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Util; + +use Psr\Container\ContainerInterface; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Psr\Log\LoggerInterface; + +use App\Util\Log; +use App\Util\GSEvent; + +class GNUsocial implements EventSubscriberInterface +{ + protected ContainerInterface $container; + protected LoggerInterface $logger; + + public function __construct(ContainerInterface $container, LoggerInterface $logger) + { + $this->container = $container; + $this->logger= $logger; + } + + public function onKernelRequest(RequestEvent $event, + string $event_name, + $event_dispatcher): RequestEvent + { + if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(__DIR__)); + define('SRCDIR', INSTALLDIR . '/src'); + define('PUBLICDIR', INSTALLDIR . '/public'); + define('GNUSOCIAL_ENGINE', 'GNU social'); + // MERGE Change to https://gnu.io/social/ + define('GNUSOCIAL_ENGINE_URL', 'https://gnusocial.network/'); + // MERGE Change to https://git.gnu.io/gnu/gnu-social + define('GNUSOCIAL_ENGINE_REPO_URL', 'https://notabug.org/diogo/gnu-social/'); + // Current base version, major.minor.patch + define('GNUSOCIAL_BASE_VERSION', '3.0.0'); + // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release' + define('GNUSOCIAL_LIFECYCLE', 'dev'); + define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE); + define('GNUSOCIAL_CODENAME', 'Big bang'); + } + + /* Work internally in UTC */ + date_default_timezone_set('UTC'); + + /* Work internally with UTF-8 */ + mb_internal_encoding('UTF-8'); + + Log::setLogger($this->logger); + GSEvent::setDispatcher($event_dispatcher); + + GSEvent::addHandler('test', function ($x) { + Log::info("Logging from an event " . var_export($x, true)); + }); + + return $event; + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::REQUEST => 'onKernelRequest' + ); + } +} diff --git a/src/Util/GSEvent.php b/src/Util/GSEvent.php new file mode 100644 index 0000000000..af944f53b4 --- /dev/null +++ b/src/Util/GSEvent.php @@ -0,0 +1,143 @@ +. + +namespace App\Util; + +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; + +abstract class GSEvent { + + private static EventDispatcherInterface $dispatcher; + + public static function setDispatcher(EventDispatcherInterface $dis): void + { + self::$dispatcher = $dis; + } + + /** + * Constants to be returned from event handlers, for increased clarity + * + * bool stop - Stop other handlers from processing the event + * bool next - Allow the other handlers to process the event + */ + public const stop = false; + public const next = true; + + + /** + * Add an event handler + * + * To run some code at a particular point in GNU social processing. + * Named events include receiving an XMPP message, adding a new notice, + * or showing part of an HTML page. + * + * The arguments to the handler vary by the event. Handlers can return + * two possible values: false means that the event has been replaced by + * the handler completely, and no default processing should be done. + * Non-false means successful handling, and that the default processing + * should succeed. (Note that this only makes sense for some events.) + * + * Handlers can also abort processing by throwing an exception; these will + * be caught by the closest code and displayed as errors. + * + * @param string $name Name of the event + * @param callable $handler Code to run + * @param int $priority Higher runs first + * + * @return void + */ + public static function addHandler(string $name, callable $handler, int $priority=0): void + { + self::$dispatcher->addListener( + $name, + function ($event, $event_name, $dispatcher) use ($handler) { + if ($event instanceof GenericEvent + // Old style of events (preferred) + && call_user_func_array($handler, $event->getArguments()) == self::stop) { + $event->stopPropagation(); + return $event; + } else { + // Symfony style of events + call_user_func($handler, $event, $event_name, $dispatcher); + } + return null; + }, + $priority + ); + } + + /** + * Handle an event + * + * Events are any point in the code that we want to expose for admins + * or third-party developers to use. + * + * We pass in an array of arguments (including references, for stuff + * that can be changed), and each assigned handler gets run with those + * arguments. Exceptions can be thrown to indicate an error. + * + * @param string $name Name of the event that's happening + * @param array $args Arguments for handlers + * + * @return bool flag saying whether to continue processing, based + * on results of handlers. + */ + public static function handle(string $name, array $args = []): bool + { + return !(self::$dispatcher->dispatch( + new GenericEvent($name, $args), + $name)->isPropagationStopped()); + } + + /** + * Check to see if an event handler exists + * + * Look to see if there's any handler for a given event, or narrow + * by providing the name of a specific plugin class. + * + * @param string $name Name of the event to look for + * @param string $plugin Optional name of the plugin class to look for + * + * @return bool flag saying whether such a handler exists + */ + public static function hasHandler(string $name, ?string $plugin=null): bool + { + $listeners = self::$dispatcher->getListeners($name); + if (isset($plugin)) { + foreach ($listeners as $handler) { + if (get_class($handler[0]) == $plugin) { + return true; + } + } + } else { + return !empty($listeners); + } + return false; + } + + /** + * Get the array of handlers for $name + * + * @param string $name Name of event + * @return array + * @return array + */ + public static function getHandlers(string $name): array + { + return self::$dispatcher->getListeners($name); + } +} diff --git a/src/Util/Log.php b/src/Util/Log.php new file mode 100644 index 0000000000..a578061faf --- /dev/null +++ b/src/Util/Log.php @@ -0,0 +1,26 @@ +error($msg); + } + public static function info(string $msg): void + { + self::$logger->info($msg); + } + public static function debug(string $msg): void + { + $logger->debug($msg); + } +} diff --git a/symfony.lock b/symfony.lock index db286ef464..02eae06c1e 100644 --- a/symfony.lock +++ b/symfony.lock @@ -115,7 +115,7 @@ "version": "2.7.0" }, "php": { - "version": "7.4" + "version": "7.3" }, "phpdocumentor/reflection-common": { "version": "2.0.0" @@ -528,5 +528,11 @@ }, "webmozart/assert": { "version": "1.7.0" + }, + "zendframework/zend-code": { + "version": "3.4.1" + }, + "zendframework/zend-eventmanager": { + "version": "3.2.1" } }