Initial commit: apps.prometeysev.ru

This commit is contained in:
root committed 2026-10-22 00:22:57 +03:00
commit 96ccabcd8b
6561 files changed
+1270349

No files matched your search

@@ -0,0 +1,68 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Model\Behavior;
use Cake\Event\Event;
use Cake\ORM\Behavior;
use DebugKit\DebugTimer;
/**
* Class TimedBehavior
*/
class TimedBehavior extends Behavior
{
/**
* beforeFind, starts a timer for a find operation.
*
* @param \Cake\Event\Event $event The beforeFind event
* @param \Cake\ORM\Query $query Query
* @return \Cake\ORM\Query
*/
public function beforeFind(Event $event, $query)
{
$alias = $event->getSubject()->getAlias();
DebugTimer::start($alias . '_find', $alias . '->find()');
return $query->formatResults(function ($results) use ($alias) {
DebugTimer::stop($alias . '_find');
return $results;
});
}
/**
* beforeSave, starts a time before a save is initiated.
*
* @param \Cake\Event\Event $event The beforeSave event
* @return void
*/
public function beforeSave(Event $event)
{
$alias = $event->getSubject()->getAlias();
DebugTimer::start($alias . '_save', $alias . '->save()');
}
/**
* afterSave, stop the timer started from a save.
*
* @param \Cake\Event\Event $event The afterSave event
* @return void
*/
public function afterSave(Event $event)
{
$alias = $event->getSubject()->getAlias();
DebugTimer::stop($alias . '_save');
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
/**
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Model\Entity;
use Cake\ORM\Entity;
/**
* Panel entity class.
*
* @property int $id
* @property int $request_id
* @property string $title
* @property string $element
* @property string $content
*/
class Panel extends Entity
{
/**
* Some fields should not be in JSON/array exports.
*
* @var array
*/
protected $_hidden = ['content'];
/**
* Read the stream contents.
*
* Over certain sizes PDO will return file handles.
* For backwards compatibility and consistency we smooth over that difference here.
*
* @param mixed $content Content
* @return string
*/
protected function _getContent($content)
{
if (is_resource($content)) {
return stream_get_contents($content);
}
return $content;
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace DebugKit\Model\Entity;
use Cake\ORM\Entity;
/**
* Request entity class.
*
* @property int $id
* @property array $panels
*/
class Request extends Entity
{
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Model\Table;
use Cake\Core\App;
use PDOException;
/**
* A set of methods for building a database table when it is missing.
*
* Because the debugkit doesn't come with a pre-built SQLite database,
* we'll need to make it as we need it.
*
* This trait lets us dump fixture schema into a given database at runtime.
*/
trait LazyTableTrait
{
/**
* Ensures the tables for the given fixtures exist in the schema.
*
* If the tables do not exist, they will be created on the current model's connection.
*
* @param array $fixtures The fixture names to check and/or insert.
* @return void
* @throws \RuntimeException When fixtures are missing/unknown/fail.
*/
public function ensureTables(array $fixtures)
{
/** @var \Cake\Database\Connection $connection */
$connection = $this->getConnection();
$schema = $connection->getSchemaCollection();
try {
$existing = $schema->listTables();
} catch (PDOException $e) {
// Handle errors when SQLite blows up if the schema has changed.
if (strpos($e->getMessage(), 'schema has changed') !== false) {
$existing = $schema->listTables();
} else {
throw $e;
}
}
try {
foreach ($fixtures as $name) {
$class = App::className($name, 'Test/Fixture', 'Fixture');
if ($class === false) {
throw new \RuntimeException("Unknown fixture '$name'.");
}
/** @var \Cake\Datasource\FixtureInterface $fixture */
$fixture = new $class($connection->configName());
if (in_array($fixture->table, $existing)) {
continue;
}
$fixture->create($connection);
}
} catch (PDOException $e) {
if (strpos($e->getMessage(), 'unable to open')) {
throw new RuntimeException(
'Could not create a SQLite database. ' .
'Ensure that your webserver has write access to the database file and folder it is in.'
);
}
throw $e;
}
}
}
@@ -0,0 +1,74 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\Table;
use DebugKit\Model\Entity\Panel;
/**
* The panels table collects the information for each panel on
* each request.
*
* @method Panel get($primaryKey, $options = [])
* @method Panel newEntity($data = null, array $options = [])
* @method Panel[] newEntities(array $data, array $options = [])
* @method Panel save(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method Panel patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method Panel[] patchEntities($entities, array $data, array $options = [])
* @method Panel findOrCreate($search, callable $callback = null)
*/
class PanelsTable extends Table
{
use LazyTableTrait;
/**
* initialize method
*
* @param array $config Config data.
* @return void
*/
public function initialize(array $config)
{
$this->belongsTo('DebugKit.Requests');
$this->ensureTables(['DebugKit.Requests', 'DebugKit.Panels']);
}
/**
* Find panels by requestid
*
* @param \Cake\ORM\Query $query The query
* @param array $options The options to use.
* @return \Cake\ORM\Query The query.
* @throws \RuntimeException
*/
public function findByRequest(Query $query, array $options)
{
if (empty($options['requestId'])) {
throw new \RuntimeException(__d('debug_kit', 'Missing request id in {0}.', 'findByRequest()'));
}
return $query->where(['Panels.request_id' => $options['requestId']])
->order(['Panels.title' => 'ASC']);
}
/**
* DebugKit tables are special.
*
* @return string
*/
public static function defaultConnectionName()
{
return 'debug_kit';
}
}
@@ -0,0 +1,128 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Driver\Sqlite;
use Cake\ORM\Query;
use Cake\ORM\Table;
use DebugKit\Model\Entity\Request;
/**
* The requests table tracks basic information about each request.
*
* @method Request get($primaryKey, $options = [])
* @method Request newEntity($data = null, array $options = [])
* @method Request[] newEntities(array $data, array $options = [])
* @method Request save(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method Request patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method Request[] patchEntities($entities, array $data, array $options = [])
* @method Request findOrCreate($search, callable $callback = null)
*/
class RequestsTable extends Table
{
use LazyTableTrait;
/**
* initialize method
*
* @param array $config Config data.
* @return void
*/
public function initialize(array $config)
{
$this->hasMany('DebugKit.Panels', [
'sort' => ['Panels.title' => 'ASC'],
]);
$this->addBehavior('Timestamp', [
'events' => [
'Model.beforeSave' => ['requested_at' => 'new'],
],
]);
$this->ensureTables(['DebugKit.Requests', 'DebugKit.Panels']);
}
/**
* DebugKit tables are special.
*
* @return string
*/
public static function defaultConnectionName()
{
return 'debug_kit';
}
/**
* Finder method to get recent requests as a simple array
*
* @param \Cake\ORM\Query $query The query
* @param array $options The options
* @return Query The query.
*/
public function findRecent(Query $query, array $options)
{
return $query->order(['Requests.requested_at' => 'DESC'])
->limit(10);
}
/**
* Check if garbage collection should be run
*
* @return bool
*/
protected function shouldGc()
{
return time() % 100 === 0;
}
/**
* Garbage collect old request data.
*
* Delete request data that is older than latest 20 requests.
* You can use the `DebugKit.requestCount` config to change this limit.
* This method will only trigger periodically.
*
* @return void
*/
public function gc()
{
if (!$this->shouldGc()) {
return;
}
$noPurge = $this->find()
->select(['id'])
->enableHydration(false)
->order(['requested_at' => 'desc'])
->limit(Configure::read('DebugKit.requestCount') ?: 20)
->extract('id')
->toArray();
$query = $this->Panels->query()
->delete()
->where(['request_id NOT IN' => $noPurge]);
$statement = $query->execute();
$statement->closeCursor();
$query = $this->query()
->delete()
->where(['id NOT IN' => $noPurge]);
$statement = $query->execute();
$statement->closeCursor();
$conn = $this->getConnection();
if ($conn->getDriver() instanceof Sqlite) {
$conn->execute('VACUUM;');
}
}
}