Skip to content

Instantly share code, notes, and snippets.

View NemanyaM's full-sized avatar

Nemanja Milosavljevic NemanyaM

View GitHub Profile
@NemanyaM
NemanyaM / Laravel-Container.md
Created October 13, 2017 07:40
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

Accessing the Container

@NemanyaM
NemanyaM / FizzBuzz.php
Created December 14, 2016 08:58
FizzBuzz solution in PHP
for ($i = 1; $i <= 100; $i++)
{
if($i % 3 == 0 && $i % 5 ==0){
echo "FizzBuzz<br />";
}
else if($i % 3 == 0){
echo "Fizz<br />";
}
else if($i % 5 == 0){
echo "Buzz<br />";
<?php
class Collection implements IteratorAggregate
{
/**
* The collection contents.
*
* @var array
*/
protected $items;
@NemanyaM
NemanyaM / artisan.php
Created September 1, 2016 09:53 — forked from vkbansal/artisan.php
Tying to use artisan migrate commands outside laravel
<?php
require_once "vendor/autoload.php";
use Symfony\Component\Console\Application;
use Illuminate\Database\Console\Migrations;
use Pimple\Container;
$container = new Container();
$container['migration-table'] = 'migration';