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 to the base of your project 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);