1<?php 2 3namespace Facebook\WebDriver\Interactions\Internal; 4 5use Facebook\WebDriver\Internal\WebDriverLocatable; 6use Facebook\WebDriver\WebDriverAction; 7use Facebook\WebDriver\WebDriverKeyboard; 8use Facebook\WebDriver\WebDriverKeys; 9use Facebook\WebDriver\WebDriverMouse; 10 11abstract class WebDriverSingleKeyAction extends WebDriverKeysRelatedAction implements WebDriverAction 12{ 13 const MODIFIER_KEYS = [ 14 WebDriverKeys::SHIFT, 15 WebDriverKeys::LEFT_SHIFT, 16 WebDriverKeys::RIGHT_SHIFT, 17 WebDriverKeys::CONTROL, 18 WebDriverKeys::LEFT_CONTROL, 19 WebDriverKeys::RIGHT_CONTROL, 20 WebDriverKeys::ALT, 21 WebDriverKeys::LEFT_ALT, 22 WebDriverKeys::RIGHT_ALT, 23 WebDriverKeys::META, 24 WebDriverKeys::RIGHT_META, 25 WebDriverKeys::COMMAND, 26 ]; 27 28 /** @var string */ 29 protected $key; 30 31 /** 32 * @param string $key 33 * @todo Remove default $key value in next major version (BC) 34 */ 35 public function __construct( 36 WebDriverKeyboard $keyboard, 37 WebDriverMouse $mouse, 38 WebDriverLocatable $location_provider = null, 39 $key = '' 40 ) { 41 parent::__construct($keyboard, $mouse, $location_provider); 42 43 if (!in_array($key, self::MODIFIER_KEYS, true)) { 44 throw new \InvalidArgumentException( 45 sprintf( 46 'keyDown / keyUp actions can only be used for modifier keys, but "%s" was given', 47 $key 48 ) 49 ); 50 } 51 $this->key = $key; 52 } 53} 54