Skip to content

Instantly share code, notes, and snippets.

@alpharder
alpharder / orms.md
Last active October 16, 2025 21:34
On ORMs

Business logic entities ARE NOT ORM models/entities

Important note: This paragraph doesn't attempt to describe a "silver bullet" aka "the only right way of doing things". What it describes is just a preferred approach of isolating persistence details from business logic at Tesseract. The world won't collapse if domain service makes direct calls to ORM or SQL. For some (usually small) projects, the separation of concerns described below may not be beneficial, and only add complexity and cognitive load instead.

Domain layer should know nothing about any persistence layer.

@alpharder
alpharder / gist:0252239c91612be90d8e287b28e8a178
Created June 20, 2019 17:26
incorrect date/time @ API response
curl -i https://api.selcdn.ru/v3/auth/tokens -XPOST -d '{"auth": { "identity": { "methods": ["password"], "password": { "user": { "id": "foo", "password": "bar"}}}}}'
HTTP/2 201
access-control-allow-origin: *
content-length: 781
content-type: application/json
x-subject-token: xxx
date: Thu, 20 Jun 2019 17:20:45 GMT
{"token":{"expires_at":"2019-06-21T11:35:20.207420239Z","issued_at":"2019-06-20T20:20:45.207420239Z","methods":["password"],"project":{"domain":{}},"catalog":[{"endpoints":[{"id":"asd","region_id":"ru-1","url":"https://api.selcdn.ru/v1/xxx","region":"ru-1","interface":"public"},{"id":"asd","region_id":"ru-1","url":"https://api.selcdn.ru/v1/xxx","region":"ru-1","interface":"admin"},{"id":"asd","region_id":"ru-1","url":"https://api.selcdn.ru/v1/xxx","region":"ru-1","interface":"internal"}],"type":"object-store","name":"swift","id":""}],"user":{"id":"asd","name":"xxx","domain":{"id":"default","name":"Default","links":{}}},"audit_ids":[""]}}
@alpharder
alpharder / add.php
Last active April 3, 2019 11:13
У вас нет доступа к библиотекам для работы с большими числами. Дано два положительных целых числа в виде строки. Числа могут быть очень большими, могут не поместиться в 64 битный integer. Использование exec не допускается. Задание: Написать функцию которая вернет сумму этих чисел.
<?php
$sum_test_cases = [
['1', '2', '3'],
['1', '100', '101'],
['0', '0', '0'],
['1234567', '1', '1234568'],
['9999999', '1', '10000000'],
// Следующие значения значительно больше, чем Int64
server {
listen 80;
server_name cscart.dev;
server_name test.cscart.dev;
############################################################################
# listen 443 ssl;
# ssl_certificate /etc/nginx/ssl/nginx.crt;
# ssl_certificate_key /etc/nginx/ssl/nginx.key;
############################################################################
charset utf-8;

Application

С версии 4.3.2 появилась новая сущность - Tygh\Application.

Объект класса Application создаётся при инициализации ядра в файле init.php, после чего он доступен отовсюду:

// получение объекта Application
Tygh::$app
diff --git a/app/addons/reward_points/func.php b/app/addons/reward_points/func.php
index f23a317..98a5e8d 100644
--- a/app/addons/reward_points/func.php
+++ b/app/addons/reward_points/func.php
@@ -164,8 +164,10 @@ function fn_reward_points_calculate_cart_taxes_pre(&$cart, &$cart_products, &$sh
if (isset($cart_products[$k]['points_info']['raw_price'])) {
$product_price_in_points = $price_coef * $cart_products[$k]['points_info']['raw_price'];
$cart['products'][$k]['extra']['points_info']['raw_price'] = $product_price_in_points;
- $cart['products'][$k]['extra']['points_info']['display_price'] = $cart['products'][$k]['extra']['points_info']['price'] = round($product_price_in_points);
- $cart['points_info']['total_price'] = (isset($cart['points_info']['total_price']) ? $cart['points_info']['total_price'] : 0) + $product_price_in_points;
diff --git a/app/controllers/backend/exim.php b/app/controllers/backend/exim.php
index 22409f8..92bbbae 100644
--- a/app/controllers/backend/exim.php
+++ b/app/controllers/backend/exim.php
@@ -1793,6 +1793,9 @@ function fn_export_build_conditions($pattern, $options)
return $conditions;
}
+/**
+ * @deprecated, use fn_exim_quote instead
diff --git a/app/controllers/backend/exim.php b/app/controllers/backend/exim.php
index 22409f8..92bbbae 100644
--- a/app/controllers/backend/exim.php
+++ b/app/controllers/backend/exim.php
@@ -1793,6 +1793,9 @@ function fn_export_build_conditions($pattern, $options)
return $conditions;
}
+/**
+ * @deprecated, use fn_exim_quote instead
diff --git a/app/Tygh/Backend/Storage/File.php b/app/Tygh/Backend/Storage/File.php
index 70d4a0d..be3910f 100644
--- a/app/Tygh/Backend/Storage/File.php
+++ b/app/Tygh/Backend/Storage/File.php
@@ -124,7 +124,9 @@ class File extends ABackend
return $file;
}
- if ($this->getOption('cdn') && Cdn::instance()->getOption('is_enabled')) {
+ $is_cdn = ($this->getOption('cdn') && Cdn::instance()->getOption('is_enabled'));
diff --git a/app/functions/fn.fs.php b/app/functions/fn.fs.php
index 87d88b7..f28a5fe 100644
--- a/app/functions/fn.fs.php
+++ b/app/functions/fn.fs.php
@@ -308,7 +308,7 @@ function fn_get_file_type($filename, $not_available_result = 'application/octet-
$types = fn_get_ext_mime_types('ext');
- $ext = fn_get_file_ext($filename);
+ $ext = fn_strtolower(fn_get_file_ext($filename));