$func = function ($data) use (&$func) {
...
$result = $func($newData);
....
return $result;
}
<?php
namespace Kohana\Mvc;
/**
* Acts as an object wrapper for HTML pages with embedded PHP, called "views". Variables can be assigned with the view
* object and referenced locally within the view.
*
* @package Kohana\MVC
*/
abstract class AbstractView
{
/**
* @var array Global variables
*/
protected static $globalData = [];
/**
* @var array Local variables
*/
protected $data = [];
/**
* @var string View filename
*/
protected $file;
/**
* @var string Source view filename
*/
protected $sourceFile;
/**
* Captures the output that is generated when a view is included.
* The view data will be extracted to make local variables. This method
* is static to prevent object scope resolution.
*
* @param string $k_view_filename Filename
* @param array $k_view_data Variables
* @return string
*/
protected static function capture(string $k_view_filename, array $k_view_data): string
{
// Import the view variables to local namespace
extract($k_view_data, EXTR_SKIP);
if (static::$globalData) {
// Import the global view variables to local namespace
extract(static::$globalData, EXTR_SKIP | EXTR_REFS);
}
// Capture the view output
ob_start();
try {
// Load the view within the current scope
include $k_view_filename;
} catch (Throwable $e) {
// Delete the output buffer
ob_end_clean();
// Re-throw the exception
$vars = [':file' => Debug::path($k_view_filename), ':error' => $e->getMessage()];
throw new ViewException('Render error in view :file: :error', $vars, 0, $e);
}
// Get the captured output and close the buffer
return ob_get_clean();
}
/**
* Sets a global variable, similar to `set()`, except that the variable will be accessible to all views.
* Note: when setting with using iterable object we're not attaching the whole object to the view, i.e. the
* object's standard properties will not be available in the view context.
*
* @param string|iterable $key Variable name or an array of variables
* @param mixed $value Value
* @return void
*/
public static function setGlobal($key, $value = null): void
{
if (is_iterable($key)) {
foreach ($key as $name => $value) {
static::$globalData[$name] = $value;
}
} else {
static::$globalData[$key] = $value;
}
}
/**
* Assigns a global variable by reference, similar to `bind()`, except that the variable will be accessible to all
* views.
*
* @param string $key Variable name
* @param mixed $value Referenced variable
* @return void
*/
public static function bindGlobal(string $key, &$value): void
{
static::$globalData[$key] =& $value;
}
/**
* Sets the initial view filename and local data.
*
* @param string|null $file View filename
* @param iterable $data Array of values
*/
public function __construct(?string $file = null, iterable $data = [])
{
if ($file !== null) {
$this->setFilename($file);
}
if ($data) {
// Add the values to the local data
$this->set($data);
}
}
/**
* Magic method, searches for the given variable and returns its value. Local variables will be returned before
* global variables. If the variable has not yet been set, an exception will be thrown.
*
* @param string $key Variable name
* @return mixed
* @throws ViewException
*/
public function &__get(string $key)
{
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
if (array_key_exists($key, static::$globalData)) {
return static::$globalData[$key];
}
throw new ViewException('Variable :var is not set', [':var' => $key]);
}
/**
* Magic method, calls `set()` with the same parameters.
*
* @param string $key Variable name
* @param mixed $value Value
* @return void
*/
public function __set(string $key, $value): void
{
$this->set($key, $value);
}
/**
* Magic method, determines if a variable is set.
*
* @param string $key Variable name
* @return bool
*/
public function __isset(string $key): bool
{
return isset($this->data[$key]) || isset(static::$globalData[$key]);
}
/**
* Magic method, unsets a given variable.
*
* @param string $key Variable name
* @return void
*/
public function __unset(string $key): void
{
unset($this->data[$key], static::$globalData[$key]);
}
/**
* Magic method, returns the output of `render()`.
*
* @return string
*/
public function __toString(): string
{
try {
return $this->render();
} catch (Throwable $e) {
// Display the exception message and halt script execution.
// We use this method here because it's impossible to throw an exception from `__toString()`.
ViewException::handler($e);
}
// This line will never ne reached
return '';
}
/**
* Sets the view filename.
*
* @param string $file View filename
* @return $this
* @throws ViewException
*/
public function setFilename(string $file)
{
$path = Kohana::findFile('views', $file);
if (! $path) {
throw new ViewException('The requested view ":file" could not be found', [':file' => $file]);
}
// Store the file path locally
$this->file = $path;
$this->sourceFile = $file;
return $this;
}
/**
* Gets the source view filename.
*
* @return string|null
*/
public function getFilename(): ?string
{
return $this->sourceFile;
}
/**
* Assigns a variable by name. Assigned values will be available as a variable within the view file.
*
* @param string|iterable $key Variable name or an array of variables
* @param mixed $value Value
* @return $this
*/
public function set($key, $value = null): self
{
if (is_iterable($key)) {
foreach ($key as $name => $value) {
$this->data[$name] = $value;
}
} else {
$this->data[$key] = $value;
}
return $this;
}
/**
* Assigns a value by reference. The benefit of binding is that values can be altered without re-setting them. It
* is also possible to bind variables before they have values. Assigned values will be available as a variable
* within the view file.
*
* @param string $key Variable name
* @param mixed $value Referenced variable
* @return $this
*/
public function bind(string $key, &$value): self
{
$this->data[$key] =& $value;
return $this;
}
/**
* Renders the view object to a string. Global and local data are merged and extracted to create local variables
* within the view file. Global variables with the same key name as local variables will be overwritten by the
* local variable.
*
* @param string $file View filename
* @return string
* @throws ViewException
*/
public function render(string $file = null): string
{
if ($file !== null) {
$this->setFilename($file);
}
if (! $this->file) {
throw new ViewException('You must set the file to use within your view before rendering');
}
// Combine local and global data and capture the output
return $this->capture($this->file, $this->data);
}
}
<?php $message = (new View($_POST))->render('edit'); ?>
<label><?=$message;?></label>
ini_set('max_execution_time', 60);
$cookieFile = tempnam(sys_get_temp_dir(), 'ccf');
$timeOut = ini_get('max_execution_time') - 5;
$ch = curl_init();
curl_setopt_array(
$ch,
[
CURLOPT_AUTOREFERER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => $timeOut,
CURLOPT_TIMEOUT => $timeOut,
CURLOPT_COOKIEFILE => $cookieFile,
CURLOPT_COOKIEJAR => $cookieFile,
CURLOPT_POSTFIELDS => [
"num" => "7746468933",
"date" => "2010-16-20",
"captchaWord" => "",
"reCaptchaToken" => "03...hg"
],
CURLOPT_URL => 'https://xn--b1afk4ade.xn--90adear.xn--p1ai/proxy/check/driver',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
CURLOPT_HTTPHEADER => [
'Upgrade-Insecure-Requests: 1',
'Pragma: no-cache',
'Cache-Control: no-cache',
'Origin: https://xn--90adear.xn--p1ai',
'Referer: https://xn--90adear.xn--p1ai/check/driver',
],
]
);
var_dump(curl_exec($ch));
// {"code":201,"message":"Проверка с помощью Google reCaptcha v3 не была пройдена, повторите попытку."}
curl_close($ch);
POST https://check.gibdd.ru/proxy/check/driver HTTP/1.1
Host: check.gibdd.ru
...
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache