-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAplAdmin.php
35 lines (29 loc) · 894 Bytes
/
AplAdmin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
include '../data/Database.php';
class AplAdmin
{
public static function getPostsComoJson(){
$objetos = Database::getDados( '../data/posts.json' );
return json_encode( $objetos );
}
public static function getUsersComoJson(){
$objetos = Database::getDados( '../data/users.json' );
return json_encode( $objetos );
}
public static function saveUser( User $user ){
if( !$user->ehEmail() ){
/* EMAIL INVÁLIDO */
return;
}
$users = Database::getDados( '../data/users.json' );
foreach( $users as $u ){
if( strcasecmp( $u->email, $user->email ) == 0 ){
/* EMAIL JÁ SALVO */
return;
}
}
/* SALVANDO NOVO EMAIL */
$users[] = $user;
Database::saveDatabase( '../data/users.json', $users );
}
}