aboutsummaryrefslogtreecommitdiffstats
path: root/gsxlib.php
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2011-05-02 23:51:39 +0300
committerFilipp Lepalaan <filipp@mac.com>2011-05-02 23:51:39 +0300
commit7a1f4b614c1552b34ddb23f2bdac089280175b5a (patch)
treefcba21d39799a87471c8103cddbdd2cf95b259e5 /gsxlib.php
parenteafe4ebe27f366bb4e24d321a5ff157feaa798b2 (diff)
downloadgsxlib-7a1f4b614c1552b34ddb23f2bdac089280175b5a.tar.gz
gsxlib-7a1f4b614c1552b34ddb23f2bdac089280175b5a.tar.bz2
gsxlib-7a1f4b614c1552b34ddb23f2bdac089280175b5a.zip
made looksLike() static to use it without instantiating
Diffstat (limited to 'gsxlib.php')
-rw-r--r--gsxlib.php18
1 files changed, 12 insertions, 6 deletions
diff --git a/gsxlib.php b/gsxlib.php
index 689981a..da5829c 100644
--- a/gsxlib.php
+++ b/gsxlib.php
@@ -85,28 +85,34 @@ class GsxLib
public function partsLookup($string = null)
{
$string = trim($string);
- $what = $this->looksLike($string);
+ $what = self::looksLike($string);
if (!$what) {
exit('Invalid search term for part lookup: ' . $string);
}
- $req = array('PartsLookup' => array('lookupRequestData' => array($what => $string)));
+ $req = array('PartsLookup' => array(
+ 'lookupRequestData' => array($what => $string)
+ ));
+
return $this->request($req)->parts;
}
/**
* Try to "categorise" a string
+ * About identifying serial numbers - before 2010, Apple had a logical
+ * serial number format, with structure, that you could id quite reliably.
+ * unfortunately, it's no longer the case
* @param string $string
*/
- private function looksLike($string, $what = null)
+ static function looksLike($string, $what = null)
{
$result = false;
$rex = array(
- 'partNumber' => '/^\w+\-\w+$/i',
- 'serialNumber' => '/^[a-z0-9]{7,18}$/i',
+ 'partNumber' => '/^[a-z]?\d{3}\-\d{4}$/i',
+ 'serialNumber' => '/^[a-z0-9]{11,12}$/i',
'eeeCode' => '/^[a-z0-9]{3,4}$/i',
'repairNumber' => '/^\d{12}$/',
'repairConfirmationNumber' => '/^G\d{9}$/i'
@@ -129,7 +135,7 @@ class GsxLib
{
$serialNumber = trim($serialNumber);
- if (!$this->looksLike($serialNumber, 'serialNumber')) {
+ if (!self::looksLike($serialNumber, 'serialNumber')) {
exit('Invalid serial number: ' . $serialNumber);
}