Loading modules/project_browser_devel/src/Plugin/ProjectBrowserSource/RandomDataPlugin.php +1 −27 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ namespace Drupal\project_browser_devel\Plugin\ProjectBrowserSource; use Drupal\Component\Utility\Random; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\project_browser\DrupalOrg\DrupalOrgReleases; use Drupal\project_browser\Plugin\ProjectBrowserSourceInterface; use Drupal\project_browser\ProjectBrowser\Project; use Drupal\project_browser\ProjectBrowser\ProjectsResultsPage; Loading @@ -20,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @ProjectBrowserSource( * id = "random_data", * label = @Translation("Random data"), * description = @Translation("Gets random project and release information"), * description = @Translation("Gets random project and filters information"), * ) */ class RandomDataPlugin extends PluginBase implements ProjectBrowserSourceInterface, ContainerFactoryPluginInterface { Loading Loading @@ -129,30 +128,6 @@ class RandomDataPlugin extends PluginBase implements ProjectBrowserSourceInterfa return $this->getRandomIdsAndNames(20); } /** * {@inheritdoc} */ public function getProjectReleases(string $project): DrupalOrgReleases { $releases = []; $number_of_releases = rand(1, 10); for ($i = 1; $i < $number_of_releases; $i++) { $releases[] = [ 'name' => $project . ' ' . $this->randomGenerator->word(8), 'version' => $i . '.x', 'tag' => $this->randomGenerator->word(4), 'release_link' => '', 'download_link' => '', 'date' => $this->getRandomDate(), 'files' => [], 'terms' => [], 'security' => '', 'core_compatibility' => rand(6, 10), ]; } return new DrupalOrgReleases($releases); } /** * {@inheritdoc} */ Loading @@ -176,7 +151,6 @@ class RandomDataPlugin extends PluginBase implements ProjectBrowserSourceInterfa 'created' => $this->getRandomDate(), 'changed' => $this->getRandomDate(), 'status' => rand(0, 1), 'releases' => $this->getProjectReleases($machine_name), 'title' => ucwords($machine_name), 'nid' => uniqid(), 'body' => [ Loading project_browser.routing.yml +0 −10 Original line number Diff line number Diff line Loading @@ -48,16 +48,6 @@ project_browser.api_project_get_all: _permission: 'administer modules' #options: # no_cache: 'TRUE' project_browser.api_project_get_releases: path: '/drupal-org-proxy/project/releases' methods: [GET] defaults: _controller: '\Drupal\project_browser\Controller\ProjectBrowserEndpointController::getProjectReleases' _title: 'Get all project releases' requirements: _permission: 'administer modules' #options: # no_cache: 'TRUE' project_browser.browse: path: '/admin/modules/browse' defaults: Loading src/Controller/ProjectBrowserEndpointController.php +0 −38 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace Drupal\project_browser\Controller; use Drupal\Component\Serialization\Json; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\project_browser\EnabledSourceHandler; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -152,43 +151,6 @@ class ProjectBrowserEndpointController extends ControllerBase { return new JsonResponse($projects); } /** * Responds to GET requests. * * Returns a list of bundles for specified entity. * * @param \Symfony\Component\HttpFoundation\Request $request * The request. */ public function getProjectReleases(Request $request) { $current_source = $this->enabledSource->getCurrentSource(); if (!$current_source) { return new JsonResponse([], Response::HTTP_ACCEPTED); } $project = $request->query->get('project'); if ($project) { $cache_key = 'project_browser:releases:' . $project; if ($releases = $this->cacheBin->get($cache_key)) { $releases = $releases->data; } else { $releases = $current_source->getProjectReleases($project); $this->cacheBin->set($cache_key, $releases); } if (count($releases)) { $response = new JsonResponse((array) $releases); if ($response instanceof CacheableResponseInterface) { $response->addCacheableDependency($releases); } return $response; } } return new JsonResponse([], Response::HTTP_ACCEPTED); } /** * Returns a list of categories. * Loading src/DrupalOrg/DrupalOrgRelease.phpdeleted 100644 → 0 +0 −68 Original line number Diff line number Diff line <?php namespace Drupal\project_browser\DrupalOrg; use Composer\Semver\Semver; /** * Represents a single release as it will be consumed by the front-end. */ class DrupalOrgRelease { public $version; public $release_link; public $date; public $date_ago; public $is_compatible; protected $name = ''; protected $tag = ''; protected $download_link = ''; protected $files = []; protected $terms = []; protected $security = ''; protected $core_compatibility = ''; /** * Constructs a new DrupalOrgRelease. * * @param array $release * The raw data for a release. */ public function __construct(array $release) { $this->name = $release['name']; $this->version = $release['version']; $this->tag = $release['tag']; $this->release_link = $release['release_link']; $this->download_link = $release['download_link']; $this->date = $release['date']; /** @var \Drupal\Core\Datetime\DateFormatter $datedate_formatter */ $date_formatter = \Drupal::service('date.formatter'); $date_ago = $date_formatter->formatTimeDiffSince($this->date, [ 'granularity' => 2, 'return_as_object' => TRUE, ])->toRenderable(); $this->date_ago = t('@date ago', ['@date' => $date_ago['#markup']]); $this->files = $release['files']; if (array_key_exists('terms', $release)) { $this->terms = $release['terms']; } $this->security = $release['security']; if (array_key_exists('core_compatibility', $release)) { $this->core_compatibility = $release['core_compatibility']; $this->is_compatible = Semver::satisfies(\Drupal::VERSION, $this->core_compatibility); } } } src/DrupalOrg/DrupalOrgReleases.phpdeleted 100644 → 0 +0 −34 Original line number Diff line number Diff line <?php namespace Drupal\project_browser\DrupalOrg; /** * Class DrupalOrgReleases. * * This class accepts an array of releases. For each release, * it will create a DrupalOrgRelease object. * * @package Drupal\project_browser\DrupalOrg */ class DrupalOrgReleases extends \ArrayObject { /** * Constructs a new DrupalOrgReleases. * * @param array $releases * An array of release arrays to be converted to * \Drupal\project_browser\DrupalOrg\DrupalOrgRelease. */ public function __construct(array $releases) { parent::__construct( array_map( function ($release) { return new DrupalOrgRelease($release); }, $releases ), self::ARRAY_AS_PROPS ); } } Loading
modules/project_browser_devel/src/Plugin/ProjectBrowserSource/RandomDataPlugin.php +1 −27 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ namespace Drupal\project_browser_devel\Plugin\ProjectBrowserSource; use Drupal\Component\Utility\Random; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\project_browser\DrupalOrg\DrupalOrgReleases; use Drupal\project_browser\Plugin\ProjectBrowserSourceInterface; use Drupal\project_browser\ProjectBrowser\Project; use Drupal\project_browser\ProjectBrowser\ProjectsResultsPage; Loading @@ -20,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @ProjectBrowserSource( * id = "random_data", * label = @Translation("Random data"), * description = @Translation("Gets random project and release information"), * description = @Translation("Gets random project and filters information"), * ) */ class RandomDataPlugin extends PluginBase implements ProjectBrowserSourceInterface, ContainerFactoryPluginInterface { Loading Loading @@ -129,30 +128,6 @@ class RandomDataPlugin extends PluginBase implements ProjectBrowserSourceInterfa return $this->getRandomIdsAndNames(20); } /** * {@inheritdoc} */ public function getProjectReleases(string $project): DrupalOrgReleases { $releases = []; $number_of_releases = rand(1, 10); for ($i = 1; $i < $number_of_releases; $i++) { $releases[] = [ 'name' => $project . ' ' . $this->randomGenerator->word(8), 'version' => $i . '.x', 'tag' => $this->randomGenerator->word(4), 'release_link' => '', 'download_link' => '', 'date' => $this->getRandomDate(), 'files' => [], 'terms' => [], 'security' => '', 'core_compatibility' => rand(6, 10), ]; } return new DrupalOrgReleases($releases); } /** * {@inheritdoc} */ Loading @@ -176,7 +151,6 @@ class RandomDataPlugin extends PluginBase implements ProjectBrowserSourceInterfa 'created' => $this->getRandomDate(), 'changed' => $this->getRandomDate(), 'status' => rand(0, 1), 'releases' => $this->getProjectReleases($machine_name), 'title' => ucwords($machine_name), 'nid' => uniqid(), 'body' => [ Loading
project_browser.routing.yml +0 −10 Original line number Diff line number Diff line Loading @@ -48,16 +48,6 @@ project_browser.api_project_get_all: _permission: 'administer modules' #options: # no_cache: 'TRUE' project_browser.api_project_get_releases: path: '/drupal-org-proxy/project/releases' methods: [GET] defaults: _controller: '\Drupal\project_browser\Controller\ProjectBrowserEndpointController::getProjectReleases' _title: 'Get all project releases' requirements: _permission: 'administer modules' #options: # no_cache: 'TRUE' project_browser.browse: path: '/admin/modules/browse' defaults: Loading
src/Controller/ProjectBrowserEndpointController.php +0 −38 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace Drupal\project_browser\Controller; use Drupal\Component\Serialization\Json; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\project_browser\EnabledSourceHandler; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -152,43 +151,6 @@ class ProjectBrowserEndpointController extends ControllerBase { return new JsonResponse($projects); } /** * Responds to GET requests. * * Returns a list of bundles for specified entity. * * @param \Symfony\Component\HttpFoundation\Request $request * The request. */ public function getProjectReleases(Request $request) { $current_source = $this->enabledSource->getCurrentSource(); if (!$current_source) { return new JsonResponse([], Response::HTTP_ACCEPTED); } $project = $request->query->get('project'); if ($project) { $cache_key = 'project_browser:releases:' . $project; if ($releases = $this->cacheBin->get($cache_key)) { $releases = $releases->data; } else { $releases = $current_source->getProjectReleases($project); $this->cacheBin->set($cache_key, $releases); } if (count($releases)) { $response = new JsonResponse((array) $releases); if ($response instanceof CacheableResponseInterface) { $response->addCacheableDependency($releases); } return $response; } } return new JsonResponse([], Response::HTTP_ACCEPTED); } /** * Returns a list of categories. * Loading
src/DrupalOrg/DrupalOrgRelease.phpdeleted 100644 → 0 +0 −68 Original line number Diff line number Diff line <?php namespace Drupal\project_browser\DrupalOrg; use Composer\Semver\Semver; /** * Represents a single release as it will be consumed by the front-end. */ class DrupalOrgRelease { public $version; public $release_link; public $date; public $date_ago; public $is_compatible; protected $name = ''; protected $tag = ''; protected $download_link = ''; protected $files = []; protected $terms = []; protected $security = ''; protected $core_compatibility = ''; /** * Constructs a new DrupalOrgRelease. * * @param array $release * The raw data for a release. */ public function __construct(array $release) { $this->name = $release['name']; $this->version = $release['version']; $this->tag = $release['tag']; $this->release_link = $release['release_link']; $this->download_link = $release['download_link']; $this->date = $release['date']; /** @var \Drupal\Core\Datetime\DateFormatter $datedate_formatter */ $date_formatter = \Drupal::service('date.formatter'); $date_ago = $date_formatter->formatTimeDiffSince($this->date, [ 'granularity' => 2, 'return_as_object' => TRUE, ])->toRenderable(); $this->date_ago = t('@date ago', ['@date' => $date_ago['#markup']]); $this->files = $release['files']; if (array_key_exists('terms', $release)) { $this->terms = $release['terms']; } $this->security = $release['security']; if (array_key_exists('core_compatibility', $release)) { $this->core_compatibility = $release['core_compatibility']; $this->is_compatible = Semver::satisfies(\Drupal::VERSION, $this->core_compatibility); } } }
src/DrupalOrg/DrupalOrgReleases.phpdeleted 100644 → 0 +0 −34 Original line number Diff line number Diff line <?php namespace Drupal\project_browser\DrupalOrg; /** * Class DrupalOrgReleases. * * This class accepts an array of releases. For each release, * it will create a DrupalOrgRelease object. * * @package Drupal\project_browser\DrupalOrg */ class DrupalOrgReleases extends \ArrayObject { /** * Constructs a new DrupalOrgReleases. * * @param array $releases * An array of release arrays to be converted to * \Drupal\project_browser\DrupalOrg\DrupalOrgRelease. */ public function __construct(array $releases) { parent::__construct( array_map( function ($release) { return new DrupalOrgRelease($release); }, $releases ), self::ARRAY_AS_PROPS ); } }