| 1 |  |  | <?php
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Kir\Services\Cmd\Dispatcher\Builder;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Kir\Services\Cmd\Dispatcher\AttributeRepositories\MySQLAttributeRepository;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Kir\Services\Cmd\Dispatcher\Dispatcher;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Kir\Services\Cmd\Dispatcher\Dispatchers\DefaultDispatcher;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use PDO;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class MySQLBuilder {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	/** @var PDO */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	private $pdo;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	/** @var bool */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	private $useLocking = true;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	/** @var string */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	private $lockPrefix = '';
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	/**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 * @param PDO $pdo
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	public function __construct(PDO $pdo) {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->pdo = $pdo;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	}
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	/**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 * Enabled by default.
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	 * You can disable global locking (using MySQL's GET_LOCK) per service-run.
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * A Lock will be optained before a service runs and will be released, is the service is done
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * (or an exception was thrown during the run)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * @param bool $useLocking
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * @return $this
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	public function useLocking(bool $useLocking = true): self {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$this->useLocking = $useLocking;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		return $this;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	}
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	/**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * Set the lock-prefix for the MySQL-`GET_LOCK` name.
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * You can think of it as calling the function like this:
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 * `SELECT GET_LOCK(CONCAT(<lock-prefix>, <registered-service-name>), 0)`
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * Something like `my-app:` would result in `my-app:service-xy` if the particular service was registered as
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * `service-xy`. The Lock is per service. Between two services, the lock will be released and reoptained.
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * @param string $lockPrefix
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * @return $this
 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  | 	 */
 | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 	public function setLockPrefix(string $lockPrefix = ''): self {
 | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 		$this->lockPrefix = $lockPrefix;
 | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 		return $this;
 | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 	}
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	/**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	 * @return DefaultDispatcher
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	public function build(): DefaultDispatcher {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$repos = new MySQLAttributeRepository($this->pdo, [
 | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			'use-locking' => $this->useLocking,
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			'lock-prefix' => $this->lockPrefix,
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		]);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		return new DefaultDispatcher($repos);
 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  | 	}
 | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: