Tutorial Extension  1.0.0
SellerDeck Extensions - Tutorial Extension
CValidator.php
1 <?php
2 
3 /**
4  * CValidator.php - Implementation file for DataBase class.
5  *
6  * @package SellerDeck Extensions
7  *
8  * @author Péter Erdődi
9  * @copyright © SellerDeck Ltd 2015. All rights reserved.
10  */
11 
12 namespace SDExtension\Helper;
13 
15  {
16 
17  /**
18  * @var object $m_oCatalogDB Catalog DB
19  */
20  protected $m_oCatalogDB = null;
21 
22  /**
23  * @var object $m_oShippingDB Shipping DB
24  */
25  protected $m_oShippingDB = null;
26 
27  /**
28  * __construct - Object constructor method
29  *
30  * @access public
31  * @param object $oCatalogDB Catalog Database Object
32  * @param object $oShippingDB Shipping Database Object
33  * @return void
34  */
35  public function __construct($oCatalogDB, $oShippingDB)
36  {
37  $this->m_oCatalogDB = $oCatalogDB;
38  $this->m_oShippingDB = $oShippingDB;
39  }
40 
41  /**
42  * ValidateEmail - Validate Email address
43  *
44  * @access public
45  * @throws ValidatorException
46  * @param string $sEmail Email address
47  * @return string Email address
48  */
49  public function ValidateEmail($sEmail)
50  {
51  if ($sEmail == "Invalid Request")
52  {
53  return null;
54  }
55  if (filter_var($sEmail, FILTER_VALIDATE_EMAIL) === false)
56  {
57  \SDExtension\Helper\CLogger::get(LOG_CHANNEL_NAME)->addError("#" . EXCEPTION_MSG_INVALID_EMAIL . ":" . EXCEPTION_CODE_INVALID_EMAIL);
58  throw new \SDExtension\SDException\ValidatorException(EXCEPTION_MSG_INVALID_EMAIL, EXCEPTION_CODE_INVALID_EMAIL);
59  }
60  return $sEmail;
61  }
62 
63  /**
64  * ValidateCurrency - Validate Currency
65  *
66  * @access public
67  * @throws ValidatorException
68  * @param string $sCurrency Currency
69  * @return string Currency
70  */
71  public function ValidateCurrency($sCurrency)
72  {
73  $aResult = $this->m_oCatalogDB->Select('currencies', '*', [['SINTLSYMBOL', $sCurrency]])->fetch(\PDO::FETCH_ASSOC);
74  if (empty($aResult))
75  {
76  throw new \SDExtension\SDException\InvalidCurrencyException($sCurrency);
77  }
78  return $sCurrency;
79  }
80 
81  }
static get($sChannel="default", $sLogRoot="")
Definition: CLogger.php:90
__construct($oCatalogDB, $oShippingDB)
Definition: CValidator.php:35