PHP code example of sonypradana / php-library

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

    

sonypradana / php-library example snippets


DB::table('table_name')
  ->select(['column_1'])
  ->equal('column_2', 'fast_mvc')
  ->order("column_1", MyQuery::ORDER_ASC)
  ->limit(1, 10)
  ->all()
;

DB::table('table_name')
  ->update()
  ->values([
    'column_1' => 'simple_mvc',
    'column_2' => 'fast_mvc',
    'column_3' => 123
  ])
  ->equal('column_4', 'fast_mvc')
  ->execute()
;

// insert
DB::table('table_name')
  ->insert()
  ->values([
    'column_1'  => '',
    'column_2'  => 'simple_mvc',
    'column_3'  => 'fast_mvc'
    ])
  ->execute()
;

// delete
DB::table('table_name')
  ->delete()
  ->equal('column_3', 'slow_mvc')
  ->execute()
;

use System\Support\Facades;

PDO::transaction(function() {
    DB::table('table_name')
        ->insert()
        ->value('age', 22)
        ->execute()
    ;

    // some condition
    if (false === $statment) {
        return false;
    }

    return true;
});

  Schema::table('users', function(Column $column) {
    $column('user')->varchar(50);
    $column('pwd')->varchar(500)->notNull();
    $column->primeryKeys('user');
  })
  ->excute();

$coll = new Collection(['vb_net', 'c_sharp', 'java', 'python', 'php', 'javascript', 'html']);

$arr = $coll
  ->remove('html')
  ->sort()
  ->filter(fn ($item) => strlen($item) > 4)
  ->map(fn ($item) => ucfirst($item))
  ->each(function($item) {
    echo $item . PHP_EOL;
  })
  ->all()
;

// arr = ['c_sharp', 'javascript', 'python', 'vb_net']

class GreatConsole extends Console
{
  public function main()
  {
    // getter to get param form cli argument
    $name = $this->name ?? 'animus';

    style("Great console Aapplication")
    	->textGreen()
        ->newLines()
        ->push("hay my name is ")
        ->push($name)
        ->textYellow()
        ->out()
    ;
  }
}

#!usr/bin/env php

// $argv come with default global php
return (new greatConsole($argv))->main();


Str::chartAt('i love php', 3); // o
Str::concat(['i', 'love', 'php']); // i love php
Str::indexOf('i love php', 'p'); // 8
Str::lastIndexOf('i love php', 'p'); // 10
Str::match('i love php', '/love/'); // love
// ...
// and many more

Str::macro('prefix', fn($text, $prefix) => $prefix.$test);

echo Str::prefix('cool', 'its '); // its cool

$string = new Text('I Love rust');

echo $string->replace('rust', 'php')->lower()->slug();
// i-love-php

echo $string->length(); // 10
echo $string->isEmpty(); // false

Str::is('[email protected]', Regex::EMAIL); // true
bash
php cli greate --name php_mvc

# output:
# Great console application
# hay my name is php_mvc