by Stephen Ginn at Crema Design Studio
This repo contains a collection of reusable PHP helper functions.
You can install the package via composer:
composer config repositories.crema/helpers git https://github.com/cremadesign/helpers
composer require crema/helpers:@dev
Add the composer autoloader to your PHP file:
require_once '../vendor/autoload.php';
$udata = new UData();
$udata->getData();
print $udata;
echo ordinal(2);
$array = ["one", "two", "three", "four"];
echo random($array);
echo slugify("Lorem#Ipsum &$ Dolar Sit Amet!");
echo contains($query, $string);
$hs = new Haystack("yourwebsite.com");
switch ($hs) {
case $hs->contains('.test'):
echo "this is a local site";
break;
case $hs->contains('.com'):
echo "this is a live site";
break;
default:
echo "we don't know what this site is";
}
header('Content-Type: application/json');
$data = findItem($obj, $query);
print json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
removeDir("cache");
removeDirs([
"cache",
"api/.cached"
]);
logger("This is a test");
Warning: This function probably should not be used, since it breaks the gulp autorefresh.
echo console("This is a test");
$products = json_decode(file_get_contents("https://dummyjson.com/products/1"), true);
printJSON($products);
echo printData("filename.json");
- Follow the installation steps above.
- Add a file named credentials.json outside your public web folder with the following info:
{
"userid": "DH_USER_ID",
"apikey": "DH_API_KEY",
"ip": "DEFAULT_HOST_IP"
}
Add the composer autoloader to your PHP file:
use Crema\DreamhostApi;
$credentials = json_decode(file_get_contents("../credentials.json"));
$account = $credentials->dreamhost;
$dreamhost = new DreamhostApi($account);
$response = $dreamhost->getRecords("thor.website.com");
printJSON($response);
$response = $dreamhost->getDomains();
printJSON($response);
$response = $dreamhost->addRecord("thor.website.com", $account->ip);
printJSON($response);
$response = $dreamhost->addRecords("thor.website.com", $account->ip);
printJSON($response);
- Add a file named credentials.json outside your public web folder with the following info:
{
"email": {
"username": "email@example.com",
"password": "INSERT_PASSWORD_HERE",
"host": "secure.hostname.com",
"port": 465
},
"sender": {
"name": "Sender Name",
"email": "sending@example.com"
},
"recipient": {
"name": "Recipient Name",
"email": "recipient@example.com"
}
}
- Load the credentials and emailer within your PHP file:
$credentials = json_decode(file_get_contents("../credentials.json"));
$emailer = new Emailer($credentials->email, $credentials->sender, $recipient);
-
Send the email using one of the methods below:
- Send with Response
$emailSent = $emailer->sendEmail([ 'subject' => "Instagram App: New Client Added", 'body' => parsify($mjml) ]); $alertClass = $emailSent ? 'alert-success' : 'alert-danger'; echo "Alert Class: $alertClass<br>"; echo $emailSent ? 'Your message has been sent' : 'Your message has not been sent';
- Send with Callbacks
$emailer->sendEmail([ 'subject' => "Instagram App: New Account Invite", 'body' => parsify($mjml) ], function($mail) use (&$response) { $response->class = 'alert-success'; $response->msg = 'Your app invite was sent!'; }, function($errorInfo) use (&$response) { $response->class = 'alert-danger'; $response->msg = 'Your app invite failed to send!'; } );