PHP code example of hudsxn / ioc-core

1. Go to this page and download the library: Download hudsxn/ioc-core 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/ */

    

hudsxn / ioc-core example snippets




    se Hudsxn\IocCore\Application;
    //                     fileDir, runType, beforeRequest
    $app = new Application("src", "web", function() {
        
        /**
         * @var \Hudsxn\IocCore\AppRouter
         */
        $router = $this->getApplicationRouter();

        $router->setNoRouteAction(function(string $method, string $path) {
            // do this when not found, you can use this to fallback on frontend apps.
        });

    }); 



    se Hudsxn\IocCore\Application;
    //                     fileDir, runType, beforeRun
    $app = new Application("src", "cli", function() {
        
    }, $argv); 

    

        namespace App\MyProject;

        use Hudsxn\IocCore\Attribute\ListenFor;

        class ProjectEvents
        {
            #[ListenFor('BeforeCreate', Project::class)]
            public function beforeCreate(Project $entity): Project 
            {
                // example.
                $entity->UserId = $this->getUserId();
            }

            #[ListenFor('BeforeUpdate', Project::class)]
            public function beforeUpdate(Project $mutated, Project $existing): Project
            {
                if ($existing->UserId == $mutated->UserId) {
                    return $mutated;
                }
                throw new Exception("Not your object");
            }

        }
  
cmd
    php cli.php @build/entity --className=App\Users\User
  
cmd
    # --sourceType either 'ts' or 'js'
    php cli.php @build/generate-types --sourceType=ts --outputDir=frontend/api"