1. Go to this page and download the library: Download icebox-php/framework 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/ */
icebox-php / framework example snippets
use Icebox\ActiveRecord\Config as ArConfig;
$database_url = (string) env('DATABASE_URL');
if($database_url == null) {
throw new \LengthException('DATABASE_URL must have a value. example: mysql://username:password@host:port/database_name');
}
// parse the URL
$parsed = ArConfig::parseDatabaseUrl($database_url);
// Extract components
$dsn = $parsed['dsn'];
$username = $parsed['username'];
$password = $parsed['password'];
$options = $parsed['options'];
// User can customize options if needed
$options[PDO::ATTR_PERSISTENT] = true;
// Create PDO connection
$connection = new PDO($dsn, $username, $password, $options);
// Initialize ActiveRecord
ArConfig::initialize($connection);
use Icebox\Model;
class User extends Model
{
// Optional: specify custom table name
protected static $table = 'users';
// Optional: specify custom primary key
protected static $primaryKey = 'id';
}
class Post extends Model
{
// Table name will be inferred as 'posts'
// Primary key will default to 'id'
}
// Count records
$count = User::where('active', 1)->count();
// Check if exists
$exists = User::where('email', '[email protected]')->exists();
// Get first result
$user = User::where('active', 1)->first();
Log::addStdoutHandler(
'info' // level (optional, default: debug)
);
// Colorful output in CLI, plain output in web
Log::addClosureHandler(function($log) {
// $log object contains:
// - level: 'debug', 'info', 'warning', 'error', etc.
// - message: The log message
// - context: Additional context data
// - channel: Logger channel name
// - datetime: When the log occurred
// Send to monitoring services (Sentry, Airbrake, etc.)
if ($log->level === 'error') {
\Sentry\captureMessage($log->message, $log->context);
}
// Or send to Slack, email, etc.
}, 'error'); // level (optional, default: debug)
// Development setup
Log::addFileHandler('log/development.log');
Log::addStdoutHandler();
// Production setup
Log::addFileHandler('log/production.log', 'info');
Log::addSyslogHandler('myapp-prod', 'error', LOG_USER);
Log::addClosureHandler(function($log) {
// Send critical errors to monitoring
if (in_array($log->level, ['error', 'critical', 'alert', 'emergency'])) {
sendToMonitoringService($log);
}
}, 'error');
use Icebox\Log;
// Clear handlers for testing
Log::clearHandlers();
// Add test handlers
Log::addClosureHandler(function($log) {
echo "Test log: {$log->level} - {$log->message}\n";
});
// Check handler count
echo Log::handlerCount(); // 1
bash
php icebox console
php icebox c # Short alias
bash
$ php icebox console
Loading development environment (PHP 8.5.0)
Type 'exit' to quit, 'help' for help.
Psy Shell v0.12.17 (PHP 8.5.0 — cli) by Justin Hileman
>>> echo App::root_url();
http://localhost/myapp
>>> $user = User::find(1);
>>> echo $user->name;
John Doe
>>> exit
bash
php icebox test
bash
php icebox test tests/create_user_test.php
php icebox test tests/Feature/
bash
php icebox test --filter testCreateUser
php icebox test tests/UserTest.php --filter testCreateUser # more specific
php icebox test --filter testCreateUser
php icebox test --coverage-html coverage