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
// if form is mapped => false;
$img = $form->get('img')->getData();
//if form is mapped => true
$img = $user->getImg();
if ($img !== NULL) {
// Generate a unique name for the file before saving it
$fileName = md5(uniqid()) . '.' . $img->getExtension();
//Get password for mapped => false
$pass = $this->getForm()->get('password')->getData();
//Get password for mapped => true
$pass = $this->getForm()->get('password')->getData();
$pass = $this->getForm()->get('password')->getData();
if ($pass !== null) {
$object->setPlainPassword($pass);
}
<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
@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;
@MaximStrutinskiy
MaximStrutinskiy / Use in controller
Created September 17, 2017 15:39
Example usage voters in symfony.
$this->denyAccessUnlessGranted('edit_comment', $comment);
$app->register(new Silex\Provider\SecurityServiceProvider(),
[
$app['security.firewalls'] = [
'secured' => [
'pattern' => '^/',
'anonymous' => true,
'form' => [
'login_path' => '/login',
'check_path' => '/admin/login_check',
],
@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();
@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()) {
<?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;
<?php
namespace DesignPatterns\Structural\DependencyInjection;
class DatabaseConfiguration
{
/**
* @var string
*/
private $host;