-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7987b13
Showing
9 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
MAGIC_PUBLISHABLE_KEY= | ||
MAGIC_SECRET_KEY= | ||
|
||
DB_HOST=localhost | ||
DB_PORT=3306 | ||
DB_DATABASE= | ||
DB_USERNAME= | ||
DB_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
require "../start.php"; | ||
use Src\Post; | ||
|
||
header("Access-Control-Allow-Origin: *"); | ||
header("Content-Type: application/json; charset=UTF-8"); | ||
header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE"); | ||
header("Access-Control-Max-Age: 3600"); | ||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); | ||
|
||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | ||
$uri = explode( '/', $uri ); | ||
|
||
// all of our endpoints start with /post | ||
// everything else results in a 404 Not Found | ||
if ($uri[1] !== 'post') { | ||
header("HTTP/1.1 404 Not Found"); | ||
exit(); | ||
} | ||
|
||
// the user id is, of course, optional and must be a number: | ||
$userId = null; | ||
if (isset($uri[2])) { | ||
$userId = (int) $uri[2]; | ||
} | ||
|
||
$requestMethod = $_SERVER["REQUEST_METHOD"]; | ||
|
||
// pass the request method and user ID to the Post and process the HTTP request: | ||
$controller = new Post($dbConnection, $requestMethod, $userId); | ||
$controller->processRequest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"require": { | ||
"vlucas/phpdotenv": "^2.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Src\\": "src/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE `posts` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`title` varchar(255) NOT NULL, | ||
`body` text NOT NULL, | ||
`author` varchar(255) NOT NULL, | ||
`author_picture` varchar(255) NOT NULL, | ||
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`) | ||
); | ||
|
||
INSERT INTO `posts` (`title`, `body`, `author`, `author_picture`) VALUES | ||
('What is Magic?', 'Magic is a developer SDK that you can integrate into your application to enable passwordless authentication using magic links - similar to Slack and Medium.', '[email protected]', 'https://www.gravatar.com/avatar/ac8b2ad0f9d1970ab22960ae04f35118.png'), ('Why Magic?', 'Magic leverages blockchain-based, standardized public-private key cryptography to achieve identity management. When a new user signs up to your service, a public-private key pair is generated for them. ', '[email protected]', 'https://www.gravatar.com/avatar/ac8b2ad0f9d1970ab22960ae04f35118.png'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
namespace Src; | ||
|
||
class Database { | ||
|
||
private $dbConnection = null; | ||
|
||
public function __construct() | ||
{ | ||
$host = getenv('DB_HOST'); | ||
$port = getenv('DB_PORT'); | ||
$db = getenv('DB_DATABASE'); | ||
$user = getenv('DB_USERNAME'); | ||
$pass = getenv('DB_PASSWORD'); | ||
|
||
try { | ||
$this->dbConnection = new \PDO( | ||
"mysql:host=$host;port=$port;dbname=$db", | ||
$user, | ||
$pass | ||
); | ||
} catch (\PDOException $e) { | ||
exit($e->getMessage()); | ||
} | ||
} | ||
|
||
public function connet() | ||
{ | ||
return $this->dbConnection; | ||
} | ||
} |
Oops, something went wrong.