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