Why another library? Popular PHP Frameworks are monoliths. You need months to fully understand what happens behind the scenes. And they are build for thousdands of application-types, mostly for CMS and E-Commerce purpose. Although you only need a very small amount of functionality, you have to deal with all of it when it comes to security or debugging. We build loosely coupled packages that do no more than they should do.
Most parts are written for large scale stateless clustered microservices demanded by big-data, infrastructural, IoT environments.
See the core concepts page for more information.
All packages are build to be installed using composer and work inside Docker-Containers.
composer require phore/core
phore/http-client is a core library when doing microservices. This library is used whenever one microservice connects to another. You’ll save yourself a lot of time looking at the rich examples.
This script will load the html-contents of a remote url. It is a wrapper around the popular cURL library.
Basic Example
echo phore_http_request("https://infracamp.org")->send()->getBody();
Extended example
try {
$response = phore_http_request("http://server.tld/{param}/load", ["param" => "some unencoded string"])
->withPostBody(["some"=>"data"]) // Set Request-Method to POST and attach parameter as JSON Data
->withQueryParams(["param1"=>"value1"]) // Append ?param1=value1 to the URL
->send();
} catch (PhoreHttpRequestException $e) {
// Catch HTTP Error Response types
echo "Error: $e->getCode() returned. $e->getResponse()->getBody()";
exit(1);
}
$respones->getHeader("Expires");
$data = $response->getBodyJson(); // Parse the JSON Body
Other features:
A wrapper around the famous PHPMailer library combining it with the powerful and secure TextTemplate template system.
Basic example
$mailer = new PhoreMailer();
$mailer->send();
Plain-text html is a pain. phore/html is a fluent api for generating fast and secure pages.
Basic example
echo fhtml("div @class=some_class @style=display:none");
<div class="some_class" style="display:none"></div>
Complex example
$p = fhtml(["div @class=text" => ["b" => "some text here"]])
$p["div"] = [
"a @href=http://link.tld" => "Click here"
];
<div class="text">
<b>some text here</b>
<div>
<a href="http://link.tld">Click here</a>
</div>
</div>
exec()
,system()
,passthrou()
,popen()
are very dangerous and complex functions when dealing with user-data. This library makes usage easy and helps escaping the phore escaping system.
Basic example
echo phore_exec("ls -l :path", ["path" => "unescapedFilename"]);
Complex example
try {
$result = phore_proc("ls -l :path", ["path" => "unescapedFilename"])->wait();
echo "Stdout: " . $result->getSTDOUTContents();
echo "StdErr: " . $result->getSTDERRContents();
} catch (\Exception $e) {
}
A wrapper around the git command to push/pull/commit repositories using ssh-auth.
Basic example
$vcsFactory = new VcsFactory();
$repository = $vcsFactory->repository("/tmp/repo", "git@github.com:phore/phore-vcs.git");
$repository->pull();
$repository->commit("my commit message here");
$repository->push();
A small microservice / container ready framework.
A skeleton project exists for kickstart. Run
./kickstart.sh skel install php-app-base
to install a out of the box base application with kickstart.
A project with libraries used by other packages. You should know the basics of this project
phore_out([string $msg, [$return=false]])
Simple logging function. Alternative to echo
.
phore_pluck(mixed $key, mixed $input [, $default])
Tiered of doing if(isset())
- constructs when parsing structs? phore_pluck()
returns
the value of the data-path specified in $key. If path was not found, it returns $default
.
(See Concepts: $default)
$data = ["some"=>["path"=>"data"]];
assert( "data" === phore_pluck("some.path", $data) );
startsWith() : bool
: Check if string starts with an other stringendsWith() : bool
: Check if a string ends with an other stringphore_random_str() : string
: Generate encyption-grade random stringphore_text_unindent() : string
: Unindent a textphore_array_transform() : array
: Transform input array to another arrayphore_escape() : string
: The phore flexible escaping api.phore_json_pretty_print()
: Print json-string pretty formatedphore_json_encode($input) : string
: Encode data to jsonphore_json_decode(string $input) : array
: Decode json string or throw exceptionExceptions
PhoreException
: Phore internal Exception
InvalidDataException
: Should be thrown if user input is invalidNotFoundException
: Thrown if a key/entity/file was not found