protected function bootNicerEvents()
    {
        $class = get_called_class();

        if (isset(static::$eventsBooted[$class])) {
            return;
        }

        $radicals = ['creat', 'sav', 'updat', 'delet', 'retriev'];
        $hooks = ['before' => 'ing', 'after' => 'ed'];

        foreach ($radicals as $radical) {
            foreach ($hooks as $hook => $event) {

                $eventMethod = $radical.$event; // saving / saved
                $method = $hook.ucfirst($radical); // beforeSave / afterSave
                if ($radical != 'fetch') $method .= 'e';

                self::$eventMethod(function ($model) use ($method) {
                    $model->fireEvent('model.'.$method);

                    if ($model->methodExists($method))
                        return $model->$method();
                });
            }
        }

        /*
         * Hook to boot events
         */
        static::registerModelEvent('booted', function ($model) {
            $model->fireEvent('model.afterBoot');
            if ($model->methodExists('afterBoot'))
                return $model->afterBoot();
        });

        static::$eventsBooted[$class] = TRUE;
    }
protected function bootNicerEvents()
    {
        $class = get_called_class();

        if (isset(static::$eventsBooted[$class])) {
            return;
        }

        $radicals = ['creat', 'sav', 'updat', 'delet', 'retriev'];
        $hooks = ['before' => 'ing', 'after' => 'ed'];

        foreach ($radicals as $radical) {
            foreach ($hooks as $hook => $event) {

                $eventMethod = $radical.$event; // saving / saved
                $method = $hook.ucfirst($radical); // beforeSave / afterSave
                if ($radical != 'fetch') $method .= 'e';

                self::$eventMethod(function ($model) use ($method) {
                    $model->fireEvent('model.'.$method);

                    if ($model->methodExists($method))
                        return $model->$method();
                });
            }
        }

        /*
         * Hook to boot events
         */
        static::registerModelEvent('booted', function ($model) {
            $model->fireEvent('model.afterBoot');
            if ($model->methodExists('afterBoot'))
                return $model->afterBoot();
        });

        static::$eventsBooted[$class] = TRUE;
    }
protected function bootNicerEvents ( ) { $ class = get_called_class ( ) ; if ( isset ( static :: $ eventsBooted [ $ class ] ) ) { return ; } $ radicals = [ 'creat' , 'sav' , 'updat' , 'delet' , 'retriev' ] ; $ hooks = [ 'before' => 'ing' , 'after' => 'ed' ] ; foreach ( $ radicals as $ radical ) { foreach ( $ hooks as $ hook => $ event ) { $ eventMethod = $ radical . $ event ; // saving / saved $ method = $ hook . ucfirst ( $ radical ) ; // beforeSave / afterSave if ( $ radical != 'fetch' ) $ method .= 'e' ; self :: $ eventMethod ( function ( $ model ) use ( $ method ) { $ model -> fireEvent ( 'model.' . $ method ) ; if ( $ model -> methodExists ( $ method ) ) return $ model -> $ method ( ) ; } ) ; } } /*
         * Hook to boot events
         */ static :: registerModelEvent ( 'booted' , function ( $ model ) { $ model -> fireEvent ( 'model.afterBoot' ) ; if ( $ model -> methodExists ( 'afterBoot' ) ) return $ model -> afterBoot ( ) ; } ) ; static :: $ eventsBooted [ $ class ] = TRUE ; }
Bind some nicer events to this model, in the format of method overrides.
Bind some nicer events to this model in the format of method overrides .