View example2-refined.php
<?php | |
final class Payment { | |
public function subscribe(PostParams $data) : Transaction { | |
$transaction = Transaction::fromPost($data); | |
$model = new TransactionModel(); | |
$model->create($transaction); | |
$processor = $model->getProcessor($transaction); // a Processor object | |
View example2.php
<?php | |
final class Payment { | |
public function subscribe(array $transaction) : array { | |
// 1 | |
$transaction = [ | |
'payment_method' => $transaction['payment_method'] ?? 'credit-card', | |
'amount' => $transaction['total'] ?? $transaction['subtotal'] ?? 0.0, | |
'currency' => $transaction['currency_code'] ?? 'USD' | |
] + $transaction; | |
$model = new TransactionModel(); |
View search.php
<?php | |
$model = new User(); | |
$model->search(SearchParams::fromData($data)); |
View search.php
<?php | |
if (empty($data["username"])) { | |
throw new \Exception("Username is required."); | |
} | |
if (empty($data["name"])) { | |
$first = $data["first_name"] ?? ''; | |
$last = $data["last_name"] ?? ''; | |
$data["name"] = "$first $last"; | |
} | |
$params = new SearchParams($data['username'], $data['name']); |
View SearchParams.php
<?php | |
final class SearchParams { | |
private $username; | |
private $name; | |
private function __construct(string $username, string $name) { | |
$this->username = $username; | |
$this->name = $name; | |
} | |
public static function fromArray(array $params) : SearchParams { | |
if (empty($params["username"])) { |
View apo-search-refactored.php
<?php | |
final class User extends Requester { | |
public function search(SearchParams $params) : array { | |
return $this->request($params->toArray())->toArray(); | |
} | |
} |
View SearchParams.php
<?php | |
final class SearchParams { | |
private $username; | |
private $name; | |
public function __construct(string $username, string $name) { | |
$this->username = $username; | |
$this->name = $name; | |
} | |
public function toArray() : array { | |
return [ |
View aop.php
<?php | |
final class User extends Requester { | |
public function search(array $params) : array { | |
if (empty($params["username"])) { | |
throw new \Exception("Username is required."); | |
} | |
if (empty($params["name"])) { | |
$first = $params["first_name"] ?? ''; | |
$last = $params["last_name"] ?? ''; | |
$params["name"] = "$first $last"; |
View gist:e69a5ba8c9b2feed84bfabeb05082fb0
-----BEGIN PGP MESSAGE----- | |
Version: Keybase OpenPGP v2.0.53 | |
Comment: https://keybase.io/crypto | |
wcFMA6nGlPiddoX9AQ/+M/7mRkzgaaS+aV5R1ZgUkEq3ohEC2mJToKwOHObulm1g | |
gNLRo3dHQjaJSfE0Egeli3HSAz+9j5NbjFZ5w9m1Rh59v8k5FHN/gXJPbls7d1OZ | |
lE7F1jVjjUUnt+2jMtFbf6dZCDsbm3QFZLQkasUUIwAbdGr/FOd/3mbf8ZLLaspD | |
5l2/p03fINCdAypVilZ2dOGxje8CVPA576Megn2qIo5wwdeRoLlNLVlCwHtyNQC/ | |
KFjuVu6mUCwQM7oU4ChdJZeAnT/rY7iQOHJUmH2Gcj2uuYO1hZukuPD2sVYRK/Zk | |
yCFLolW1Gm2+6atQFki45U1qwWKAOHmvRWVUC9xxK/vydWKZssYp3Yvc1MrhjMvE |
View bootstrap.js
const path = require('path'); | |
const glob = require('glob'); | |
const express = require('express'); | |
const Bottle = require('bottlejs'); | |
const bottle = Bottle.pop('MyPdfApp'); // name your instance here. | |
glob.sync(path.join(path.resolve(__dirname), 'app/**/*.js')).forEach((match) => { | |
require(match); // just require, no need to pass the bottle reference. | |
}); |
NewerOlder