1212 */
1313class MacDevice
1414{
15+ use ShellTrait;
16+
1517 const CPU_INTEL = 'intel ' ;
1618 const CPU_APPLE = 'apple ' ;
1719
18- use ShellTrait;
19-
2020 /** @var int */
2121 protected $ _cores ;
2222 /** @var bool */
@@ -143,7 +143,7 @@ public function getProcessorSpeed()
143143 */
144144 public function getSerialNumber ()
145145 {
146- return $ this ->getSpHardwareDataType ('serial_number_system ' );
146+ return $ this ->getSpHardwareDataType ('serial_number ' );
147147 }
148148
149149 /**
@@ -247,11 +247,11 @@ public function isSecureBoot()
247247 }
248248
249249 /**
250- * @param string|null $key
250+ * @param string|null $tKey
251251 *
252252 * @return string[]|string
253253 */
254- protected function getSpHardwareDataType ($ key = null )
254+ protected function getSpHardwareDataType ($ tKey = null )
255255 {
256256 if (is_null ($ this ->_SPHardwareDataType ))
257257 {
@@ -261,21 +261,24 @@ protected function getSpHardwareDataType($key = null)
261261 {
262262 foreach ($ matches as $ match )
263263 {
264- $ key = !empty ($ match [1 ]) ? preg_replace ('~(?<= \\w)([A-Z])~u ' , '_$1 ' , $ match [1 ]) : null ;
265- $ val = !empty ($ match [2 ]) ? $ match [2 ] : null ;
266-
267- if ($ key && $ val )
264+ if (!empty ($ match [1 ]) && !empty ($ match [2 ]))
268265 {
269- $ this ->_SPHardwareDataType [$ key ] = $ val ;
266+ $ key = strtolower ($ match [1 ]);
267+ $ key = str_replace (' (system) ' , '' , $ key );
268+ $ key = str_replace (['( ' , ') ' ], '' , $ key );
269+ $ key = str_replace (['number of ' , ' per core ' ], ['' , '_core ' ], $ key );
270+ $ key = str_replace ([' ' , '- ' ], '_ ' , $ key );
271+
272+ $ this ->_SPHardwareDataType [$ key ] = $ match [2 ];
270273 }
271274 }
272275 }
273276 }
274277 }
275278
276- if ($ key )
279+ if ($ tKey )
277280 {
278- return !empty ($ this ->_SPHardwareDataType [$ key ]) ? $ this ->_SPHardwareDataType [$ key ] : null ;
281+ return !empty ($ this ->_SPHardwareDataType [$ tKey ]) ? $ this ->_SPHardwareDataType [$ tKey ] : null ;
279282 }
280283 else
281284 {
0 commit comments