Skip to content

Instantly share code, notes, and snippets.

View popovserhii's full-sized avatar

Serhii Popov popovserhii

View GitHub Profile
@popovserhii
popovserhii / GridApplyOnlyFilters.php
Last active July 10, 2024 21:20
Apply filters to DataSource of Datagrid
<?php
use ZfcDatagrid\Library\FilterHelper;
use Popov\DatagridBundle\Renderer\Json\Renderer;
$this->abstractFactory->setDataSource(...func_get_args());
$filterColumn = $this->abstractFactory->getFilterColumn();
$retriever = $this->abstractFactory->getRetriever();
@popovserhii
popovserhii / Entity.php
Last active April 6, 2023 22:09
Doctrine add "ON UPDATE CURRENT_TIMESTAMP" and default value
<?php
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @var DateTime
*
* @Gedmo\Timestampable(on="create")
@popovserhii
popovserhii / pre-commit.sh
Created September 30, 2021 11:13
PHP ECS (Easy Coding standard) git pre commit hook
#!/usr/bin/env bash
echo "PHP-ECS pre commit hook start"
PASS=true
PHP_ECS="bin/ecs"
HAS_PHP_ECS=false
if [ -x $PHP_ECS ]; then
HAS_PHP_ECS=true
@popovserhii
popovserhii / strpos.php
Last active September 15, 2021 11:29
Custom implementation of PHP strpos function
<?php
# Live Codding https://codeshare.io/
# Task
Find the position of the first occurrence of a substring in a string
strpos ( string $haystack , string $needle [, int $offset = 0 ] ) : int | false
fucntion strpos(string $haystack, string $needle, int $offset = 0): int|false
@popovserhii
popovserhii / ecs-converter.php
Last active September 30, 2021 11:17
Convert PHP-CS-Fixer rules to ECS rules
<?php
require_once 'vendor/autoload.php';
function varExport($expression, $return = false)
{
$export = var_export($expression, true);
$export = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $export);
$array = preg_split("/\r\n|\n|\r/", $export);
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [null, ']$1', ' => ['], $array);
@popovserhii
popovserhii / pre-commit
Created June 22, 2020 13:33
PHP Code Sniffer: git pre commit hook
#!/bin/bash
# .git-hook/pre-commit
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.php')
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
@popovserhii
popovserhii / override.php
Last active October 4, 2018 12:53
ZF3 Override ServiceManager Config
protected function overrideServiceManagerConfig(ServiceManager $sm, array $appendConfig)
{
$globalConfig = $sm->get('Config');
$allConfig = \Zend\Stdlib\ArrayUtils::merge($globalConfig, $appendConfig);
// set Config service, service manager can't operate without it
$sm->setAllowOverride(true);
$sm->setService('Config', $allConfig);
$sm->setAllowOverride(false);
}
@popovserhii
popovserhii / Bootstrap.php
Last active March 27, 2020 10:59
ZF3 PHPUnit Bootstrap
<?php
namespace StagemTest\Order;
use Psr\Container\ContainerInterface;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ArrayUtils;
/**
* Test bootstrap, for setting up autoloading
@popovserhii
popovserhii / cli-config.php
Last active June 5, 2019 05:11
Integrating Doctrine 2 ORM and Migrations into Zend Expressive
<?php
/**
* config/cli-config.php
* For more details @see \DoctrineORMModule\Module
*
* Run next commands for Migrations work
* $ composer require doctrine/doctrine-orm-module
* $ composer require doctrine/migrations
*/
$container = require 'container.php';
@popovserhii
popovserhii / install_phpexcel_php7.sh
Last active June 8, 2018 06:23 — forked from belgattitude/install_phpexcel_php7.sh
Install libxl, php_excel extension on PHP7 (main interpretator) on CentOS7 (ondrej/ppa)
#!/bin/bash
#
# ilia/php_excel extension example install script for PHP7+ on CentOS 7+ as base interpreatator
#
# usage:
# > ./install_phpexcel_php7.sh
# > (optionally) sudo service php7.0-fpm restart)
#
# requirements:
# - Ubuntu 64bits (trusty/xenial)