Kaynağa Gözat

optional-callbacks

Alexandru Miron 11 yıl önce
ebeveyn
işleme
0b2b5f21fa

+ 3 - 0
DependencyInjection/Configuration.php

@@ -77,6 +77,9 @@ class Configuration implements ConfigurationInterface
                         ->scalarNode('method')
                             ->defaultValue('doNormal')
                         ->end()
+                        ->scalarNode('callbacks')
+                            ->defaultValue(true)
+                        ->end()
                     ->end()
                 ->end()
             ->end();

+ 2 - 1
Resources/config/services.yml

@@ -39,4 +39,5 @@ services:
         parent: gearman.abstract.service
         calls:
           - [setDefaultServers, [%gearman.servers%]]
-          - [setGearmanCallbacks, [@gearman.callbacks]]
+          - [setGearmanCallbacks, [@gearman.callbacks]]
+          - [setDefaultSettings, [%gearman.default.settings%]]

+ 25 - 1
Service/GearmanClient.php

@@ -50,6 +50,13 @@ class GearmanClient extends AbstractGearmanService
      */
     protected $defaultServers;
 
+    /**
+     * @var array
+     *
+     * Set default settings
+     */
+    protected $settings;
+
 
     /**
      * Set  default servers
@@ -80,6 +87,20 @@ class GearmanClient extends AbstractGearmanService
         return $this;
     }
 
+    /**
+     * Set default settings
+     *
+     * @param array $settings
+     *
+     * @return GearmanClient self Object
+     */
+    public function setDefaultSettings($settings)
+    {
+        $this->settings = $settings;
+
+        return $this;
+    }
+
 
     /**
      * Set server to client. Empty all servers and set this one
@@ -548,7 +569,10 @@ class GearmanClient extends AbstractGearmanService
     {
         $gearmanClient = new \GearmanClient();
         $this->assignServers($gearmanClient);
-        $this->gearmanCallbacks->assignTaskCallbacks($gearmanClient);
+
+        if ($this->settings['callbacks']) {
+            $this->gearmanCallbacks->assignTaskCallbacks($gearmanClient);
+        }
 
         foreach ($this->taskStructure as $task) {