/var/www/vhosts/nabawater/api/components
NameSizeModeActions
ApiException.php5690644editdlrm
CApplication.php5560644editdlrm
CController.php90390644editdlrm
CHttpBearerAuth.php8500644editdlrm
CModule.php3770644editdlrm
CResponse.php70420644editdlrm
CSerializer.php5150644editdlrm
CUrlRule.php3750644editdlrm
Vendor.php1340644editdlrm
Edit: /var/www/vhosts/nabawater/api/components/CController.php (9039B)
*/ class CController extends Controller { /** * @var array */ public $serializer = ['class' => CSerializer::class]; /** * @var string */ private $language; /** * @var string */ private $message; /** * @var array */ private $errors; /** * @var Boolean */ private $isObject = false; /** * @return array */ public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = [ 'class' => CHttpBearerAuth::class, 'optional' => [ 'user/login', 'user/register', 'user/social-register', 'user/verify_otp', 'user/resend_otp', 'user/forgot-password', 'user/change-promotion-status', 'user/update', 'user/change-password', 'user/add-favourite', 'user/remove-favourite', 'user/friend-and-family', 'user/create-post', 'user/settings', 'user/otp-login', 'mobile-translation/*', 'user/settings', 'home/*', 'ads/*', 'customer-address/address-type', 'branch/index', 'branch/view', 'branch/info', 'branch/get-vendor-type', 'branch/get-filter-details', 'branch/delivery-date', 'branch/delivery-time-slot', 'branch/get-currency-code', 'order/get-delivery-time', 'order/calculate-data', 'order/place-order', 'order/deliveryboy', 'order/details-new', 'order/subscrption-week', 'order/driver-reschedule', 'order/driver-delivered', 'delivery-boy/*', 'vendor/*', 'site/index', 'rating/index', 'newsletter/create', 'newsletter/delete', 'contactus/create', 'contactus/contact_details', 'cuisine/index', 'customer-address/list', 'enquiry/create', 'wallet/transfer-amount', 'order/hyperpay-webhook' ] ]; return $behaviors; } /** * CController constructor. * @param string $id * @param \yii\base\Module $module * @param array $config */ public function __construct($id, $module, array $config = array()) { parent::__construct($id, $module, $config); $this->setTimeZone(); } /** * @param \yii\base\Action $action * @return bool * @throws \yii\web\BadRequestHttpException */ public function beforeAction($action) { $header = Yii::$app->getRequest()->getHeaders(); $language = Configuration::DEFAULT_LANG_CODE; if ($header->has('Accept-Language')) { $language = trim($header->get('Accept-Language')); if ($language === '') { $language = Configuration::DEFAULT_LANG_CODE; } } $this->setLanguage(strtolower(substr($language, 0, 2))); return parent::beforeAction($action); } /** * */ public function setTimeZone() { if (($timeZone = Configuration::get(Configuration::TIME_ZONE)) !== null) { Yii::$app->timeZone = $timeZone; } } /** * @param string $language */ private function setLanguage($language = 'en') { $this->language = $language; Yii::$app->language = $language; } /** * @return string */ public function getLanguage() { return $this->language; } /** * @param Boolean $isObject */ public function setIsObject($isObject = false) { $this->isObject = $isObject; } /** * @return Boolean */ public function getIsObject() { return $this->isObject; } /** * @param $message * @param null|string $category * @param array $params */ public function setMessage($message, $category = null, array $params = []) { if ($category === null) { $category = 'api'; } $this->message = Yii::t($category, $message, $params); } /** * @return string */ public function getMessage() { return $this->message === null ? Yii::t('api', 'DEFAULT_MESSAGE') : $this->message; } /** * @param array $errors */ public function setErrors(array $errors) { $this->errors = $errors; } /** * @return array */ public function getErrors() { return $this->errors; } /** * @param array $request * @param $params * @throws \api\components\ApiException */ protected function checkRequiredParam(array $request, $params) { $params = (array) $params; foreach ($params as $param) { if (!array_key_exists($param, $request)) { $this->setErrors(['missing-param' => $param]); $this->paramMissing(); } } } /** * @param null $param * @throws ApiException */ protected function paramMissing($param = null) { if ($param !== null) { $this->setErrors(['missing-param' => $param]); } throw new ApiException(Yii::t('api', 'Required param missing'), 460); } /** * * @throws ApiException */ protected function invalidLogin() { throw new ApiException(Yii::t('api', 'Invalid OTP supplied'), 400); } /** * @throws \yii\web\UnauthorizedHttpException */ protected function unauthorizedAccess() { throw new UnauthorizedHttpException(Yii::t('api', 'Your request was made with invalid credentials')); } /** * @throws ApiException */ protected function emailNotFound() { throw new ApiException(Yii::t('api', 'Email not found'), 404); } /** * @param string|null $error * @param null|string $category * @param array $params * @throws ApiException */ public function commonError($error = null, $category = null, array $params = []) { if ($error === null) { $error = 'EXPECTATION_FAILED'; } if ($category === null) { $category = 'api'; } throw new ApiException(Yii::t($category, $error, (array) $params), 417); } /** * @throws ApiException */ public function userNotFound() { $this->commonError('UNABLE_TO_FIND_THE_REQUESTED_USER'); } /** * @param $data * @param array $fields * @return array */ public function serializeModel($data, array $fields = []) { if ($data instanceof Arrayable) { return $data->toArray($fields); } return $data; } /** * @param array $models * @param array $fields * @return array */ public function serializeModels(array $models, array $fields = []) { foreach ($models as $i => $model) { if ($model instanceof Arrayable) { $models[$i] = $model->toArray($fields); } elseif (is_array($model)) { $models[$i] = ArrayHelper::toArray($model); } } return $models; } /** * @param array $point * @param array $polygon * @return integer */ public function DeliveryAreaCheck($point, $polygon) { if ($polygon[0] != $polygon[count($polygon) - 1]) { $polygon[count($polygon)] = $polygon[0]; } $j = 0; $oddNodes = false; $x = $point[1]; $y = $point[0]; $n = count($polygon); for ($i = 0; $i < $n; $i++) { $j++; if ($j == $n) { $j = 0; } if ( (($polygon[$i][0] < $y) && ($polygon[$j][0] >= $y)) || (($polygon[$j][0] < $y) && ($polygon[$i][0] >= $y)) ) { if ( $polygon[$i][1] + ($y - $polygon[$i][0]) / ($polygon[$j][0] - $polygon[$i][0]) * ($polygon[$j][1] - $polygon[$i][1]) < $x ) { $oddNodes = !$oddNodes; } } } return $oddNodes ? 1 : 0; } }