<?php
/**
 * c:\tmp\php\php.exe c:\tmp\src\index.php
 * echo file_get_contents(__DIR__ . '\tmp.txt');
 * file_put_contents(__DIR__ . '\tmp.html', $view);
 */
error_reporting(-1);
// set_time_limit(0);
// $filename = 'time.txt';
// $end = 60; // Время выполнения скрипта (в секундах)
// $i = 0;
// try {
//     while (true) {
//         stopExec($filename, $end);
//         echo (++$i % 10 ? $i . str_repeat("\t", rand(1, 2)) : "");
//         flush();
//     }
// } catch (Exception $e) {
//     echo $e->getMessage();
// }
// function stopExec($filename, $end) {
//     if (! file_exists($filename)) {
//         $time = time();
//         file_put_contents($filename, $time);
//     } else {
//         $tmStmp = file_get_contents($filename);
//         $time = time() - $end;
//         if ($tmStmp < $time) {
//             unlink($filename);
//             $msg = 'Превышено время выполнения!';
//             throw new Exception($msg);
//         }
//     }
// }
// $arr = array("2236" => array("id" => "2236", "name" => "75D"),
//     "2241" =>  array("id" => "2241", "name" => "76F"),
//     "2242" =>  array("id" => "2242", "name" => "75C"),
//     "2243" =>  array("id" => "2243", "name" => "76A"));
// uasort($arr, function($a, $b) { return $a['name'] <=> $b['name']; });
// print_r($arr);
// $arr = array(
//     "2236" => array("id" => "2236", "name" => "75D"),
//     "2241" =>  array("id" => "2241", "name" => "76F"),
//     "2242" =>  array("id" => "2242", "name" => "75C"),
//     "2243" =>  array("id" => "2243", "name" => "76A"),
//     "2245" =>  array("id" => "2245", "name" => "100B"),
//     "2246" =>  array("id" => "2246", "name" => "100A"));
// array_multisort(array_column($arr, 'name'), SORT_ASC, SORT_NATURAL, $arr);
// print_r($arr);
// $str = <<<STR
// STR;
// $str = preg_replace_callback(
//     '~~',
//     function($m){
//         print_r($m);
//         #return;
//     },
//     $str
// );
// #echo $str;
// $str = <<<STR
// STR;
// $pcre = '~~';
// preg_match_all($pcre, $str, $arr);
// print_r($arr);
// $str = 'whiteоченьwhiteочень';
// $str = preg_replace('~(?<=\p{Latin})(?=\p{Cyrillic})|(?<=\p{Cyrillic})(?=\p{Latin})~iu', ' ', $str);
// echo $str; // white очень white очень
// date_default_timezone_set('Europe/Kiev');
// echo (new DateTime)->modify('-5 minutes')->format('H:i:s') . PHP_EOL;
// echo (new DateTime)->modify('-10 minutes')->format('H:i:s') . PHP_EOL;
// echo (new DateTime('-5 minutes'))->format('H:i:s') . PHP_EOL;
// echo (new DateTime('-10 minutes'))->format('H:i:s') . PHP_EOL;
// $sim = similar_text('barfoo', 'barfoo', $perc);
// echo "сходство: $sim ($perc %)\n";
// $sim = similar_text('barfoo', 'bafoobar', $perc);
// echo "сходство: $sim ($perc %)\n";
// $c = new SplFixedArray(4);
// $c[0] = 'p';
// $c[1] = 'Драмы';
// $c[2] = 'Комедии';
// $c[3] = 'Жанры';
// $key = array_search('Драмы', $c->toArray());
// echo $key;
// Шаблонизатор
// function render(string $path, array $params): string {
//     extract($params);
//     ob_start();
//     require $path;
 
//     return ob_get_clean();
// }
// 
// file_put_contents(__DIR__ . '\tmp.html', $view);
// class MethodTest
// {
//     public function __call($name, $arguments) {
//         // Замечание: значение $name регистрозависимо.
//         print_r($arguments);
//         echo "Вызов метода '$name' " . implode(', ', $arguments). "\n";
//     }
// }
// $obj = new MethodTest;
// $obj->runTest('в контексте объекта');
// class Account
// {
//     private $login;
    
//     public static function create()
//     {
//         return new self;
//     }
//     public function __call($name, $arguments) {
//         echo "Вызов метода '$name' " . implode(', ', $arguments). "\n";
//     }
// }
// account::create()->lastConnect(time());
// $start = microtime(true);
// //-----------------------------------------------------------------------------
// for ($i = 0; $i < 100000; $i++) { 
//    
// }
// //-----------------------------------------------------------------------------
// $time = microtime(true) - $start;
// printf('Время выполнения скрипта %.4F сек.', $time);
// trait Foo
// {
//     private static function create()
//     {
//         return new self;
//     }
// }
// class Account
// {
//     use Foo { create as public; }
//     public function __call($name, $arguments)
//     {
//         echo "Вызов метода '$name' " . join(', ', $arguments). "\n";
//     }
// }
// class Bar extends Account {}
// Bar::create()->lastConnect(123);
// $array = [
//     'April' => [
//         ['Unreal' => 3200],
//         ['Real' => 2280],
//         ['Owful' => 5400]
//     ]
// ];
// $outArray = array_map(function($a) {
//     return call_user_func_array('array_merge', $a);
// }, $array);
// var_export($outArray);
// /* Результат:
// $array = [
//     'April' => [
//         'Unreal' => 3200,
//         'Real' => 2280,
//         'Owful' => 5400
//     ],
// ];
// */
// ob_start();
// // ---------------------------------------------------------
// // print_r();
// // ---------------------------------------------------------
// file_put_contents(__DIR__ . '\tmp.html', ob_get_clean());
/*
abstract class DomainObject
{
    private $group;
    public function __construct()
    {
        $this->group = static::getGroup();
    }
    
    public static function create()
    {
        return new static;
    }
    
    public static function getGroup()
    {
        return "default";
    }
}
class User extends DomainObject {}
class Document extends DomainObject
{
    public static function getGroup()
    {
        return "document";
    }
}
class SpreadSheet extends Document {}
print_r ( User::create() );
print_r ( SpreadSheet::create() ) ;
*/
/*
class Conf
{
    private $file;
    private $xml;
    private $lastmatch;
    public function __construct($file)
    {
        $this->file = $file;
        $this->xml = simplexml_load_file($file);
    }
    public function write()
    {
        file_put_contents($this->file, $this->xml->asXML());
    }
    public function get($str)
    {
        $matches = $this->xml->xpath("/conf/item[@name=\"$str\"]");
        if (count($matches)) {
            $this->lastmatch = $matches[0];
            return (string) $matches[0];
        }
        return null;
    }
    public function set($key, $value)
    {
        if (! is_null($this->get($key))) {
            $this->lastmatch[0] = $value;
            return null;
        }
        $conf = $this->xml->conf;
        $this->xml->addChild('item', $value)->addAttribute('name', $key);
    }
}
$conf = new Conf(__DIR__ . '/test.xml');
var_dump($conf->get('user'));
var_dump($conf->get('pass'));
var_dump($conf->get('host'));
*/
// echo getTime(60); // 00:01:00
// function getTime(int $time): string
// {
//     $date = new \DateTime('@0');
//     return $date->diff(new \DateTime("@$time"))->format('%H:%I:%S');
// }
// ob_start();
// // date_default_timezone_set('Europe/Kiev');
// // ---------------------------------------------------------
// // print_r();
// // ---------------------------------------------------------
// file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'tmp.html', ob_get_clean());