/** * Custom validation by overwriting the validate function. * * @return */ public function validate() { // Format the date fields: month, date and year, into a date string (e.g. 2000-01-31) if (is_string($this->get('date_month')) && is_string($this->get('date_day')) && is_string($this->get('date_year'))) { $combinedDate = implode('-', [$this->get('date_year'), str_pad($this->get('date_month'), 2, '0', STR_PAD_LEFT), str_pad($this->get('date_day'), 2, '0', STR_PAD_LEFT)]); $this->merge(['date_of_birth' => $combinedDate]); } return parent::validate(); }
/** * Custom validation by overwriting the validate function. * * @return */ public function validate() { // Concatenating both address fields into a single string if (is_string($this->get('address')) && is_string($this->get('address_more'))) { if (empty($this->get('address_more'))) { $combinedAddress = $this->get('address'); } else { $combinedAddress = $this->get('address') . ", " . $this->get('address_more'); } $this->merge(['address_full' => $combinedAddress]); } return parent::validate(); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { if (isset($_GET['Request'])) { $request = new Request(); $request->attributes = $_GET['Request']; if ($request->validate()) { $request->action(); //возвращаем массив номеров для отображения+список рег. городов с их номерами echo CJSON::encode(array('regions' => $request->regions, 'phones' => $request->phones)); //echo '<pre>'; print_r(array('regions'=>$request->regions, 'phones'=>$request->phones)); } else { echo '<pre>'; print_r($request->errors); } } else { echo 'Empty Request array'; } }
/** * Custom validation by overwriting the validate function. * * @return */ public function validate() { // Format the date fields: month, date and year, into a date string (e.g. 2000-01-31) if (is_string($this->get('date_month')) && is_string($this->get('date_day')) && is_string($this->get('date_year'))) { $combinedDate = implode('-', [$this->get('date_year'), str_pad($this->get('date_month'), 2, '0', STR_PAD_LEFT), str_pad($this->get('date_day'), 2, '0', STR_PAD_LEFT)]); $this->merge(['date_of_birth' => $combinedDate]); } // Remove leading zeros if any if (is_string($this->get('minutes_volunteered'))) { if (ltrim($this->get('minutes_volunteered'), '0') != '') { $minutes = ltrim($this->get('minutes_volunteered'), '0'); } else { $minutes = '0'; } $this->merge(['minutes_volunteered' => $minutes]); } return parent::validate(); }
/** * Custom validation by overwriting the validate function. * * @return */ public function validate() { // Format the date fields: month, date and year, into a date string (e.g. 2000-01-31) if (is_string($this->get('date_month')) && is_string($this->get('date_day')) && is_string($this->get('date_year'))) { $combinedDate = implode('-', [$this->get('date_year'), str_pad($this->get('date_month'), 2, '0', STR_PAD_LEFT), str_pad($this->get('date_day'), 2, '0', STR_PAD_LEFT)]); $this->merge(['date' => $combinedDate]); } // Format the time fields: hour, minute and period, into a time string (e.g. 08:05 am) if (is_string($this->get('time_hour')) && is_string($this->get('time_minute')) && is_string($this->get('time_period'))) { $combinedTime = str_pad($this->get('time_hour'), 2, '0', STR_PAD_LEFT) . ":" . str_pad($this->get('time_minute'), 2, '0', STR_PAD_LEFT) . " " . $this->get('time_period'); $this->merge(['time' => $combinedTime]); } // Convert the activity duration into minutes if (is_integer((int) $this->get('duration_hour')) && is_integer((int) $this->get('duration_minute'))) { $combinedDuration = (int) $this->get('duration_hour') * 60 + (int) $this->get('duration_minute'); $this->merge(['duration' => $combinedDuration]); } return parent::validate(); }
/** * Run Application * * @return void */ public static function run() { // Get application object $app = self::get_instance(); // Default configurations $app->config['app_domain'] = App::remove_last_slash('http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME'])); $app->config['stylesheets_path'] = $app->config['app_domain'] . '/public/stylesheets/'; $app->config['javascripts_path'] = $app->config['app_domain'] . '/public/javascripts/'; $app->config['images_path'] = $app->config['app_domain'] . '/public/images/'; $route = array(); $route['404'] = array('RequestError::error_404'); $route['401'] = array('RequestError::error_401'); include APP_PATH . '/config/routes.php'; include APP_PATH . '/config/application.php'; include APP_PATH . '/config/enviroments/' . $app->config['env'] . '.php'; // Set most used configurations, for rapid access. define('APP_DOMAIN', $app->config['app_domain']); define('STYLESHEETS_PATH', $app->config['stylesheets_path']); define('JAVASCRIPTS_PATH', $app->config['javascripts_path']); define('IMAGES_PATH', $app->config['images_path']); define('PLUGINS_PATH', APP_PATH . '/vendor/plugins'); define('LANGUAGE', $app->config['language']); define('JS_FRAMEWORK', $app->config['js_framework']); // Load application plugins foreach ($app->plugins as $plugin) { require_once APP_PATH . '/vendor/plugins/' . $plugin . '/init.php'; } // Fire on_init event $app->fire_event('on_init'); // Required files for Drumon include CORE_PATH . '/class/request.php'; include CORE_PATH . '/class/response.php'; include CORE_PATH . '/class/helper.php'; include CORE_PATH . '/class/view.php'; include CORE_PATH . '/class/controller.php'; include APP_PATH . '/app/controllers/app_controller.php'; // Token protection against CSFR define('REQUEST_TOKEN', $app->create_request_token()); // Initialize request $request = new Request($route, APP_PATH); $request->validate(); // Proccess controller and action $app->proccess_controller($request); }
/** * Before validating, form the date and time entries from the sub-entries. */ public function validate() { $this->createDateEntry('date'); $this->createTimeEntry('time'); return parent::validate(); }
public function beforeAction($action) { if ($this->isActionAttachedByActionsMethod($action) || $this->isSpecialAction($action)) { return parent::beforeAction($action); } try { $requestModel = $this->createApiValidation($this->getId(), $action->id); $postParamsKey = self::$configuration['requestKey']; if (empty($this->request)) { $this->request = isset($_POST[$postParamsKey]) ? $_POST[$postParamsKey] : file_get_contents('php://input'); } Request::setModel($requestModel); Request::setRawRequest($this->request); if (Request::validate()) { return parent::beforeAction($action); } else { Response::error(ErrorCodes::VALIDATION_ERROR, Request::model()->getErrors()); $this->afterAction($action); } } catch (Exception $e) { if ($e instanceof CHttpException) { throw $e; } $trace = YII_DEBUG ? ' Trace: ' . $e->getTraceAsString() : ''; Response::error(ErrorCodes::SERVER_ERROR, $e->getMessage() . $trace); $this->renderAndLogResponse(); } }