@@ -6,67 +6,67 @@ |
||
| 6 | 6 | |
| 7 | 7 | class PackagistApi |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var HttpClientInterface |
|
| 11 | - */ |
|
| 12 | - private $client; |
|
| 9 | + /** |
|
| 10 | + * @var HttpClientInterface |
|
| 11 | + */ |
|
| 12 | + private $client; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * PackagistApi constructor. |
|
| 16 | - * @param HttpClientInterface $client |
|
| 17 | - */ |
|
| 18 | - public function __construct(HttpClientInterface $client) |
|
| 19 | - { |
|
| 20 | - $this->client = $client; |
|
| 21 | - } |
|
| 14 | + /** |
|
| 15 | + * PackagistApi constructor. |
|
| 16 | + * @param HttpClientInterface $client |
|
| 17 | + */ |
|
| 18 | + public function __construct(HttpClientInterface $client) |
|
| 19 | + { |
|
| 20 | + $this->client = $client; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param string $package_name |
|
| 25 | - * @return false|mixed |
|
| 26 | - */ |
|
| 27 | - public function getPackageInformation(string $package_name) |
|
| 28 | - { |
|
| 29 | - if ($this->package_info) { |
|
| 30 | - return $this->package_info; |
|
| 31 | - } |
|
| 23 | + /** |
|
| 24 | + * @param string $package_name |
|
| 25 | + * @return false|mixed |
|
| 26 | + */ |
|
| 27 | + public function getPackageInformation(string $package_name) |
|
| 28 | + { |
|
| 29 | + if ($this->package_info) { |
|
| 30 | + return $this->package_info; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - if (!strpos($package_name, "/")) { |
|
| 34 | - return false; |
|
| 35 | - } |
|
| 33 | + if (!strpos($package_name, "/")) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - $packgist_url = "https://repo.packagist.org/p/".$package_name.".json"; |
|
| 38 | - $response = $this->client->request("GET", $packgist_url); |
|
| 37 | + $packgist_url = "https://repo.packagist.org/p/".$package_name.".json"; |
|
| 38 | + $response = $this->client->request("GET", $packgist_url); |
|
| 39 | 39 | |
| 40 | - if ($response->getStatusCode() == 200) { |
|
| 41 | - $content = json_decode($response->getContent(), true); |
|
| 42 | - if (is_array($content) && $content["packages"] && $content["packages"][$this->package->getPackageName()]) { |
|
| 43 | - $this->package_info = $content["packages"][$this->package->getPackageName()]; |
|
| 44 | - return $this->package_info; |
|
| 45 | - } |
|
| 46 | - } |
|
| 40 | + if ($response->getStatusCode() == 200) { |
|
| 41 | + $content = json_decode($response->getContent(), true); |
|
| 42 | + if (is_array($content) && $content["packages"] && $content["packages"][$this->package->getPackageName()]) { |
|
| 43 | + $this->package_info = $content["packages"][$this->package->getPackageName()]; |
|
| 44 | + return $this->package_info; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - return false; |
|
| 49 | - } |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $package_name |
|
| 53 | - * @return false|int|string|null |
|
| 54 | - */ |
|
| 55 | - public function getLastPackagistVersion(string $package_name) |
|
| 56 | - { |
|
| 57 | - if (!strpos($package_name, "/")) { |
|
| 58 | - return false; |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * @param string $package_name |
|
| 53 | + * @return false|int|string|null |
|
| 54 | + */ |
|
| 55 | + public function getLastPackagistVersion(string $package_name) |
|
| 56 | + { |
|
| 57 | + if (!strpos($package_name, "/")) { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $packgist_url = "https://repo.packagist.org/p/".$package_name.".json"; |
|
| 61 | + $packgist_url = "https://repo.packagist.org/p/".$package_name.".json"; |
|
| 62 | 62 | |
| 63 | - $response = $this->client->request("GET", $packgist_url); |
|
| 63 | + $response = $this->client->request("GET", $packgist_url); |
|
| 64 | 64 | |
| 65 | - if ($response->getStatusCode() == 200) { |
|
| 66 | - $content = json_decode($response->getContent(), true); |
|
| 67 | - if (is_array($content) && $content["packages"] && $content["packages"][$this->package->getPackageName()]) { |
|
| 68 | - return array_key_first($content["packages"][$this->package->getPackageName()]); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 65 | + if ($response->getStatusCode() == 200) { |
|
| 66 | + $content = json_decode($response->getContent(), true); |
|
| 67 | + if (is_array($content) && $content["packages"] && $content["packages"][$this->package->getPackageName()]) { |
|
| 68 | + return array_key_first($content["packages"][$this->package->getPackageName()]); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $packgist_url = "https://repo.packagist.org/p/".$package_name.".json"; |
|
| 37 | + $packgist_url = "https://repo.packagist.org/p/" . $package_name . ".json"; |
|
| 38 | 38 | $response = $this->client->request("GET", $packgist_url); |
| 39 | 39 | |
| 40 | 40 | if ($response->getStatusCode() == 200) { |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | return false; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $packgist_url = "https://repo.packagist.org/p/".$package_name.".json"; |
|
| 61 | + $packgist_url = "https://repo.packagist.org/p/" . $package_name . ".json"; |
|
| 62 | 62 | |
| 63 | 63 | $response = $this->client->request("GET", $packgist_url); |
| 64 | 64 | |
@@ -13,52 +13,52 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PackagesDistController extends AbstractController |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @Route("/packages/send-package/{package_name}", name="ribsadmin_packages_send", requirements={"package_name"=".+"}) |
|
| 18 | - * @param EntityManagerInterface $em |
|
| 19 | - * @param Version $version |
|
| 20 | - * @param string $package_name |
|
| 21 | - * @return mixed|null |
|
| 22 | - * @throws Exception |
|
| 23 | - */ |
|
| 24 | - public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
| 25 | - { |
|
| 26 | - $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
| 16 | + /** |
|
| 17 | + * @Route("/packages/send-package/{package_name}", name="ribsadmin_packages_send", requirements={"package_name"=".+"}) |
|
| 18 | + * @param EntityManagerInterface $em |
|
| 19 | + * @param Version $version |
|
| 20 | + * @param string $package_name |
|
| 21 | + * @return mixed|null |
|
| 22 | + * @throws Exception |
|
| 23 | + */ |
|
| 24 | + public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
| 25 | + { |
|
| 26 | + $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
| 27 | 27 | |
| 28 | - if ($package) { |
|
| 29 | - $version->setPackageEntity($package); |
|
| 30 | - } |
|
| 28 | + if ($package) { |
|
| 29 | + $version->setPackageEntity($package); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - return new JsonResponse([ |
|
| 33 | - "package" => $version->getPackage(), |
|
| 34 | - "package_date" => $version->getVersionDate() |
|
| 35 | - ]); |
|
| 36 | - } |
|
| 32 | + return new JsonResponse([ |
|
| 33 | + "package" => $version->getPackage(), |
|
| 34 | + "package_date" => $version->getVersionDate() |
|
| 35 | + ]); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @Route("/packages/send-composer-lock/", name="ribsadmin_packages_send_composer_lock") |
|
| 40 | - * @return JsonResponse |
|
| 41 | - */ |
|
| 42 | - public function sendComposerJson(): JsonResponse |
|
| 43 | - { |
|
| 44 | - $composer_lock = file_get_contents('../composer.lock'); |
|
| 38 | + /** |
|
| 39 | + * @Route("/packages/send-composer-lock/", name="ribsadmin_packages_send_composer_lock") |
|
| 40 | + * @return JsonResponse |
|
| 41 | + */ |
|
| 42 | + public function sendComposerJson(): JsonResponse |
|
| 43 | + { |
|
| 44 | + $composer_lock = file_get_contents('../composer.lock'); |
|
| 45 | 45 | |
| 46 | - if ($composer_lock) { |
|
| 47 | - $composer_lock = json_decode($composer_lock); |
|
| 48 | - } |
|
| 46 | + if ($composer_lock) { |
|
| 47 | + $composer_lock = json_decode($composer_lock); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return new JsonResponse($composer_lock); |
|
| 51 | - } |
|
| 50 | + return new JsonResponse($composer_lock); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @Route("/packages/send-token/", name="ribsadmin_packages_send_token") |
|
| 55 | - * @param ParameterBagInterface $parameter |
|
| 56 | - * @return JsonResponse |
|
| 57 | - */ |
|
| 58 | - public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
| 59 | - { |
|
| 60 | - return new JsonResponse([ |
|
| 61 | - "token" => $parameter->get("ribs_admin.packages_token") |
|
| 62 | - ]); |
|
| 63 | - } |
|
| 53 | + /** |
|
| 54 | + * @Route("/packages/send-token/", name="ribsadmin_packages_send_token") |
|
| 55 | + * @param ParameterBagInterface $parameter |
|
| 56 | + * @return JsonResponse |
|
| 57 | + */ |
|
| 58 | + public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
| 59 | + { |
|
| 60 | + return new JsonResponse([ |
|
| 61 | + "token" => $parameter->get("ribs_admin.packages_token") |
|
| 62 | + ]); |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -14,108 +14,108 @@ |
||
| 14 | 14 | |
| 15 | 15 | class PackageController extends AbstractController |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @Route("/packages/", name="ribsadmin_packages") |
|
| 19 | - * @param EntityManagerInterface $em |
|
| 20 | - * @return Response |
|
| 21 | - */ |
|
| 22 | - public function index(EntityManagerInterface $em): Response |
|
| 23 | - { |
|
| 24 | - $packages = $em->getRepository(Package::class)->findAll(); |
|
| 17 | + /** |
|
| 18 | + * @Route("/packages/", name="ribsadmin_packages") |
|
| 19 | + * @param EntityManagerInterface $em |
|
| 20 | + * @return Response |
|
| 21 | + */ |
|
| 22 | + public function index(EntityManagerInterface $em): Response |
|
| 23 | + { |
|
| 24 | + $packages = $em->getRepository(Package::class)->findAll(); |
|
| 25 | 25 | |
| 26 | - return $this->render("@RibsAdmin/packages/list.html.twig", ["packages" => $packages]); |
|
| 27 | - } |
|
| 26 | + return $this->render("@RibsAdmin/packages/list.html.twig", ["packages" => $packages]); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @Route("/packages/create/", name="ribsadmin_packages_create") |
|
| 31 | - * @Route("/packages/show/{guid}", name="ribsadmin_packages_show") |
|
| 32 | - * @Route("/packages/edit/{guid}", name="ribsadmin_packages_edit") |
|
| 33 | - * @param Request $request |
|
| 34 | - * @param EntityManagerInterface $em |
|
| 35 | - * @param string|null $guid |
|
| 36 | - * @return Response |
|
| 37 | - */ |
|
| 38 | - public function edit(Request $request, EntityManagerInterface $em, string $guid = null): Response |
|
| 39 | - { |
|
| 40 | - $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
| 41 | - if (!$guid) { |
|
| 42 | - $package = new Package(); |
|
| 43 | - $text = "created"; |
|
| 44 | - } else { |
|
| 45 | - $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
| 46 | - $text = "edited"; |
|
| 47 | - } |
|
| 29 | + /** |
|
| 30 | + * @Route("/packages/create/", name="ribsadmin_packages_create") |
|
| 31 | + * @Route("/packages/show/{guid}", name="ribsadmin_packages_show") |
|
| 32 | + * @Route("/packages/edit/{guid}", name="ribsadmin_packages_edit") |
|
| 33 | + * @param Request $request |
|
| 34 | + * @param EntityManagerInterface $em |
|
| 35 | + * @param string|null $guid |
|
| 36 | + * @return Response |
|
| 37 | + */ |
|
| 38 | + public function edit(Request $request, EntityManagerInterface $em, string $guid = null): Response |
|
| 39 | + { |
|
| 40 | + $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
| 41 | + if (!$guid) { |
|
| 42 | + $package = new Package(); |
|
| 43 | + $text = "created"; |
|
| 44 | + } else { |
|
| 45 | + $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
| 46 | + $text = "edited"; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Package::class, $package, ["disabled" => $disabled_form]); |
|
| 50 | - $form->handleRequest($request); |
|
| 49 | + $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Package::class, $package, ["disabled" => $disabled_form]); |
|
| 50 | + $form->handleRequest($request); |
|
| 51 | 51 | |
| 52 | - if ($form->isSubmitted() && $form->isValid()) { |
|
| 53 | - /** @var Package $data */ |
|
| 54 | - $data = $form->getData(); |
|
| 55 | - $em->persist($data); |
|
| 56 | - $em->flush(); |
|
| 57 | - $this->addFlash("success-flash", "Package " . $data->getProjectName() . " was " . $text); |
|
| 52 | + if ($form->isSubmitted() && $form->isValid()) { |
|
| 53 | + /** @var Package $data */ |
|
| 54 | + $data = $form->getData(); |
|
| 55 | + $em->persist($data); |
|
| 56 | + $em->flush(); |
|
| 57 | + $this->addFlash("success-flash", "Package " . $data->getProjectName() . " was " . $text); |
|
| 58 | 58 | |
| 59 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
| 60 | - } |
|
| 59 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return $this->render("@RibsAdmin/packages/edit.html.twig", [ |
|
| 63 | - "disabled_form" => $disabled_form, |
|
| 64 | - "form" => $form->createView(), |
|
| 65 | - "form_errors" => $form->getErrors(), |
|
| 66 | - "package" => $package |
|
| 67 | - ]); |
|
| 68 | - } |
|
| 62 | + return $this->render("@RibsAdmin/packages/edit.html.twig", [ |
|
| 63 | + "disabled_form" => $disabled_form, |
|
| 64 | + "form" => $form->createView(), |
|
| 65 | + "form_errors" => $form->getErrors(), |
|
| 66 | + "package" => $package |
|
| 67 | + ]); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @Route("/packages/delete/{guid}", name="ribsadmin_packages_delete") |
|
| 72 | - * @param EntityManagerInterface $em |
|
| 73 | - * @param string $guid |
|
| 74 | - * @return RedirectResponse |
|
| 75 | - */ |
|
| 76 | - public function delete(EntityManagerInterface $em, string $guid): RedirectResponse |
|
| 77 | - { |
|
| 78 | - $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
| 70 | + /** |
|
| 71 | + * @Route("/packages/delete/{guid}", name="ribsadmin_packages_delete") |
|
| 72 | + * @param EntityManagerInterface $em |
|
| 73 | + * @param string $guid |
|
| 74 | + * @return RedirectResponse |
|
| 75 | + */ |
|
| 76 | + public function delete(EntityManagerInterface $em, string $guid): RedirectResponse |
|
| 77 | + { |
|
| 78 | + $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
| 79 | 79 | |
| 80 | - if ($package) { |
|
| 81 | - $em->remove($package); |
|
| 82 | - $em->flush(); |
|
| 83 | - $this->addFlash("success-flash", "The project package was deleted"); |
|
| 84 | - } else { |
|
| 85 | - $this->addFlash("error-flash", "The project package was not found"); |
|
| 86 | - } |
|
| 80 | + if ($package) { |
|
| 81 | + $em->remove($package); |
|
| 82 | + $em->flush(); |
|
| 83 | + $this->addFlash("success-flash", "The project package was deleted"); |
|
| 84 | + } else { |
|
| 85 | + $this->addFlash("error-flash", "The project package was not found"); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
| 89 | - } |
|
| 88 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @Route("/packages/update/{guid}", name="ribsadmin_packages_update") |
|
| 93 | - * @param Version $version |
|
| 94 | - * @param string $guid |
|
| 95 | - * @return RedirectResponse |
|
| 96 | - * @throws Exception |
|
| 97 | - */ |
|
| 98 | - public function updatePackage(Version $version, string $guid): RedirectResponse |
|
| 99 | - { |
|
| 100 | - if ($guid) { |
|
| 101 | - $version->save($guid); |
|
| 91 | + /** |
|
| 92 | + * @Route("/packages/update/{guid}", name="ribsadmin_packages_update") |
|
| 93 | + * @param Version $version |
|
| 94 | + * @param string $guid |
|
| 95 | + * @return RedirectResponse |
|
| 96 | + * @throws Exception |
|
| 97 | + */ |
|
| 98 | + public function updatePackage(Version $version, string $guid): RedirectResponse |
|
| 99 | + { |
|
| 100 | + if ($guid) { |
|
| 101 | + $version->save($guid); |
|
| 102 | 102 | |
| 103 | - if ($version->getMessages()) { |
|
| 104 | - $message = "<ul>"; |
|
| 105 | - $message .= "<li>The project package was not well updated</li>"; |
|
| 106 | - foreach ($version->getMessages() as $version_message) { |
|
| 107 | - $message .= "<li>".$version_message."</li>"; |
|
| 108 | - } |
|
| 109 | - $message .= "</ul>"; |
|
| 103 | + if ($version->getMessages()) { |
|
| 104 | + $message = "<ul>"; |
|
| 105 | + $message .= "<li>The project package was not well updated</li>"; |
|
| 106 | + foreach ($version->getMessages() as $version_message) { |
|
| 107 | + $message .= "<li>".$version_message."</li>"; |
|
| 108 | + } |
|
| 109 | + $message .= "</ul>"; |
|
| 110 | 110 | |
| 111 | - $this->addFlash("info-flash", $message); |
|
| 112 | - } else { |
|
| 113 | - $this->addFlash("success-flash", "The project package was updated"); |
|
| 114 | - } |
|
| 115 | - } else { |
|
| 116 | - $this->addFlash("error-flash", "The project package was not found"); |
|
| 117 | - } |
|
| 111 | + $this->addFlash("info-flash", $message); |
|
| 112 | + } else { |
|
| 113 | + $this->addFlash("success-flash", "The project package was updated"); |
|
| 114 | + } |
|
| 115 | + } else { |
|
| 116 | + $this->addFlash("error-flash", "The project package was not found"); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
| 120 | - } |
|
| 119 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
| 120 | + } |
|
| 121 | 121 | } |