PHP code example of tfhinc / ci-newton

1. Go to this page and download the library: Download tfhinc/ci-newton library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tfhinc / ci-newton example snippets




namespace Listeners;

/**
 * UpdateUserStatsListener
 *
 * Update the User stats with the new User data.
 *
 */
class UpdateUserStatsListener extends TFHInc/Newton/NewtonListener {
    /**
     * Run the listener.
     *
     * @return  void
     */
    public function run($event): void
    {
        // Update the User Stats.
    }
}

newton()->subscribe('Events\UserCreatedEvent', [
    'Listeners\SendAdminEmailListener',
    'Listeners\UpdateUserStatsListener'
]);
 php
$this->load->helper('newton');
 php
$newton = new TFHInc/Newton/Newton();
 php
$this->load->library('Newton');
 php

defined('BASEPATH') OR exit('No direct script access allowed');

namespace Events;

/**
 * UserCreatedEvent
 *
 * A new User has been created. Yay, new user!
 *
 */
class UserCreatedEvent {
    /**
     * @var string
     */
    public $email;

    /**
     * @var string
     */
    public $first_name;

    /**
     * @var string
     */
    public $last_name;

    /**
     * Construct the event.
     *
     * @param   string   $email
     * @param   string   $first_name
     * @param   string   $last_name
     * @return  UserCreatedEvent
     */
    public function __construct(string $email, string $first_name, string $last_name)
    {
        $this->email = $email;
        $this->first_name = $first_name;
        $this->last_name = $last_name;
    }
}
 php
$config['subscriptions'] = [
    'Events\UserCreatedEvent' => [
        'Listeners\SendAdminEmailListener',
        'Listeners\UpdateUserStatsListener'
    ]
];