Skip to content

Instantly share code, notes, and snippets.

View cod3beat's full-sized avatar

A. Akbar Hidayat cod3beat

View GitHub Profile
@cod3beat
cod3beat / NewsFeedServiceProvider.php
Created November 18, 2015 07:15
News Feed Service Provider
<?php
class NewsFeedServiceProvider extends ServiceProvider
{
public function register()
{
// Ketika seluruh event dari Domain Challenge dibangkitkan, maka kita jalankan ChallengeFeedListener
// untuk menangani event tersebut.
\Event::listen('Dicoding.Domain.Challenge.*', 'Dicoding\Infrastructure\Feeds\Challenges\ChallengeFeedListener');
}
@cod3beat
cod3beat / EventMailerServiceProvider.php
Created November 18, 2015 07:09
Event Mailer Service Provider
<?php
class EventMailerServiceProvider extends ServiceProvider
{
public function register()
{
// Ketika seluruh event dari Domain Challenge dibangkitkan, maka kita jalankan ChallengeEventMailer
// untuk menangani event tersebut.
\Event::listen('Dicoding.Domain.Challenge.*', 'Dicoding\Infrastructure\Emailing\Challenge\ChallengeEventMailer');
}
@cod3beat
cod3beat / ChallengePublicationContext.php
Last active November 18, 2015 07:01
Contoh Mempublikasikan sebuah unpublished challenge
<?php
class ChallengePublicationContext
{
public function publishUnpublishedChallenge($challengeId)
{
// Jalankan logika bisnis yang berhubungan dengan
// proses mempublikasikan unpublised challenge
// Bila sukses, maka kita tambahkan Challenge ini ke
@cod3beat
cod3beat / PublishUnpublishedChallengeHandler.php
Created November 18, 2015 06:52
PublishUnpublishedChallengeHandler.php tanpa tugas sekunder
<?php
class PublishUnpublishedChallengeHandler
{
public function handle(PublishUnpublishedChallenge $command)
{
try {
DB::beginTransaction();
$publishedChallenge = $this->challengePublicationContext->publishUnpublishedChallenge($command->challenge_id);
@cod3beat
cod3beat / PublishUnpublishedChallengeHandler.php
Created November 18, 2015 06:38
Publishing Unpublished Challenge
<?php
class PublishUnpublishedChallengeHandler
{
public function handle(PublishUnpublishedChallenge $command)
{
try {
DB::beginTransaction();
@cod3beat
cod3beat / CreateUnpublishedChallengeHandler.php
Last active November 17, 2015 08:07
Create Unpublished Challenge Command Handler
<?php
use Dicoding\ApplicationService\Challenges;
class CreateUnpublishedChallengeHandler
{
public function handle(CreateUnpublishedChallenge $command)
{
try {
@cod3beat
cod3beat / RegistrationExample.php
Created November 17, 2015 08:00
Register Developer
<?php
class EmailMembershipController
{
public function store()
{
try {
$this->execute(RegisterDeveloper::class);
@cod3beat
cod3beat / DailyTaskNotifier.php
Created November 17, 2015 07:17
Menjalankan Command di luar controller
<?php
use Dicoding\ApplicationService\Administration\NotifyPendingTaskCommand;
use Illuminate\Console\Command;
class DailyTaskNotifier extends Command
{
// code lain disembunyikan agar contoh ini menjadi lebih ringkas
public function fire()
@cod3beat
cod3beat / ChallengeController.php
Last active November 17, 2015 07:11
SimpleBus
<?php
class ChallengeController
{
public function store()
{
try {
$this->commandBus()->handle(new CreateUnpublishedChallenge(
'Nama',
@cod3beat
cod3beat / ChallengeController.php
Created November 17, 2015 07:05
Excecuting Create Unpublished Command
<?php
class ChallengeController
{
public function store()
{
try {
// Mengeksekusi Command
$this->execute(CreateUnpublishedChallenge::class);