diff --git a/api-payroll/.htaccess b/api-payroll/.htaccess index 5a928f6..42322c0 100644 --- a/api-payroll/.htaccess +++ b/api-payroll/.htaccess @@ -1 +1,2 @@ Options -Indexes +Deny from all diff --git a/api-payroll/Dockerfile b/api-payroll/Dockerfile index d4fdc8f..a0733af 100644 --- a/api-payroll/Dockerfile +++ b/api-payroll/Dockerfile @@ -1,10 +1,29 @@ +# Stage 1 - the build process +FROM composer:1.7.1 as build-deps +ENV COMPOSER_ALLOW_SUPERUSER 1 + +WORKDIR /root + +COPY . . +RUN composer install +RUN composer test + +# Stage 2 - the production environment FROM ubuntu:16.04 -# Updating RUN apt-get -y update && apt-get -y upgrade -# Installing php, apache and supplementary software -RUN apt-get -y install apache2 php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zip curl git unzip composer +RUN apt-get -y install apache2 \ +php7.0 \ +libapache2-mod-php7.0 \ +php7.0-cli \ +php7.0-common \ +php7.0-mbstring \ +php7.0-gd \ +php7.0-intl \ +php7.0-xml \ +php7.0-mysql \ +php7.0-mcrypt # Enable apache mods RUN a2enmod php7.0 @@ -20,24 +39,14 @@ ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 ENV APACHE_LOCK_DIR /var/lock/apache2 -# Expose apache -EXPOSE 80 - -# Copy this repo into place. -ADD . /var/www/site WORKDIR /var/www/site +COPY --from=build-deps /root . -# Testing permisions -RUN chmod 777 -R . +RUN touch logs/app.log +RUN chmod 777 logs/app.log -# Installing dependencies -RUN composer install +# Update the default apache site +ADD docker/apache-config.conf /etc/apache2/sites-enabled/000-default.conf -# Unit tests -RUN composer test - -# Update the default apache site with the config we created. -ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf - -# By default start up apache in the foreground, override with /bin/bash for interative +# By default start up apache in the foreground CMD /usr/sbin/apache2ctl -D FOREGROUND diff --git a/api-payroll/apache-config.conf b/api-payroll/docker/apache-config.conf similarity index 100% rename from api-payroll/apache-config.conf rename to api-payroll/docker/apache-config.conf diff --git a/api-payroll/logs/app.log b/api-payroll/logs/app.log new file mode 100755 index 0000000..e69de29 diff --git a/api-payroll/public/.htaccess b/api-payroll/public/.htaccess index f5d1969..9b6908a 100644 --- a/api-payroll/public/.htaccess +++ b/api-payroll/public/.htaccess @@ -1,3 +1,5 @@ +allow from all + RewriteEngine On diff --git a/api-payroll/public/css/panel.css b/api-payroll/public/css/panel.css deleted file mode 100644 index 365cfee..0000000 --- a/api-payroll/public/css/panel.css +++ /dev/null @@ -1,258 +0,0 @@ -body { - background-color: #e3e3e3; - /* Se agrego color blanco a letra en panel en general*/ - color: #000; -} - -/*Cambia el color del date picker a negro para permitir su visibilidad*/ -.datepicker{ - color: black; -} - -/*El color con el que se muestra el peso del archivo en la carga masiva se imagenes*/ -.size{ - color: black; -} - -.calendar{ - background: #fff; -} - -#cuerpo{ - top:17%; - left:1%; - width:98%; - float:left; -} - -#navigation_spot{ - margin: 0; - padding: 0; -} - -#footer { - -} - -#cuerpo .modal-body{ - color: #000; - border:none; -} - -#cuerpo .panel-default{ - border: 3px solid #4A89A5; - border-radius: 5px; -} - -#cuerpo .panel > .panel-heading { - background-image: none; - background-color: #4A89A5; - color: white; - border-radius: 0; -} - -#cuerpo .btn-default{ - border: 2px solid #62655F; - background: #F9DFAF; -} - -#cuerpo .btn-default:hover{ - border: 2px solid #62655F; - background: #F9DFAF; -} - -#cuerpo .alert-success{ - background: #C6E97C; -} - -#modal_header_error{ - background-color: #d9534f; -} - -#modal_header_respuesa_servidor_error{ - background-color: #d9534f; -} - -#modal_header_respuesa_servidor_success{ - background-color: #5bc0de; -} - - -/* botoner�a panel principal */ -.metro{ - width:auto; - height:auto; -} -.metroBox{ - margin: 0 auto; - width:100%; - padding: 0; - height:auto; - display:table; - overflow: hidden; -} -.metroBox h3{ - margin-bottom: 0; - padding-bottom: 0; -} -.metroBox a{ - text-decoration: none; - color: #fff; -} -.boxElement{ - color: #fff; - height:210px; - width: 318px; - float:left; - margin:0 5px 5px 0; - padding:0 1% 0 1%; -} -.boxElement:hover{ - color: #fff; - background: #483D8B; - text-decoration: none; -} -.amarelo{ - background:#f4c20d; -} -.vermelho{ - background:#da542d; -} -.azul{ - background:#009bad; -} -.azulFuerte{ - background:#5636b0; -} -.verde{ - background-color: #009f00; -} -.violet{ - background-color: #a400ab; -} -.iconPanel{ - font-size: 130px; -} -@media (max-width: 310px){ - .boxElement{ - width: 245px; - } -} -@media (min-width: 311px) and (max-width: 353px){ - .boxElement{ - width: 265px; - } -} -@media (min-width: 354px) and (max-width: 365px){ - .boxElement{ - width: 320px; - } -} -@media (min-width: 366px) and (max-width: 520px){ - .boxElement{ - width: 320px; - } -} -@media (min-width: 521px) and (max-width: 549px){ - .boxElement{ - width: 235px; - } -} -@media (min-width: 550px) and (max-width: 590px){ - .boxElement{ - width: 250px; - } -} -@media (min-width: 591px) and (max-width: 610px){ - .boxElement{ - width: 265px; - } -} -@media (min-width: 611px) and (max-width: 630px){ - .boxElement{ - width: 275px; - } -} -@media (min-width: 631px) and (max-width: 655px){ - .boxElement{ - width: 280px; - } -} -@media (min-width: 656px) and (max-width: 699px){ - .boxElement{ - width: 300px; - } -} -@media (min-width: 700px) and (max-width: 739px){ - .boxElement{ - width: 320px; - } -} -@media (min-width: 740px) and (max-width: 769px){ - .boxElement{ - width: 340px; - } -} -@media (min-width: 770px) and (max-width: 1230px){ - .boxElement{ - width: 280px; - } -} - -/* FORMATO PARA TEXTO CUSTOM */ -.formato_texto_custom{ - width: 97%; - float: left; - border: 1px solid #222; - padding: 1%; - margin: .5%; -} - -.cliente_muestra_producto{ - width: 96%; - padding: 1%; - margin: 0 1% 2% 1%; -} - -textarea{ - resize: none; -} - -#custom-bootstrap-menu.navbar-default .navbar-brand { - color: rgba(255, 255, 255, 1); -} -#custom-bootstrap-menu.navbar-default { - font-size: 14px; - background-color: rgba(27, 35, 78, 1); - border-width: 1px; - border-radius: 4px; -} -#custom-bootstrap-menu.navbar-default .navbar-nav>li>a { - color: rgba(255, 255, 255, 1); - background-color: rgba(27, 35, 78, 1); -} -#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:hover, -#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:focus { - color: rgba(106, 171, 232, 1); - background-color: rgba(27, 35, 78, 1); -} -#custom-bootstrap-menu.navbar-default .navbar-nav>.active>a, -#custom-bootstrap-menu.navbar-default .navbar-nav>.active>a:hover, -#custom-bootstrap-menu.navbar-default .navbar-nav>.active>a:focus { - color: rgba(255, 255, 255, 1); - background-color: rgba(27, 35, 78, 1); -} -#custom-bootstrap-menu.navbar-default .navbar-toggle { - border-color: #1b234e; -} -#custom-bootstrap-menu.navbar-default .navbar-toggle:hover, -#custom-bootstrap-menu.navbar-default .navbar-toggle:focus { - background-color: #1b234e; -} -#custom-bootstrap-menu.navbar-default .navbar-toggle .icon-bar { - background-color: #1b234e; -} -#custom-bootstrap-menu.navbar-default .navbar-toggle:hover .icon-bar, -#custom-bootstrap-menu.navbar-default .navbar-toggle:focus .icon-bar { - background-color: #1b234e; -} \ No newline at end of file diff --git a/api-payroll/public/fonts/glyphicons-halflings-regular.ttf b/api-payroll/public/fonts/glyphicons-halflings-regular.ttf deleted file mode 100644 index 1413fc6..0000000 Binary files a/api-payroll/public/fonts/glyphicons-halflings-regular.ttf and /dev/null differ diff --git a/api-payroll/public/fonts/glyphicons-halflings-regular.woff b/api-payroll/public/fonts/glyphicons-halflings-regular.woff deleted file mode 100644 index 9e61285..0000000 Binary files a/api-payroll/public/fonts/glyphicons-halflings-regular.woff and /dev/null differ diff --git a/api-payroll/public/fonts/glyphicons-halflings-regular.woff2 b/api-payroll/public/fonts/glyphicons-halflings-regular.woff2 deleted file mode 100644 index 64539b5..0000000 Binary files a/api-payroll/public/fonts/glyphicons-halflings-regular.woff2 and /dev/null differ diff --git a/api-payroll/public/html/landing.php b/api-payroll/public/html/landing.php deleted file mode 100644 index 1cdf05a..0000000 --- a/api-payroll/public/html/landing.php +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/api-payroll/public/js/login.js b/api-payroll/public/js/login.js index bfc30e3..707ec99 100644 --- a/api-payroll/public/js/login.js +++ b/api-payroll/public/js/login.js @@ -4,22 +4,21 @@ function getbaseUrl(uriPath){ } function processLogin() { - var baseUrl = getbaseUrl('/html/'); - +console.log(getbaseUrl('html/')); var parametros = { "userName":$('#userName').val(), "password":$('#password').val() }; $.ajax({ - url: baseUrl + '/index.php/api/session/login', + url: getbaseUrl('/html/') + '/index.php/api/session/login', type: 'POST', dataType: 'json', data: parametros, success:function(data){ console.log(JSON.stringify(data)); if(data["status"] == "success"){ - redirect(baseUrl + '/html/landing.php'); + redirect("http://stackoverflow.com"); }else if(data["status"] == "success" || (data["status"] === undefined)){ $('#modalLoginError').modal('show'); document.getElementById('modalLoginErrorBody').innerHTML = "The server didn't respond in time, please try again or refresh this page."; diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index d17e9e1..c2ceebc 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -56,11 +56,11 @@ class EmployeeApplication{ * @return integer */ function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){ - $this->asserts->isNotEmpty($firstName, "The first name can't be empty."); - $this->asserts->isNotEmpty($middleName, "The middle name can't be empty."); - $this->asserts->isNotEmpty($birthDate, "The birth date can't be empty."); - $this->asserts->isNotEmpty($email, "The email can't be empty."); - $this->asserts->isNotEmpty($phone, "The phone number can't be empty."); + $this->asserts->firstName($firstName); + $this->asserts->middleName($middleName); + $this->asserts->birthDate($birthDate); + $this->asserts->email($email); + $this->asserts->phone($phone); try { $stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone) @@ -89,10 +89,6 @@ class EmployeeApplication{ * @return mixed */ function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){ - $this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0"); - $this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0"); - $this->asserts->isNotEmpty($code, "The code can't be empty."); - $this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); try { $stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType) VALUES (:idEmployeeType, :idPerson, :code, :contractType)"); @@ -119,29 +115,21 @@ class EmployeeApplication{ function saveNewEmployee($requestData){ // Getting and validating the data $firstName = $requestData['firstName']; - $this->asserts->isNotEmpty($firstName, "The first name can't be empty."); - $this->asserts->isString($firstName, "The first name must be a string."); - $this->asserts->betweenLength($firstName, 1, 50, "The first name must have a length between 1 and 50 characters."); + $this->asserts->firstName($firstName); $middleName = $requestData['middleName']; - $this->asserts->isNotEmpty($middleName, "The middle name can't be empty."); - $this->asserts->isString($middleName, "The middle name must be a string."); - $this->asserts->betweenLength($middleName, 1, 50, "The middle name must have a length between 1 and 50 characters."); + $this->asserts->middleName($middleName); - $lastName = isset($requestData['lastName']) - ? $requestData['lastName'] - : null; + $lastName = isset($requestData['lastName']) ? $requestData['lastName'] : null; $birthDate = $requestData['birthDate']; - $this->asserts->isNotEmpty($birthDate, "The birth date can't be empty."); + $this->asserts->birthDate($birthDate); $email = $requestData['email']; - $this->asserts->isNotEmpty($email, "The email can't be empty."); - $this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters."); + $this->asserts->email($email); $phone = $requestData['phone']; - $this->asserts->isNotEmpty($phone, "The phone number can't be empty."); - $this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters."); + $this->asserts->phone($phone); $idEmployeeType = $requestData{'idEmployeeType'}; $contractType = $requestData{'contractType'}; @@ -181,8 +169,6 @@ class EmployeeApplication{ * @return Integer */ function getIdPersonByIdEmployee($idEmployee){ - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - $stmt = $this->pdo->prepare("SELECT COALESCE((SELECT idPerson @@ -203,12 +189,10 @@ class EmployeeApplication{ } /** - * @param $code string - * @return integer + * @param $code + * @return mixed */ function getIdEmployeeTypeByCode($code){ - $this->asserts->isNotEmpty($code, "The code can't be empty."); - $stmt = $this->pdo->prepare("SELECT COALESCE((SELECT et.id FROM @@ -235,8 +219,6 @@ class EmployeeApplication{ * @return array */ function getEmployeeDataById($idEmployee){ - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - $stmt = $this->pdo->prepare("SELECT p.id AS idPerson, p.firstName, @@ -271,8 +253,6 @@ class EmployeeApplication{ * @return array */ function proxyGetEmployeeDataById($idEmployee){ - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - $employeeData = $this->getEmployeeDataById($idEmployee); $response = array( @@ -299,8 +279,6 @@ class EmployeeApplication{ * @return array */ function getEmployeeDataByCode($code){ - $this->asserts->isNotEmpty($code, "The code can't be empty."); - $idEmployee = $this->getIdEmployeeTypeByCode($code); return $this->proxyGetEmployeeDataById($idEmployee); @@ -316,13 +294,6 @@ class EmployeeApplication{ * @param $phone string */ function updatePerson($idPerson, $firstName, $middleName, $lastName, $birthDate, $email, $phone){ - $this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0"); - $this->asserts->isNotEmpty($firstName, "The first name can't be empty."); - $this->asserts->isNotEmpty($middleName, "The middle name can't be empty."); - $this->asserts->isNotEmpty($birthDate, "The birth date can't be empty."); - $this->asserts->isNotEmpty($email, "The email can't be empty."); - $this->asserts->isNotEmpty($phone, "The phone number can't be empty."); - try { $stmt = $this->pdo->prepare("UPDATE persons SET @@ -352,11 +323,6 @@ class EmployeeApplication{ * @param $contractType string */ function updateEmployee($idEmployee, $code, $idEmployeeType, $contractType){ - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - $this->asserts->isNotEmpty($code, "The code can't be empty."); - $this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0"); - $this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); - try { $stmt = $this->pdo->prepare("UPDATE employees SET @@ -383,42 +349,28 @@ class EmployeeApplication{ function updateEmployeeData($requestData){ // Getting and validating the data $idEmployee = $requestData['idEmployee']; - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - $idPerson = $this->getIdPersonByIdEmployee($idEmployee); - $this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0"); - $code = $requestData['code']; - $this->asserts->isNotEmpty($code, "The code can't be empty."); $firstName = $requestData['firstName']; - $this->asserts->isNotEmpty($firstName, "The first name can't be empty."); - $this->asserts->isString($firstName, "The first name must be a string."); - $this->asserts->betweenLength($firstName, 1, 50, "The first name must have a length between 1 and 50 characters."); + $this->asserts->firstName($firstName); $middleName = $requestData['middleName']; - $this->asserts->isNotEmpty($middleName, "The middle name can't be empty."); - $this->asserts->isString($middleName, "The middle name must be a string."); - $this->asserts->betweenLength($middleName, 1, 50, "The middle name must have a length between 1 and 50 characters."); + $this->asserts->middleName($middleName); $lastName = isset($requestData['lastName']) ? $requestData['lastName'] : null; $birthDate = $requestData['birthDate']; - $this->asserts->isNotEmpty($birthDate, "The birth date can't be empty."); + $this->asserts->birthDate($birthDate); $email = $requestData['email']; - $this->asserts->isNotEmpty($email, "The email can't be empty."); - $this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters."); + $this->asserts->email($email); $phone = $requestData['phone']; - $this->asserts->isNotEmpty($phone, "The phone number can't be empty."); - $this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters."); + $this->asserts->phone($phone); $idEmployeeType = $requestData{'idEmployeeType'}; - $this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0"); - $contractType = $requestData{'contractType'}; - $this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); // Encrypting the sensitive data $securedFirstName = $this->cryptographyService->encryptString($firstName); @@ -452,8 +404,6 @@ class EmployeeApplication{ } function disableEmployeeRecord($idEmployee){ - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - try { $stmt = $this->pdo->prepare("UPDATE employees SET @@ -497,9 +447,6 @@ class EmployeeApplication{ return $results; } - /** - * @return array - */ function listAllActiveEmployees(){ $ids = $this->getIdEmployeeFromAllActiveEmployees(); diff --git a/api-payroll/src/application/SessionApplication.php b/api-payroll/src/application/SessionApplication.php index 43855e2..62ff2fd 100644 --- a/api-payroll/src/application/SessionApplication.php +++ b/api-payroll/src/application/SessionApplication.php @@ -41,18 +41,15 @@ class SessionApplication{ /** * @param $userName string * @return mixed - * @throws Exception */ function getPassword($userName){ - $this->asserts->isNotEmpty($userName, "The username can't be empty"); - $this->asserts->isString($userName, "The username must be a string."); - $this->asserts->betweenLength($userName, 1, 50, "The username must have a length between 1 and 50 characters."); + $this->asserts->userName($userName); $stmt = $this->pdo->prepare("SELECT password FROM users WHERE name = :userName"); $stmt->execute(array(':userName' => $userName)); $results = $stmt->fetchAll(); if(!$results){ - throw new Exception('The user or password didnt match, please try again.'); + exit($this->databaseSelectQueryErrorMessage); } $stmt = null; return $results[0]['password']; @@ -65,12 +62,8 @@ class SessionApplication{ * @throws Exception */ function newSession($userName, $password){ - $this->asserts->isNotEmpty($userName, "The username can't be empty"); - $this->asserts->isString($userName, "The username must be a string."); - $this->asserts->betweenLength($userName, 1, 50, "The username must have a length between 1 and 50 characters."); - $this->asserts->isNotEmpty($password, "The password can't be empty"); - $this->asserts->isString($password, "The password must be a string."); - $this->asserts->betweenLength($password, 1, 50, "The password must have a length between 1 and 50 characters."); + $this->asserts->userName($userName); + $this->asserts->password($password); $storedPassword = $this->getPassword($userName); @@ -100,14 +93,6 @@ class SessionApplication{ * @throws Exception */ function login($userName, $password){ - $this->asserts->isNotEmpty($userName, "The username can't be empty"); - $this->asserts->isString($userName, "The username must be a string."); - $this->asserts->betweenLength($userName, 1, 50, "The username must have a length between 1 and 50 characters."); - $this->asserts->isNotEmpty($password, "The password can't be empty"); - $this->asserts->isString($password, "The password must be a string."); - $this->asserts->betweenLength($password, 1, 50, "The password must have a length between 1 and 50 characters."); - - if($this->newSession($userName, $password)){ return array('status' => 'success', 'message' => 'Logged in successfully.'); } diff --git a/api-payroll/src/service/Asserts.php b/api-payroll/src/service/Asserts.php index 9e1f1d3..94b3023 100644 --- a/api-payroll/src/service/Asserts.php +++ b/api-payroll/src/service/Asserts.php @@ -6,54 +6,78 @@ use Respect\Validation\Validator as v; class Asserts{ /** - * @param $string string - * @param $errorMessage string + * @param $string * @throws Exception */ - function isString($string, $errorMessage){ - $validation = v::stringType()->validate($string); + function userName($string){ + $validateFirstName = v::stringType()->notEmpty()->length(1, 50)->validate($string); - if(!$validation){ - throw new Exception($errorMessage); + if(!$validateFirstName){ + throw new Exception('The user name must be a string between 1 and 50 characters'); } } /** - * @param $string string - * @param $errorMessage string + * @param $string * @throws Exception */ - function isNotEmpty($string, $errorMessage){ - $validation = v::notEmpty()->validate($string); + function password($string){ + $validateFirstName = v::stringType()->notEmpty()->length(1, 50)->validate($string); - if(!$validation){ - throw new Exception($errorMessage); + if(!$validateFirstName){ + throw new Exception('The password must be a string between 1 and 50 characters'); } } /** - * @param $string string - * @param $min integer - * @param $max integer - * @param $errorMessage string + * @param $string * @throws Exception */ - function betweenLength($string, $min, $max, $errorMessage){ - $validation = v::length($min, $max)->validate($string); + function firstName($string){ + $validateFirstName = v::stringType()->notEmpty()->length(1, 100)->validate($string); - if(!$validation){ - throw new Exception($errorMessage); + if(!$validateFirstName){ + throw new Exception('The first name must be a string between 1 and 100 characters'); } } /** - * @param $number integer - * @param $errorMessage string + * @param $string * @throws Exception */ - function higherThanZero($number, $errorMessage){ - if($number <= 0){ - throw new Exception($errorMessage); + function middleName($string){ + if(!v::stringType()->notEmpty()->length(1, 100)->validate($string)){ + throw new Exception('The middle name must be a string between 1 and 100 characters'); + } + } + + /** + * @param $string + * @throws Exception + */ + function birthDate($string){ + if(!v::date('Y-m-d')->notEmpty()->validate($string)){ + throw new Exception('The birth date must be in the yyyy-mm-dd format'); + } + } + + /** + * @param $string + * @throws Exception + */ + function email($string){ + if(!v::stringType()->notEmpty()->length(1, 100)->validate($string)){ + throw new Exception('The email must be a string between 1 and 100 characters'); + } + } + + /** + * @param $string + * @throws Exception + */ + function phone($string){ + if(!v::digit()->notEmpty()->length(10, 10)->validate($string)){ + throw new Exception('The phone must be a numeric value of 10 digits'); } } } diff --git a/docker-compose.yml b/docker-compose.yml index eb9029a..aa5a8d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: ports: - "8085:80" volumes: - - api-payroll:/var/www/site + - ./volumes/apache-logs:/var/log/apache2 depends_on: - mysql mysql: @@ -18,11 +18,11 @@ services: ports: - "3307:3307" volumes: - - my-datavolume:/var/lib/mysql + - ./volumes/mysql-data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: '12345678' MYSQL_USER: 'sloth' MYSQL_PASS: '12345678' volumes: - api-payroll: - my-datavolume: + mysql-data: + apache-logs: diff --git a/volumes/.gitignore b/volumes/.gitignore new file mode 100644 index 0000000..9e750a3 --- /dev/null +++ b/volumes/.gitignore @@ -0,0 +1,2 @@ +mysql-data/ +apache-logs/ diff --git a/volumes/README.md b/volumes/README.md new file mode 100644 index 0000000..3c5b13b --- /dev/null +++ b/volumes/README.md @@ -0,0 +1 @@ +# Do not delete this directory, it'll contain the volumes created by the containers