123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Mmoreramerino\GearmanBundle\Service;
- use Symfony\Component\Yaml\Parser;
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Mmoreramerino\GearmanBundle\Exceptions\SettingsNotLoadedException;
- use Mmoreramerino\GearmanBundle\Exceptions\NoSettingsFileExistsException;
- /**
- * Class GearmanSettings
- *
- * @author Marc Morera <marc@ulabox.com>
- */
- class GearmanSettings extends ContainerAware
- {
- /**
- * Settings defined into settings file
- *
- * @var Array
- */
- private $settings = null;
-
- /**
- * Return Gearman settings, previously loaded by method load()
- * If settings are not loaded, a SettingsNotLoadedException Exception is thrown
- *
- * @return array Settings getted from file
- */
- public function getSettings()
- {
- if (null === $this->settings) {
- throw new SettingsNotLoadedException();
- }
-
- return $this->settings;
- }
-
- /**
- * Get yaml file and load all settings for Gearman engine
- *
- * @param type $settingsPath Resource path to get settings
- * @return array Settings
- */
- public function loadSettings($settingsPath)
- {
-
- if (!file_exists($settingsPath)) {
- throw new NoSettingsFileExistsException($settingsPath);
- }
-
- $yaml = new Parser();
- $this->settings = $yaml->parse(file_get_contents($settingsPath));
-
- return $this->settings;
- }
- }
|