Skip to content

Instantly share code, notes, and snippets.

View MaximStrutinskiy's full-sized avatar
✍️
Open to new offers.

Maxim Strutinskiy MaximStrutinskiy

✍️
Open to new offers.
View GitHub Profile
@MaximStrutinskiy
MaximStrutinskiy / BulkInsert.php
Last active October 10, 2017 12:31
Doctrine Bulk Inserts
<?php
foreach ($nominals as $nominal) {
for ($i = 1; $i <= $nominal['code_count']; $i++) {
$code = new Code();
$code->setShop($shop);
$code->setCode($this->GenerateData($codeLength, $codeType, $codePrefix));
$code->setPincode($this->GenerateData($pincodeLength, $pincodeType));
$code->setCodeLiveCikle($codeLiveCikle);
$code->setMinDateActivity($minDateActivity);
<?php
namespace DesignPatterns\Creational\AbstractFactory;
/**
* In this case, the abstract factory is a contract for creating some components
* for the web. There are two ways of rendering text: HTML and JSON
*/
abstract class AbstractFactory
{
<?php
namespace DesignPatterns\Structural\DependencyInjection;
class DatabaseConfiguration
{
/**
* @var string
*/
private $host;
<?php
namespace App\Command;
use App\Entity\User;
use Knp\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@MaximStrutinskiy
MaximStrutinskiy / Controller
Last active September 19, 2017 05:59
Event Dispatcher.
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$shipment = new Shipment();
$form = $this->createFormBuilder($shipment)
->add('name', TextType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@MaximStrutinskiy
MaximStrutinskiy / Call dispatch
Created September 18, 2017 17:10
Event Subscribers in Silex
public function createNewContributionAction(Request $request, int $userReviewId, int $review_id)
{
$user = $this->getApp()['user'];
$userReview = $this->getRepository(UserReview::class)->findBy(['id' => $userReviewId]);
$userReview = $userReview[0];
$form = $this->getFormFactory()->createBuilder(CreateContributionType::class)->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
if (isset($_POST['save'])) {
$data = $form->getData();
$app->register(new Silex\Provider\SecurityServiceProvider(),
[
$app['security.firewalls'] = [
'secured' => [
'pattern' => '^/',
'anonymous' => true,
'form' => [
'login_path' => '/login',
'check_path' => '/admin/login_check',
],
@MaximStrutinskiy
MaximStrutinskiy / Use in controller
Created September 17, 2017 15:39
Example usage voters in symfony.
$this->denyAccessUnlessGranted('edit_comment', $comment);
@MaximStrutinskiy
MaximStrutinskiy / CustomLength
Last active September 17, 2017 15:33
Custom symfony constraint.
<?php
namespace MainBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/** @Annotation */
class CustomLength extends Constraint
{
// Define all annotation parameters;
<VirtualHost *:80>
ServerName giftshere
DocumentRoot /home/maximstrutinskiy/Sites/giftshere/web
<Directory /home/maximstrutinskiy/Sites/giftshere/web>
AllowOverride None
Require all granted
Allow from All
</Directory>
ErrorLog /home/maximstrutinskiy/Sites/giftshere-log/error.log
CustomLog /home/maximstrutinskiy/Sites/giftshere-log/access.log combined