|  |  |  | <?php
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace core\services;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use core\entities\Settings;
 | 
					
						
							|  |  |  | use core\forms\SettingsForm;
 | 
					
						
							|  |  |  | use core\repositories\SettingsRepository;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SettingsService
 | 
					
						
							|  |  |  | {
 | 
					
						
							|  |  |  |     private $_repository;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function __construct(SettingsRepository $repository)
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         $this->_repository = $repository;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function create(SettingsForm $form): Settings
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         $settings = Settings::create(
 | 
					
						
							|  |  |  |             $form->type,
 | 
					
						
							|  |  |  |             $form->section,
 | 
					
						
							|  |  |  |             $form->key,
 | 
					
						
							|  |  |  |             $form->value,
 | 
					
						
							|  |  |  |             $form->active
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  |         $this->_repository->save($settings);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $settings;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function edit($id, SettingsForm $form): void
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         $settings = $this->_repository->get($id);
 | 
					
						
							|  |  |  |         $settings->edit(
 | 
					
						
							|  |  |  |             $form->type,
 | 
					
						
							|  |  |  |             $form->section,
 | 
					
						
							|  |  |  |             $form->key,
 | 
					
						
							|  |  |  |             $form->value,
 | 
					
						
							|  |  |  |             $form->active
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  |         $this->_repository->save($settings);
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function remove($id): void
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         $settings = $this->_repository->get($id);
 | 
					
						
							|  |  |  |         $this->_repository->remove($settings);
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 |