Skip to content

Instantly share code, notes, and snippets.

@nuryagdym
nuryagdym / .env
Last active January 15, 2024 09:16
api-platform v3 - Create a service for Bramble GraphQl Federation Support
# if you have TRUSTED_HOSTS config in your environments,
# add host.docker.internal into it so that local development with docker works
TRUSTED_HOSTS=^(localhost|php|host.docker.internal)$
@nuryagdym
nuryagdym / app.php
Created September 8, 2021 06:26
Laravel Lumen v5.4 Monolog Logger (Graylog Gelf logger) integration
<?php
//bootstrap/app.php:
//...
$app->configureMonologUsing(function ($monolog) use ($app) {
$publisher = new \Gelf\Publisher(new \Gelf\Transport\HttpTransport(env('GRAYLOG_HOST'), env('GRAYLOG_PORT'), env('GRAYLOG_PATH')));
$failureHandler = new \Monolog\Handler\WhatFailureGroupHandler([new \Monolog\Handler\GelfHandler($publisher)]);
$monolog->pushHandler($failureHandler);
@nuryagdym
nuryagdym / Address.php
Last active June 20, 2021 09:17
How to use Symfony Serializer Component to Normalize Phalcon PHP models
<?php
namespace App\Model;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
/**
* @IgnoreAnnotation("Primary")
* @IgnoreAnnotation("Identity")
@nuryagdym
nuryagdym / query-string-builder.ts
Last active January 29, 2021 12:41
Angular JSON object to query string
import {HttpParams} from "@angular/common/http";
export class QueryStringBuilder {
static buildParametersFromSearch<T>(obj: T): HttpParams {
let params: HttpParams= new HttpParams();
if (obj == null)
{
return params;
@nuryagdym
nuryagdym / register.html.twig
Last active August 14, 2020 06:42 — forked from ThePeterMick/register.html.twig
Symfony 4 bootstrap 4 check box form label with link
{% form_theme form _self %}
{% block checkbox_radio_label -%}
{# {% block _user_registration_form_termsAccepted_label %} - use this if you need it for just a single field, amend accordingly to your form type/field #}
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
{%- if widget is defined -%}
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %}
{% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class) %}
{%- if is_parent_custom or is_custom -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
@nuryagdym
nuryagdym / LoginSubcriber.php
Last active November 2, 2021 15:02
Symfony 4.4 google captcha integration to login form using KarserRecaptcha3Bundle
<?php
namespace App\EventSubscriber;
use App\Form\LoginType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
@nuryagdym
nuryagdym / Version20200508000000.php
Created July 20, 2020 11:05
Doctrine 2.x "Unknown database type enum, MySQL57Platform may not support it" fix
<?php
/**
* Symfony 4.4 migration file.
* add this file to src/migrations/ directory.
* github issue: https://github.com/doctrine/dbal/issues/3161
*/
declare(strict_types=1);
namespace DoctrineMigrations;
@nuryagdym
nuryagdym / my_bootstrap_4_layout.html.twig
Created July 2, 2020 14:04
Symfony Form Builder Bootstrap 4 input-group Append and Prepend
{% use "bootstrap_4_layout.html.twig" %}
{# extend form_widget_simple #}
{% block form_widget_simple -%}
{%- if (prepend is defined) or (append is defined) -%}
<div class="input-group{{ group_class|default('') }}">
{%- if prepend is defined -%}
<div class="input-group-prepend">
{{ prepend|raw }} {# without raw filter the html code will be escaped #}
</div>
@nuryagdym
nuryagdym / times.js
Last active June 12, 2021 06:37
Javascript Türkçe zaman birimleri
const translations = {
monthsFull: ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
monthsShort: ['Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Eki', 'Kas', 'Ara'],
//first day is Monday
weekdaysFull: ['Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi', 'Pazar'],
weekdaysShort: ['Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cmt', 'Paz'],
today: 'Bugün',
tomorrow: 'Yarın',
yesterday: 'Dün',
hour: 'saat',
@nuryagdym
nuryagdym / RolesType.php
Last active May 9, 2020 17:37 — forked from Glideh/RolesType.php
This is an example of how one could create a custom type for roles to add in a User form (Symfony v4.3 >)
<?php
namespace AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Role\RoleHierarchy;