1. Go to this page and download the library: Download italix/contracts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
italix / contracts example snippets
use Italix\Contracts\DataContainer;
// Create with initial data
$user = new DataContainer(['name' => 'Alice', 'age' => 30]);
// Array syntax works naturally
$user['email'] = '[email protected]';
echo $user['name']; // 'Alice'
isset($user['email']); // true
unset($user['age']);
// Method syntax with fluent chaining
$user->set('city', 'Rome')
->set('role', 'admin')
->merge(['active' => true, 'score' => 100]);
$user = new DataContainer(['name' => 'Alice', 'role' => 'admin']);
// get() with default value — never throws on missing keys
$user->get('name'); // 'Alice'
$user->get('missing'); // null
$user->get('missing', 'N/A'); // 'N/A'
// Check existence
$user->has('name'); // true — key exists and is not null
$user->has('missing'); // false
$user->has_key('name'); // true — key exists (even if value is null)
use Italix\Contracts\DataContainer;
class Config extends DataContainer
{
/**
* Get a nested value using dot notation.
*/
public function dot_get(string $path, $default = null)
{
$keys = explode('.', $path);
$value = $this->data;
foreach ($keys as $key) {
if (!is_array($value) || !array_key_exists($key, $value)) {
return $default;
}
$value = $value[$key];
}
return $value;
}
}
$config = new Config([
'database' => ['host' => 'localhost', 'port' => 3306],
]);
$config->dot_get('database.host'); // 'localhost'
$config->dot_get('database.name', 'myapp'); // 'myapp' (default)
use Italix\Contracts\DataContainer;
class FormData extends DataContainer
{
/**
* Sanitize all string values.
*/
public function sanitize(): self
{
foreach ($this->data as $key => $value) {
if (is_string($value)) {
$this->data[$key] = trim(strip_tags($value));
}
}
return $this;
}
}
$input = new FormData($_POST);
$input->sanitize();
$clean_name = $input->get('name');
use Italix\Contracts\TableMeta;
use Italix\Contracts\ColumnMeta;
class UsersTable implements TableMeta
{
private array $columns;
public function describe_columns(): iterable
{
return $this->columns;
}
public function describe_column(string $name): ?ColumnMeta
{
return $this->columns[$name] ?? null;
}
}
use Italix\Contracts\ColumnMeta;
class VarcharColumn implements ColumnMeta
{
public function get_name(): string { return $this->name; }
public function get_type(): string { return 'VARCHAR'; }
public function is_nullable(): bool { return $this->nullable; }
public function is_primary_key(): bool { return false; }
public function get_length(): ?int { return $this->length; }
public function get_default() { return $this->default; }
public function has_default(): bool { return $this->hasDefault; }
}
use Italix\Forms\FormMeta;
// Any TableMeta implementation works
$form = new FormMeta($usersTable);
// DelegatedTableMeta enables delegation
$form = new FormMeta($thingsTable);
$form->delegate('Book'); // Merges Thing + Book columns
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.