Welcome Guest, Not a member yet? Register   Sign In
Config/Services getSharedInstance returns an empty array
#3

we have these layers controller service entity model migrtation seeder

for  problem  use config not service 

use service like that

PHP Code:
<?php namespace Modules\Auth\Config;


use 
CodeIgniter\HTTP\UserAgent;
use 
Config\App;
use 
Config\Services as AppServices;
use 
Config\Services as BaseService;
use 
Modules\Auth\Libraries\RequestWithUser;
use 
Modules\Auth\Services\AuthService;
use 
Modules\Auth\Services\GroupsPermissionService;
use 
Modules\Auth\Services\PermissionService;
use 
Modules\Auth\Services\RoleRouteService;
use 
Modules\Auth\Services\GroupService;
use 
Modules\Auth\Services\UsersPermissionService;

class 
Services extends BaseService
{
    //--------------------------------------------------------------------

    /**
    * The Request class models an HTTP request.
    *
    * @param App|null $config
    * @param boolean $getShared
    *
    * @return RequestWithUser
    */
    public static function requestWithUser(App $config nullbool $getShared true)
    {
        if ($getShared) {
            return static::getSharedInstance('requestWithUser'$config);
        }

        $config $config ?? config('App');;
        return new RequestWithUser(
            $config,
            AppServices::uri(),
            'php://input',
            new UserAgent()
        );
    }

    //--------------------------------------------------------------------


    public static function roleRoute($getShared true)
    {
        if ($getShared) {
            return static::getSharedInstance('roleRoute');
        }

        return new RoleRouteService();
    }
//--------------------------------------------------------------------

    public static function authService($getShared false)
    {
        if (!$getShared) {
            return new AuthService();
        }
        return static::getSharedInstance('authService');

    }
//--------------------------------------------------------------------

    public static function groupService($getShared false)
    {
        if (!$getShared) {


            return new GroupService();
        }

        return static::getSharedInstance('groupService');
    }
//--------------------------------------------------------------------

    public static function permissionService($getShared false)
    {
        if (!$getShared) {


            return new PermissionService();
        }

        return static::getSharedInstance('permissionService');
    }
//--------------------------------------------------------------------

    public static function groupsPermissionService($getShared false)
    {
        if (!$getShared) {


            return new GroupsPermissionService();
        }

        return static::getSharedInstance('groupsPermissionService');
    }
//--------------------------------------------------------------------

    public static function userPermissionService($getShared false)
    {
        if (!$getShared) {


            return new UsersPermissionService();
        }

        return static::getSharedInstance('usersPermissionService');
    }

//--------------------------------------------------------------------





PHP Code:
<?php namespace Modules\Auth\Controllers;


use 
Modules\Auth\Config\Services;
use 
Modules\Auth\Entities\GroupEntity;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Modules\Shared\Controllers\ApiController;

class  Group extends ApiController
{
    /**
    * index function
    * @method : GET
    */
    public function index()
    {


        $groupEntity = new GroupEntity();

        $this->urlQueryParam->dataMap($groupEntity->getDataMap());


        $groupService Services::groupService();
        $findAllData $groupService->index($this->urlQueryParam);

        return $this->respond([
            'data' => $findAllData['data'],
            'pager' => $findAllData['pager']
        ], ResponseInterface::HTTP_OKlang('Shared.api.receive'));


    }

    /**
    * show function
    * @method : GET with params ID
    */
    public function show($id null)
    {
        $groupService Services::groupService();
        $findOneData $groupService->show($id);

        return $this->respond([
            'data' => $findOneData['data'],
            'pager' => $findOneData['pager']
        ], ResponseInterface::HTTP_OKlang('Shared.api.receive'));


    }

    public function create()
    {


        $rules = [
            'name' => 'required|min_length[3]|max_length[255]|is_unique[auth_groups.name]',
            'description' => 'required|min_length[3]|max_length[255]',
        ];

        if (!$this->validate($rules)) {

            return $this->respond([
                'error' => $this->validator->getErrors(),
                
            
], ResponseInterface::HTTP_NOT_ACCEPTABLElang('Shared.api.validation'));

        }


        $groupEntity = new GroupEntity((array)$this->request->getVar());

        $groupService Services::groupService();
        $groupService->create($groupEntity);


        return $this->respond([
            'data' => ''
        ], ResponseInterface::HTTP_CREATEDlang('Shared.api.save'));


    }

    /**
    * update function
    * @method : PUT or PATCH
    */
    public function update($id null)
    {


        //get request from Vue Js

        //get request from Vue Js
        $json $this->request->getJSON();
        if (!isset($id)) {
            $id $json->id;
        }


        $rules = [
            'name' => 'if_exist|required|min_length[3]|max_length[255]',
            'description' => 'required|min_length[3]|max_length[255]',
        ];

        if (!$this->validate($rules)) {
            return $this->respond([
                'error' => $this->validator->getErrors(),
                
            
], ResponseInterface::HTTP_NOT_ACCEPTABLElang('Shared.api.validation'));

        }


        $groupEntity = new GroupEntity((array)$this->request->getVar());

        $groupService Services::groupService();
        $groupService->update($id$groupEntity);


        return $this->respond([
        ], ResponseInterface::HTTP_OKlang('Shared.api.update'));


    }

    /**
    * edit function
    * @method : DELETE with params ID
    */
    public function delete($id null)
    {

        $groupService Services::groupService();
        $groupService->delete($id);


        return $this->respond([
        ], ResponseInterface::HTTP_OKlang('Shared.api.remove'));


    }



Enlightenment  Is  Freedom
Reply


Messages In This Thread
RE: Config/Services getSharedInstance returns an empty array - by paliz - 10-15-2021, 05:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB