Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Natacha clase3 #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions Natacha/Clase14/ejemploCrud/php/model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,17 @@ public function setSexo($sexo)
{
$this->sexo = $sexo;
}
public function validate()
{
if ($this->sexo !== 'F' && $this->sexo !== 'M' && $this->sexo !== 'N') {
throw new \Exception ('Sexo tiene que valer F M o N');
}
if ($this->email === '') {
throw new \Exception ('El email es obligatorio');
}
if ($this->name === '') {
throw new \Exception ('Nombre vacio');
}
return true;
}
}
3 changes: 3 additions & 0 deletions Natacha/Clase14/ejemploCrud/php/normalizer/UserNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static function createFromRow($row)
$newUser->setName($row['name']);
$newUser->setEmail($row['email']);
$newUser->setSexo($row['sexo']);
$newPet->validate();
$newUser->validate();

return $newUser;
}
Expand All @@ -22,6 +24,7 @@ public static function createFromVariables($id, $name, $email, $sexo)
$newUser->setName($name);
$newUser->setEmail($email);
$newUser->setSexo($sexo);
$newUser->validate();

return $newUser;
}
Expand Down
10 changes: 10 additions & 0 deletions Natacha/Clase15/ejemploCookies/cookie.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?php
session_start();
if(!empty($_SESSION['usuario'])){
/* La funcion empty() devuelve verdadero si el argumento posee un valor vacio,
al usar !empty() devuelve verdadero no solo si la variable fue declarada sino
ademas si contiene algun valor no nulo.
*/
echo 'Te haz logueado como: '.$_SESSION['usuario'].'<br />';
echo 'Haz logrado el acceso a una pagina segura';
}
if(isset($_COOKIE['contador']))
{
// Caduca en un año
setcookie('contador', $_COOKIE['contador'] + 1, time() + 365 * 24 * 60 * 60);
$mensaje = 'Número de visitas: ' . $_COOKIE['contador'];
// suma 1 al contador de cookies
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions Natacha/Clase15/ejemploCookies/logedpage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php
session_start();
$referer = ($_SERVER['HTTP_REFERER'])??'SIN REFERER';
$_SESSION['referer_list'][] = $referer;
print_r( $_SESSION['referer_list']);

if(!empty($_SESSION['usuario'])){
/* La funcion empty() devuelve verdadero si el argumento posee un valor vacio,
al usar !empty() devuelve verdadero no solo si la variable fue declarada sino
Expand All @@ -10,6 +14,7 @@
}else{
echo 'No estas logueado<br />';
echo 'Esta pagina es restringida!';

}
?>
<a href="login.php">BACK TO LOGIN</a>
Expand Down
5 changes: 4 additions & 1 deletion Natacha/Clase15/ejemploCookies/login.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

<?php
session_start();
$referer = ($_SERVER['HTTP_REFERER'])??'SIN REFERER';
$_SESSION['referer_list'][] = $referer;
print_r( $_SESSION['referer_list']);
// inicia sesion
?>
<html>
<head>
Expand Down
3 changes: 2 additions & 1 deletion Natacha/Clase15/ejemploCrud/docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ RUN docker-php-ext-install mysqli

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
apt-get install -y git && \
apt-get install -y curl
3 changes: 3 additions & 0 deletions Natacha/Clase15/ejemploCrud/php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"require-dev": {
"phpunit/phpunit": "^7.3",
"sebastian/version": "^2.0"
},
"require": {
"guzzlehttp/guzzle": "^6.3"
}
}
278 changes: 276 additions & 2 deletions Natacha/Clase15/ejemploCrud/php/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Natacha/Clase15/ejemploCrud/php/guzzletests/testBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
require 'vendor/autoload.php';

$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $res->getStatusCode();
// 200
echo $res->getHeaderLine('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// '{"id": 1420053, "name": "guzzle", ...}'
Loading