Skip to content

Instantly share code, notes, and snippets.

View mikhailovv's full-sized avatar

Vyacheslav Mikhailov mikhailovv

View GitHub Profile
@mikhailovv
mikhailovv / run.sh
Created January 7, 2022 14:10
Run PHP build-in server from docker
## Run docker in interactive mode
docker run -it -p 8082:8082 -v ${PWD}:/app php:latest bash
## Run build-in server with mounted sources
php -S 0.0.0.0:8082 public/index.php
@mikhailovv
mikhailovv / MailService.php
Created April 26, 2020 20:46
PHP Trait to run a private method in tests
<?php
class MailService
{
private function validateString(String $input, int $minSize = 10): bool
{
return strlen($input) >= $minSize;
}
}
@mikhailovv
mikhailovv / <ModuleNamespace>\Model\Logger\Handler\File
Last active April 9, 2019 11:15
Add custom logger in Magento 2
namespace <ModuleNamespace>\Model\Logger\Handler;
use Magento\Framework\Logger\Handler\Base;
use Monolog\Logger;
class ExceptionFile extends Base
{
protected $fileName = 'var/log/my.log';
protected $loggerType = Logger::CRITICAL;
@mikhailovv
mikhailovv / bash.sh
Created October 30, 2018 10:31
Terminator Docker resolve cols problem
docker exec -it php bash -c "stty cols $COLUMNS rows $LINES && bash";
@mikhailovv
mikhailovv / InstallData.php
Created August 16, 2018 08:30
Magento 2 category attributes boolean\text\select
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
/** Boolean attribute */
$eavSetup->addAttribute(Category::ENTITY, 'have_engine',
[
'type' => 'int',
'label' => 'Have engine',
'input' => 'boolean',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'visible' => true,
$ brew install [email protected]
$ brew install [email protected]
$ brew install [email protected]
$ brew install [email protected]
/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
@mikhailovv
mikhailovv / main.php
Created July 12, 2018 09:59
Create foreign key
$installer->getConnection()->getTable('<TableName>')
->addForeignKey(
$installer->getFkName('<ChildTable>', 'entity_id', '<ParentTable>', 'entity_id'),
'entity_id',
$installer->getTable('<ParentTable>'),
'entity_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)
@mikhailovv
mikhailovv / YOU_DOMEN_DataProvider
Created July 12, 2018 08:47
Filter data in grid
class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider
{
public function getData()
{
$typeId = intval($this->request->getParam({field_name_for_filter}), 10);
if ($typeId){
$filter = new \Magento\Framework\Api\Filter();
$filter->setField({field_name_for_filter_in_database})->setValue($typeId)->setConditionType('eq');
$this->addFilter($filter);
@mikhailovv
mikhailovv / gist:2269b01561beb8603312cab3fad0ae44
Created July 10, 2018 12:44
Autoupdate timestamps fields
ALTER TABLE tablename ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;
ALTER TABLE tablename ADD updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL
@mikhailovv
mikhailovv / check_sql.php
Created May 24, 2018 10:23
Check SQL when binding params
$query = "SELECT * FROM table WHERE name = :name";
$bindParams = [":name" => $value];
$query = str_replace(
array_keys($bindParams),
array_map(function($a){ return '"' . addslashes($a) . '"';}, array_values($bindParams)),
$query
);