Gaming.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. namespace WhichBrowser\Analyser\Header\Useragent\Device;
  3. use WhichBrowser\Constants;
  4. use WhichBrowser\Model\Version;
  5. trait Gaming
  6. {
  7. private function detectGaming($ua)
  8. {
  9. if (!preg_match('/(Nintendo|Nitro|PlayStation|PS[0-9]|Sega|Dreamcast|Xbox)/ui', $ua)) {
  10. return;
  11. }
  12. $this->detectNintendo($ua);
  13. $this->detectPlaystation($ua);
  14. $this->detectXbox($ua);
  15. $this->detectSega($ua);
  16. }
  17. /* Nintendo Wii and DS */
  18. private function detectNintendo($ua)
  19. {
  20. /* Wii */
  21. if (preg_match('/Nintendo Wii/u', $ua)) {
  22. $this->data->os->reset();
  23. $this->data->device->setIdentification([
  24. 'manufacturer' => 'Nintendo',
  25. 'model' => 'Wii',
  26. 'type' => Constants\DeviceType::GAMING,
  27. 'subtype' => Constants\DeviceSubType::CONSOLE
  28. ]);
  29. }
  30. /* Wii U */
  31. if (preg_match('/Nintendo Wii ?U/u', $ua)) {
  32. $this->data->os->reset();
  33. $this->data->device->setIdentification([
  34. 'manufacturer' => 'Nintendo',
  35. 'model' => 'Wii U',
  36. 'type' => Constants\DeviceType::GAMING,
  37. 'subtype' => Constants\DeviceSubType::CONSOLE
  38. ]);
  39. }
  40. /* DS */
  41. if (preg_match('/Nintendo DS/u', $ua) || preg_match('/Nitro.*Opera/u', $ua)) {
  42. $this->data->os->reset();
  43. $this->data->device->setIdentification([
  44. 'manufacturer' => 'Nintendo',
  45. 'model' => 'DS',
  46. 'type' => Constants\DeviceType::GAMING,
  47. 'subtype' => Constants\DeviceSubType::PORTABLE
  48. ]);
  49. }
  50. /* DSi */
  51. if (preg_match('/Nintendo DSi/u', $ua)) {
  52. $this->data->os->reset();
  53. $this->data->device->setIdentification([
  54. 'manufacturer' => 'Nintendo',
  55. 'model' => 'DSi',
  56. 'type' => Constants\DeviceType::GAMING,
  57. 'subtype' => Constants\DeviceSubType::PORTABLE
  58. ]);
  59. }
  60. /* 3DS */
  61. if (preg_match('/Nintendo 3DS/u', $ua)) {
  62. $this->data->os->reset();
  63. $this->data->os->identifyVersion('/Version\/([0-9.]*[0-9])/u', $ua);
  64. $this->data->engine->set([
  65. 'name' => 'WebKit'
  66. ]);
  67. $this->data->device->setIdentification([
  68. 'manufacturer' => 'Nintendo',
  69. 'model' => '3DS',
  70. 'type' => Constants\DeviceType::GAMING,
  71. 'subtype' => Constants\DeviceSubType::PORTABLE
  72. ]);
  73. }
  74. /* New 3DS */
  75. if (preg_match('/New Nintendo 3DS/u', $ua)) {
  76. $this->data->os->reset();
  77. $this->data->os->identifyVersion('/Version\/([0-9.]*[0-9])/u', $ua);
  78. $this->data->device->setIdentification([
  79. 'manufacturer' => 'Nintendo',
  80. 'model' => 'New 3DS',
  81. 'type' => Constants\DeviceType::GAMING,
  82. 'subtype' => Constants\DeviceSubType::PORTABLE
  83. ]);
  84. }
  85. }
  86. /* Sony PlayStation */
  87. private function detectPlaystation($ua)
  88. {
  89. /* PlayStation Portable */
  90. if (preg_match('/PlayStation Portable/u', $ua)) {
  91. $this->data->os->reset();
  92. $this->data->engine->set([
  93. 'name' => 'NetFront'
  94. ]);
  95. $this->data->device->setIdentification([
  96. 'manufacturer' => 'Sony',
  97. 'model' => 'Playstation Portable',
  98. 'type' => Constants\DeviceType::GAMING,
  99. 'subtype' => Constants\DeviceSubType::PORTABLE
  100. ]);
  101. }
  102. /* PlayStation Vita */
  103. if (preg_match('/PlayStation Vita/iu', $ua)) {
  104. $this->data->os->reset();
  105. $this->data->os->identifyVersion('/PlayStation Vita ([0-9.]*)/u', $ua);
  106. $this->data->device->setIdentification([
  107. 'manufacturer' => 'Sony',
  108. 'model' => 'Playstation Vita',
  109. 'type' => Constants\DeviceType::GAMING,
  110. 'subtype' => Constants\DeviceSubType::PORTABLE
  111. ]);
  112. if (preg_match('/VTE\//u', $ua)) {
  113. $this->data->device->model = 'Playstation TV';
  114. $this->data->device->subtype = Constants\DeviceSubType::CONSOLE;
  115. }
  116. }
  117. /* PlayStation 2 */
  118. if (preg_match('/Playstation2/u', $ua) || preg_match('/\(PS2/u', $ua)) {
  119. $this->data->os->reset();
  120. $this->data->device->setIdentification([
  121. 'manufacturer' => 'Sony',
  122. 'model' => 'Playstation 2',
  123. 'type' => Constants\DeviceType::GAMING,
  124. 'subtype' => Constants\DeviceSubType::CONSOLE
  125. ]);
  126. }
  127. /* PlayStation 3 */
  128. if (preg_match('/PlayStation 3/ui', $ua) || preg_match('/\(PS3/u', $ua)) {
  129. $this->data->os->reset();
  130. $this->data->os->identifyVersion('/PLAYSTATION 3;? ([0-9.]*)/u', $ua);
  131. if (preg_match('/PLAYSTATION 3; [123]/', $ua)) {
  132. $this->data->engine->set([
  133. 'name' => 'NetFront'
  134. ]);
  135. }
  136. $this->data->device->setIdentification([
  137. 'manufacturer' => 'Sony',
  138. 'model' => 'Playstation 3',
  139. 'type' => Constants\DeviceType::GAMING,
  140. 'subtype' => Constants\DeviceSubType::CONSOLE
  141. ]);
  142. }
  143. /* PlayStation 4 */
  144. if (preg_match('/PlayStation 4/ui', $ua)) {
  145. $this->data->os->reset();
  146. $this->data->os->identifyVersion('/PlayStation 4 ([0-9.]*)/u', $ua);
  147. $this->data->device->setIdentification([
  148. 'manufacturer' => 'Sony',
  149. 'model' => 'Playstation 4',
  150. 'type' => Constants\DeviceType::GAMING,
  151. 'subtype' => Constants\DeviceSubType::CONSOLE
  152. ]);
  153. }
  154. }
  155. /* Microsoft Xbox */
  156. private function detectXbox($ua)
  157. {
  158. /* Xbox 360 */
  159. if (preg_match('/Xbox\)$/u', $ua, $match)) {
  160. $this->data->os->reset();
  161. $this->data->device->setIdentification([
  162. 'manufacturer' => 'Microsoft',
  163. 'model' => 'Xbox 360',
  164. 'type' => Constants\DeviceType::GAMING,
  165. 'subtype' => Constants\DeviceSubType::CONSOLE
  166. ]);
  167. }
  168. /* Xbox One */
  169. if (preg_match('/Xbox One\)/u', $ua, $match)) {
  170. if ($this->data->isOs('Windows Phone', '=', '10')) {
  171. $this->data->os->name = 'Windows';
  172. $this->data->os->version->alias = '10';
  173. }
  174. if (!$this->data->isOs('Windows', '=', '10')) {
  175. $this->data->os->reset();
  176. }
  177. $this->data->device->setIdentification([
  178. 'manufacturer' => 'Microsoft',
  179. 'model' => 'Xbox One',
  180. 'type' => Constants\DeviceType::GAMING,
  181. 'subtype' => Constants\DeviceSubType::CONSOLE
  182. ]);
  183. }
  184. }
  185. /* Sega */
  186. private function detectSega($ua)
  187. {
  188. /* Sega Saturn */
  189. if (preg_match('/SEGASATURN/u', $ua, $match)) {
  190. $this->data->os->reset();
  191. $this->data->device->setIdentification([
  192. 'manufacturer' => 'Sega',
  193. 'model' => 'Saturn',
  194. 'type' => Constants\DeviceType::GAMING,
  195. 'subtype' => Constants\DeviceSubType::CONSOLE
  196. ]);
  197. }
  198. /* Sega Dreamcast */
  199. if (preg_match('/Dreamcast/u', $ua, $match)) {
  200. $this->data->os->reset();
  201. $this->data->device->setIdentification([
  202. 'manufacturer' => 'Sega',
  203. 'model' => 'Dreamcast',
  204. 'type' => Constants\DeviceType::GAMING,
  205. 'subtype' => Constants\DeviceSubType::CONSOLE
  206. ]);
  207. }
  208. }
  209. }