Skip to content

Instantly share code, notes, and snippets.

View J7mbo's full-sized avatar
🔨
Working with distributed systems

James Mallison J7mbo

🔨
Working with distributed systems
View GitHub Profile
@J7mbo
J7mbo / php-symfony-controllers-as-services-blog-5.php
Created May 31, 2020 14:23
php-symfony-controllers-as-services-blog-5.php
protected function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ControllersAsServices, PassConfig::TYPE_BEFORE_OPTIMIZATION, -1);
parent::build($container);
}
@J7mbo
J7mbo / php-symfony-controllers-as-services-blog-4.php
Created May 31, 2020 14:22
php-symfony-controllers-as-services-blog-4.php
<?php
namespace App;
use Symfony\Component\DependencyInjection\{Compiler\CompilerPassInterface, ContainerBuilder};
class ControllersAsServices implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
@J7mbo
J7mbo / php-symfony-controllers-as-services-blog-3.yaml
Created May 31, 2020 14:14
php-symfony-controllers-as-services-blog-3.yaml
#config/services.yaml
services:
_instanceof:
App\Contract\ControllerInterface:
tags: ['controller.service_arguments']
@J7mbo
J7mbo / php-symfony-controllers-as-services-blog-2.php
Created May 31, 2020 14:12
php-symfony-controllers-as-services-blog-2.php
// Found some configuration with "controller.service_arguments" in its tags...
foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
// Do all the rest of the dependency injection stuff...
}
@J7mbo
J7mbo / php-symfony-controllers-as-services-blog-1.yaml
Created May 31, 2020 13:58
php-symfony-controllers-as-services-blog-1.yaml
App\SomeOtherDirectory\Controller:
resource: '../src/SomeOtherDirectory/Controller'
tags: ['controller.service_arguments']

Keybase proof

I hereby claim:

  • I am j7mbo on github.
  • I am j7mbo (https://keybase.io/j7mbo) on keybase.
  • I have a public key ASDbtkEn9HZOO_qCjM4QyDf0M0xl6ykUUXMoA4-U8XTXngo

To claim this, I am signing this object:

// Service Package
type Service interface {
CountNumUsers() int
}
type service struct {
Repository *UserRepository
}
func (s service) CountNumUsers() int {
return s.Repository.Count()
}
type Service struct {
Repository *UserRepository
}
func (s *Service) CountNumUsers() int {
if s == nil || s.Repository == nil {
return 0
}
return s.Repository.Count()
}
type Service struct {
Repository *UserRepository
}
func (s Service) CountNumUsers() int {
return s.Repository.Count()
}
s := Service{}
s.CountNumUsers() // SIGSEGV nil pointer
@J7mbo
J7mbo / understanding-goroutines.go
Created August 30, 2019 10:12
Goroute, single running, cancellable, running on an interval
func main() {
manager := make(chan struct{})
_ = publisher(manager)
time.Sleep(10 * time.Second)
close(manager)
}
func publisher(manager chan struct{}) chan<- struct{} {
pubch := make(chan struct{})