/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Controller/Controller.php
$this->eventTrigger("controller.beforeAction", [$params], $this);
}
public function afterActionInternal($action, $params, $response)
{
$this->afterAction($action, $params, $response);
$this->eventTrigger("controller.afterAction", [$params, $response], $this);
}
public function beforeAction($action, $params)
{
}
public function afterAction($action, $params, $response)
{
}
public function error($code = 404, $message = null)
{
throw new HttpException($code, $message);
}
public function jsonResponse($data = [])
{
header('Content-Type: application/json');
echo json_encode($data);
}
/**
* @param $class string|Model
* @param $filter array|string|int
* @return Model
* @throws HttpException
*/
public function getOr404(Model $class, $filter)
{
if (!is_array($filter)) {
$filter = ['id' => $filter];
}
$model = $class::objects()->filter($filter)->get();
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Controller/Controller.php
public function jsonResponse($data = [])
{
header('Content-Type: application/json');
echo json_encode($data);
}
/**
* @param $class string|Model
* @param $filter array|string|int
* @return Model
* @throws HttpException
*/
public function getOr404(Model $class, $filter)
{
if (!is_array($filter)) {
$filter = ['id' => $filter];
}
$model = $class::objects()->filter($filter)->get();
if (!$model) {
$this->error(404);
}
return $model;
}
}
/home/i/ikolbin/sila-shop.ru/app/Modules/Request/Controllers/RequestController.php
{
$this->processInlineForm(new WholesaleForm());
}
public function recallModal()
{
$this->processModelForm(
new RecallForm(),
'pages/recall/index.tpl',
'pages/recall/success.tpl',
[
'title' => self::t('messages', 'Заказать обратный звонок'),
'button' => self::t('messages', 'Заказать звонок')
]
);
}
public function fastModal($id, $offerId = null)
{
$product = $this->getOr404(new Product(), $id);
$fast = new Fast();
$fast->product_id = $product->id;
if($offerId && $offer = Offer::objects()->filter(['product' => $id, 'id' => $offerId])->get()) {
$fast->size = $offer->name;
}
$form = new FastForm();
$form->setInstance($fast);
$this->processModelForm(
$form,
'pages/recall/index.tpl',
'pages/recall/success.tpl',
[
'title' => self::t('messages','Быстрый заказ'),
'button' => self::t('messages','Заказать сейчас')
]
);
}
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Di/Container.php
* Invoke callable with dependency injection
*
* @param $callable
* @param array $attributes
* @return mixed
* @throws ContainerException
* @throws NotFoundContainerException
* @throws ReflectionException
* @throws InvalidAttributeException
*/
public function invoke($callable, $attributes = [])
{
if (!is_callable($callable)) {
throw new InvalidAttributeException('$callable attribute must be callable');
}
$dependencies = $this->fetchCallableDependencies($callable);
$parameters = $this->buildParameters($attributes);
$arguments = $this->buildFunctionArguments($dependencies, $parameters);
if ($arguments) {
return call_user_func_array($callable, $arguments);
} else {
return call_user_func($callable);
}
}
/**
* Construct instance of class with constructor arguments
*
* @param string $className
* @param $arguments array
* @return object
* @throws ContainerException
* @throws NotFoundContainerException
* @throws ReflectionException
*/
public function construct(string $className, $arguments = [])
{
return $this->make($className, $arguments);
}
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Di/Container.php
* Invoke callable with dependency injection
*
* @param $callable
* @param array $attributes
* @return mixed
* @throws ContainerException
* @throws NotFoundContainerException
* @throws ReflectionException
* @throws InvalidAttributeException
*/
public function invoke($callable, $attributes = [])
{
if (!is_callable($callable)) {
throw new InvalidAttributeException('$callable attribute must be callable');
}
$dependencies = $this->fetchCallableDependencies($callable);
$parameters = $this->buildParameters($attributes);
$arguments = $this->buildFunctionArguments($dependencies, $parameters);
if ($arguments) {
return call_user_func_array($callable, $arguments);
} else {
return call_user_func($callable);
}
}
/**
* Construct instance of class with constructor arguments
*
* @param string $className
* @param $arguments array
* @return object
* @throws ContainerException
* @throws NotFoundContainerException
* @throws ReflectionException
*/
public function construct(string $className, $arguments = [])
{
return $this->make($className, $arguments);
}
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Application/Application.php
isset($match['target'][0]) &&
is_a($match['target'][0], ControllerInterface::class, true))
{
$controllerClass = $match['target'][0];
$action = isset($match['target'][1]) ? $match['target'][1] : null;
$params = isset($match['params']) ? $match['params'] : [];
$name = isset($match['name']) ? $match['name'] : null;
if ($router && $name) {
$router->setCurrentName($name);
}
$this->logDebug("Processing route to controller '{$controllerClass}' and action '{$action}'", ['params' => $params]);
/** @var Controller $controller */
$controller = $this->_container->construct($controllerClass);
$action = $action ?: $controller->defaultAction;
$this->eventTrigger("application.beforeRunController", [$controller, $action, $name, $params], $this);
$controller->beforeActionInternal($action, $params);
$matched = $this->_container->invoke([$controller, $action], $params);
$controller->afterActionInternal($action, $params, $matched);
$this->eventTrigger("application.afterRunController", [$controller, $action, $name, $params, $matched], $this);
} elseif (is_callable($match['target'])) {
$fn = $match['target'];
$matched = $fn($this->request, $match['params']);
} else {
$matched = false;
}
return $matched;
}
public function handleCliRequest()
{
/** @var CliRequest $request */
$request = $this->getComponent(CliRequestInterface::class);
$this->logDebug("Try to find command");
if (!$request->isEmpty()) {
list($class, $action, $arguments) = $request->match();
/** @var Command $command */
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Application/Application.php
if ($this->hasComponent(AuthInterface::class)) {
return $this->getComponent(AuthInterface::class)->getUser();
}
return null;
}
public function handleWebRequest()
{
/** @var HttpRequestInterface $request */
$request = $this->getComponent(HttpRequestInterface::class);
/** @var RouterInterface $router */
$router = $this->getComponent(RouterInterface::class);
$url = $request->getUrl();
$method = $request->getMethod();
$this->logDebug("Matching route for url '{$url}' and method '{$method}'");
$matches = $router->match($url, $method);
foreach ($matches as $match) {
$matched = $this->handleMatch($match, $router);
if ($matched !== false) {
return true;
}
}
$this->logDebug("Matching route not found");
throw new NotFoundHttpException("Page not found");
}
public function handleMatch(array $match, RouterInterface $router = null)
{
if (is_array($match['target']) &&
isset($match['target'][0]) &&
is_a($match['target'][0], ControllerInterface::class, true))
{
$controllerClass = $match['target'][0];
$action = isset($match['target'][1]) ? $match['target'][1] : null;
$params = isset($match['params']) ? $match['params'] : [];
$name = isset($match['name']) ? $match['name'] : null;
if ($router && $name) {
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Application/Application.php
$this->logDebug("Application run");
$this->eventTrigger("application.beforeRun", [], $this);
$this->provideModuleEvent('onApplicationRun');
register_shutdown_function([$this, 'end'], 0);
$this->logDebug("Start handling request");
$this->handleRequest();
$this->end();
}
public function end($status = 0, $response = null)
{
$this->eventTrigger("application.beforeEnd", [], $this);
$this->provideModuleEvent('onApplicationEnd', [$status, $response]);
exit($status);
}
public function handleRequest()
{
if ($this->getIsWebMode()) {
$this->handleWebRequest();
} else {
$this->handleCliRequest();
}
}
/**
* @return bool
*/
public static function getIsCliMode()
{
return php_sapi_name() == 'cli';
}
/**
* @return bool
*/
public static function getIsWebMode()
{
return !self::getIsCliMode();
}
/home/i/ikolbin/sila-shop.ru/vendor/phact-cmf/phact/src/Phact/Application/Application.php
/**
* Check or create system path
*
* @param $path
* @return bool
*/
protected function setUpPath($path): bool
{
return is_dir($path) || mkdir($path, 0755, true);
}
public function run()
{
$this->logDebug("Application run");
$this->eventTrigger("application.beforeRun", [], $this);
$this->provideModuleEvent('onApplicationRun');
register_shutdown_function([$this, 'end'], 0);
$this->logDebug("Start handling request");
$this->handleRequest();
$this->end();
}
public function end($status = 0, $response = null)
{
$this->eventTrigger("application.beforeEnd", [], $this);
$this->provideModuleEvent('onApplicationEnd', [$status, $response]);
exit($status);
}
public function handleRequest()
{
if ($this->getIsWebMode()) {
$this->handleWebRequest();
} else {
$this->handleCliRequest();
}
}
/**
/home/i/ikolbin/sila-shop.ru/www/index.php
<?php
include(__DIR__ . '/../vendor/autoload.php');
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/../');
$dotenv->load();
define('PHACT_DEBUG', getenv('DEBUG') === 'true');
$config = include __DIR__ . '/../app/config/settings.php';
\Phact\Main\Phact::init($config);
\Phact\Main\Phact::app()->run();