├── .gitignore ├── .htaccess ├── README.md ├── composer.json ├── composer.phar ├── config └── database.config.php ├── database.sql ├── functions.php ├── index.php ├── modules └── ModuleDefault │ ├── Controllers │ ├── AbstractController.php │ ├── IndexController.php │ └── NovoController.php │ ├── Form │ └── Index │ │ ├── Create.php │ │ ├── Delete.php │ │ └── Update.php │ ├── Model │ ├── CarroBusiness.php │ └── Gateway │ │ └── Carro.php │ └── views │ ├── index │ └── index.phtml │ ├── layout.phtml │ └── novo │ └── index.phtml └── var └── log └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | # Does not show folders content 2 | Options -Indexes 3 | 4 | RewriteEngine on 5 | 6 | # check https 7 | #RewriteCond %{HTTPS} off 8 | #RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 9 | 10 | # check www 11 | # NC = case insensitive 12 | #RewriteCond %{HTTP_HOST} !^www\. [NC] 13 | #RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 14 | 15 | # The following rule tells Apache that if the requested filename 16 | # exists, simply serve it. 17 | RewriteCond %{REQUEST_FILENAME} -s [OR] 18 | RewriteCond %{REQUEST_FILENAME} -l [OR] 19 | RewriteCond %{REQUEST_FILENAME} -d 20 | RewriteRule ^.*$ - [NC,L] 21 | # The following rewrites all other queries to index.php. The 22 | # condition ensures that if you are using Apache aliases to do 23 | # mass virtual hosting, the base path will be prepended to 24 | # allow proper resolution of the index.php file; it will work 25 | # in non-aliased environments as well, providing a safe, one-size 26 | # fits all solution. 27 | RewriteCond %{REQUEST_URI}::youtube ^(/.+)(.+)::\2$ 28 | RewriteRule ^(.*) - [E=BASE:%1] 29 | RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 30 | 31 | # Set environment development variables 32 | SetEnv DEVELOPMENT true 33 | SetEnv SHOW_ERRORS true 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter-php-api 2 | Uma api simples feita para conexão com o flutter 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prescott/youtube", 3 | "description": "A youtube video", 4 | "type": "project", 5 | "require": { 6 | "braghim-sistemas/suitup-php": "^2" 7 | }, 8 | "license": "private", 9 | "minimum-stability": "dev" 10 | } 11 | -------------------------------------------------------------------------------- /composer.phar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thizer/flutter-php-api/331dea4fe863ec0d1732b56256a52768db46ebbb/composer.phar -------------------------------------------------------------------------------- /config/database.config.php: -------------------------------------------------------------------------------- 1 | 'mysql', 4 | 'host' => '192.168.15.36', 5 | 'dbname' => 'test', 6 | 'username' => 'youtube', 7 | 'password' => '142536', 8 | ); 9 | 10 | -------------------------------------------------------------------------------- /database.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.17 Distrib 10.3.17-MariaDB, for debian-linux-gnu (x86_64) 2 | -- 3 | -- Host: 127.0.0.1 Database: test 4 | -- ------------------------------------------------------ 5 | -- Server version 10.1.29-MariaDB-6+b1 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8mb4 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `carro` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `carro`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `carro` ( 26 | `pk_carro` int(11) NOT NULL AUTO_INCREMENT, 27 | `nome_carro` varchar(100) NOT NULL, 28 | PRIMARY KEY (`pk_carro`) 29 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 30 | /*!40101 SET character_set_client = @saved_cs_client */; 31 | 32 | -- 33 | -- Dumping data for table `carro` 34 | -- 35 | 36 | LOCK TABLES `carro` WRITE; 37 | /*!40000 ALTER TABLE `carro` DISABLE KEYS */; 38 | INSERT INTO `carro` VALUES (1,'Fusca'),(2,'Chevette'); 39 | /*!40000 ALTER TABLE `carro` ENABLE KEYS */; 40 | UNLOCK TABLES; 41 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 42 | 43 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 44 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 45 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 46 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 47 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 48 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 49 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 50 | 51 | -- Dump completed on 2019-10-15 12:18:40 52 | -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | add('System', 'library/.'); 28 | } else { 29 | exit("Project dependencies not found, run 'php composer.phar install'"); 30 | } 31 | 32 | // Let's start SuitUp Framework 33 | $mvc = new SuitUpStart('modules/'); 34 | 35 | // Sql monitoring 36 | $mvc->setSqlMonitor(DEVELOPMENT); 37 | 38 | $mvc->run(); 39 | 40 | -------------------------------------------------------------------------------- /modules/ModuleDefault/Controllers/AbstractController.php: -------------------------------------------------------------------------------- 1 | ajax(array('error' => 'Invalid Method')); 11 | } 12 | 13 | $carroBo = new \ModuleDefault\Model\CarroBusiness(); 14 | $lista = $carroBo->list(); 15 | 16 | return $this->ajax($lista); 17 | } 18 | 19 | public function getItemAction() { 20 | 21 | // Amarro o metodo para GET 22 | if (getenv('REQUEST_METHOD') != 'GET') { 23 | return $this->ajax(array('error' => 'Invalid Method')); 24 | } 25 | 26 | $id = $this->getParam('id', 0); 27 | 28 | $carroBo = new \ModuleDefault\Model\CarroBusiness(); 29 | $item = $carroBo->get($id); 30 | 31 | return $this->ajax($item ? $item : array()); 32 | } 33 | 34 | public function createAction() { 35 | 36 | // Amarro o metodo para POST 37 | if (getenv('REQUEST_METHOD') != 'POST') { 38 | return $this->ajax(array('error' => 'Invalid Method')); 39 | } 40 | 41 | // Instancio o formulário 42 | $form = new \ModuleDefault\Form\Index\Create(); 43 | $data = $form->getData(); 44 | 45 | // Valido o formulario 46 | if ($form->isValid()) { 47 | 48 | // Insert on db 49 | $carroBo = new \ModuleDefault\Model\CarroBusiness(); 50 | $newId = $carroBo->insert(array( 51 | 'nome_carro' => $data['name'] 52 | )); 53 | 54 | return $this->ajax(array('id' => $newId)); 55 | } 56 | 57 | // Caso for invalido 58 | return $this->ajax(array('errors' => $form->getMessages())); 59 | } 60 | 61 | public function updateAction() { 62 | 63 | // Amarro o metodo para PUT 64 | if (getenv('REQUEST_METHOD') != 'PUT') { 65 | return $this->ajax(array('error' => 'Invalid Method')); 66 | } 67 | 68 | // Instancio o formulário 69 | $form = new \ModuleDefault\Form\Index\Update(); 70 | $form->post = $this->getParams(); 71 | 72 | $data = $form->getData(); 73 | 74 | // Valido o formulario 75 | if ($form->isValid()) { 76 | 77 | // Update on db 78 | $carroBo = new \ModuleDefault\Model\CarroBusiness(); 79 | $rows = $carroBo->update( 80 | array('nome_carro' => $data['name']), 81 | array('pk_carro' => $data['id']) 82 | ); 83 | 84 | return $this->ajax(array('rows' => $rows)); 85 | } 86 | 87 | // Caso for invalido 88 | return $this->ajax(array('errors' => $form->getMessages())); 89 | } 90 | 91 | public function deleteAction() { 92 | 93 | // Amarro o metodo para DELETE 94 | if (getenv('REQUEST_METHOD') != 'DELETE') { 95 | return $this->ajax(array('error' => 'Invalid Method')); 96 | } 97 | 98 | $form = new \ModuleDefault\Form\Index\Delete(); 99 | $form->post = $this->getParams(); 100 | 101 | $data = $form->getData(); 102 | 103 | // Valido o formulario 104 | if ($form->isValid()) { 105 | 106 | // Update on db 107 | $carroBo = new \ModuleDefault\Model\CarroBusiness(); 108 | $result = $carroBo->delete(array('pk_carro' => $data['id'])); 109 | 110 | return $this->ajax(array('result' => $result)); 111 | } 112 | 113 | // Caso for invalido 114 | return $this->ajax(array('errors' => $form->getMessages())); 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /modules/ModuleDefault/Controllers/NovoController.php: -------------------------------------------------------------------------------- 1 | array('validation' => array('notEmpty', 'teste'), 'filter' => array('string')), 14 | ); 15 | 16 | public function teste($value) { 17 | 18 | $result = new \SuitUp\FormValidator\FormResult(); 19 | 20 | // $result->setError('Nao gostei'); 21 | 22 | return $result; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /modules/ModuleDefault/Form/Index/Delete.php: -------------------------------------------------------------------------------- 1 | array('validation' => array('notEmpty'), 'filter' => array('digits')), 14 | ); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /modules/ModuleDefault/Form/Index/Update.php: -------------------------------------------------------------------------------- 1 | array('validation' => array('notEmpty'), 'filter' => array('digits')), 14 | 'name' => array('validation' => array('notEmpty'), 'filter' => array('string')), 15 | ); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /modules/ModuleDefault/Model/CarroBusiness.php: -------------------------------------------------------------------------------- 1 | gateway->list(); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /modules/ModuleDefault/Model/Gateway/Carro.php: -------------------------------------------------------------------------------- 1 | 'NOW()'); 21 | 22 | public function list() { 23 | 24 | $query = $this->select("SELECT c.* FROM {$this->name} c") 25 | ->order('c.nome_carro ASC'); 26 | 27 | return $this->db->query($query); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /modules/ModuleDefault/views/index/index.phtml: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 | Card image cap 6 |
7 |
Card title
8 |

Some quick example text to build on the card title and make up the bulk of the card's content.

9 | Go somewhere 10 |
11 |
12 |
13 |
14 |
15 | Card image cap 16 |
17 |
Card title
18 |

Some quick example text to build on the card title and make up the bulk of the card's content.

19 | Go somewhere 20 |
21 |
22 |
23 |
24 | 25 | -------------------------------------------------------------------------------- /modules/ModuleDefault/views/layout.phtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Hello, world! 12 | 13 | 14 |
15 |

ModuleDefault

16 |

Created by SuitUp Manager Version: 1.0.2

17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /modules/ModuleDefault/views/novo/index.phtml: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 | Card image cap 6 |
7 |
NovoController
8 |

Some quick example text to build on the card title and make up the bulk of the card's content.

9 | Go somewhere 10 |
11 |
12 |
13 |
14 |
15 | Card image cap 16 |
17 |
NovoController
18 |

Some quick example text to build on the card title and make up the bulk of the card's content.

19 | Go somewhere 20 |
21 |
22 |
23 |
24 | 25 | -------------------------------------------------------------------------------- /var/log/.gitignore: -------------------------------------------------------------------------------- 1 | * --------------------------------------------------------------------------------