We will keep some validation constants in the class itself, and the class will use My\Service
as its namespace. Follow these steps to create the ValidatorService
class:
1. Create a new directory named
Service
under your project directory. The Service classes will be inside this directory.2. Create a new PHP file inside the
Service
directory namedValidatorService.php
, and type in the following class:<?php namespace My\Service; use My\Dao\UserDao; class ValidatorService { private $values = array(); private $errors = array(); public $statusMsg = null; public $num_errors; const NAME_LENGTH_MIN = 5; const NAME_LENGTH_MAX = 100; const PASS_LENGTH_MIN = 8; const PASS_LENGTH_MAX = 32; public function __construct() { } public function setUserDao(UserDao $userDao){ $this->userDao = $userDao; } } $validator = new \My\Service\ValidatorService; $validator->setUserDao($userDao); ?>
Note that the class is under the
My\Service
namespace and...