PHP code example of sowe / framework

1. Go to this page and download the library: Download sowe/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/ */

    

sowe / framework example snippets


class MyEntity extends AbstractEntity{
    protected static $table = "myentity";
    protected static $key = "id";
}

$entities = new MyEntity();
// loads all entities
$all = $entities->list();

class MyResource extends AbstractObject{
    protected static $table = "myresource";
    protected static $key = "id";
}

$resources = new MyResource();
// Updating resource
$resources->load(10)
  ->setData("name", "Jonh")
  ->setData("lastname", "Doe")
  ->save();

$qb = new QueryBuilder("SELECT", $database);
$data = $qb->table("users")
   ->fields("id", "email", "role")
   ->condition("username", "=", "jdoe")
   ->run() //returns Query object
   ->fetchAll() // this is from Query object.

$mailer = new Mailer($host, $user, $pass, $sender, $sendername);
$mailer->new()
  ->to("[email protected]", "Javier")
  ->cc("[email protected]")
  ->subject("Test Sowe/Framework/Mailer")
  ->body("This is a test message sent with Sowe/Framework/Mailer")
  ->send();

use Sowe\Framework\Logger;
use Monolog\ErrorHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;

$logpath = __DIR__ . "/logs/log.log";
$logger = new Logger("");
$formatter = new LineFormatter(
    "[%datetime%]:%level_name%: %message% %context%\n",
    "Y-m-d\TH:i:s",
    true, /* allow break lines */
    true /* ignore empty contexts */
);
$stream = new StreamHandler($logpath, Logger::DEBUG);
$stream->setFormatter($formatter);
$logger->pushHandler($stream);
$handler = new ErrorHandler($logger);
$handler->registerErrorHandler([], false);
$handler->registerExceptionHandler();
$handler->registerFatalHandler();