casbin/webman Error: Call to a member function getPolicy() on null

sunsgne

Error: Call to a member function getPolicy() on null

截图

截图

截图

1478 1 0
1个回答

Tinywan

casbin_rule 表数据

截图

获取用户的所有角色

use Casbin\WebmanPermission\Permission;
$roles = Permission::getRolesForUser('200022');
var_export($roles);

以上输出

Workerman[start.php] reloading
array (
  0 => 'province',
  1 => 'city',
  2 => 'area',
  3 => 'trainer',
)
  • sunsgne 2022-03-29

    我拉一个新的webman就可以获取了,在老的项目就报Call to a member function getPolicy() on null,在null上调用成员函数getPolicy()

  • Tinywan 2022-03-29

    老的项目是?怎么使用的?用的版本是多少?

  • sunsgne 2022-03-29
    "php": ">=7.4",
    "workerman/webman-framework": "^1.2.1",
    "monolog/monolog": "^2.0",
    "webman/console": "^1.0",
    "illuminate/redis": "^8.0",
    "illuminate/database": "^8.0",
    "illuminate/pagination": "^8.0",
    "illuminate/events": "^8.0",
    "vlucas/phpdotenv": "^5.0",
    "jenssegers/mongodb": "^3.0",
    "tinywan/jwt": "^1.0",
    "doctrine/annotations": "^1.13",
    "webman/think-orm": "^1.0",
    "workerman/validation": "^3.0",
    "guzzlehttp/guzzle": "^7.4",
    "workerman/rabbitmq": "^1.0",
    "alibabacloud/dingtalk": "^1.2",
    "tinywan/captcha": "^0.0.1",
    "casbin/webman-permission": "^1.0"
  • sunsgne 2022-03-29

    "autoload": {
    "psr-4": {
    "": "./",
    "App\": "./app"
    },
    "files": [
    "./support/helpers.php"
    ]
    },

  • sunsgne 2022-03-29

    try {
    $roles = Permission::getRolesForUser('28' );
    // $roles = $this->permission->getRolesForUserInDomain($userType . $userId);

            $roleIds = $this->decryptArray($roles, 'role:');
    
            var_dump($userId);
            $adminRole = AdminRole::query()->whereIn('id' , $roleIds)->get();
    
            return  $adminRole->isNotEmpty() ? $adminRole->toArray() : [];
        }catch (\Exception $exception)
        {
            return [];
    
        }
  • Tinywan 2022-03-29

    老项目不能升级?

  • sunsgne 2022-03-29

    前几天一直能跑,

  • Tinywan 2022-03-29

    你先移除,重新安装试试 composer remove casbin/webman-permission

  • sunsgne 2022-03-29

    版本都是最新的,我感觉没有自动加载

  • Tinywan 2022-03-29

    这一直都没改动过的,都是6天之前发布的1.0,https://github.com/php-casbin/webman-permission/releases/tag/v1.0.0

  • sunsgne 2022-03-29

    最开始是用得tinywan/casbin ,抛出异常后我换了casbin/webman

  • sunsgne 2022-03-29

    依然是这样
    rror: Call to a member function getAllRoles() on null in /var/www/php/fj-dmp/vendor/casbin/webman-permission/src/Permission.php:91\nStack trace:

  • Tinywan 2022-03-29

    我怎么没搜到 casbin/webman 这个插件库

  • Tinywan 2022-03-29

    di有没有安装,看看,我这边尝试了么有问题的

  • sunsgne 2022-03-29

    就是casbin/webman-permission

  • Tinywan 2022-03-29

    依赖信息发一下:composer info

  • sunsgne 2022-03-29
    "php-di/php-di": "^6.3",
  • sunsgne 2022-03-29

    adbario/php-dot-notation 2.2.0 PHP dot notation access to arrays
    alibabacloud/credentials 1.1.4 Alibaba Cloud Credentials for PHP
    alibabacloud/darabonba-openapi 0.2.5 Alibaba Cloud OpenApi Client
    alibabacloud/dingtalk 1.3.25 Alibaba Cloud Dingtalk SDK Library for PHP
    alibabacloud/endpoint-util 0.1.1 Alibaba Cloud Endpoint Library for PHP
    alibabacloud/gateway-spi 0.0.1 Alibaba Cloud Gateway SPI Client
    alibabacloud/openapi-util 0.1.11 Alibaba Cloud OpenApi Util
    alibabacloud/tea 3.1.23 Client of Tea for PHP
    alibabacloud/tea-utils 0.2.15 Alibaba Cloud Tea Utils for PHP
    bunny/bunny v0.5.1 Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library
    casbin/casbin v3.20.3 a powerful and efficient open-source access control library for php projects.
    casbin/webman-permission v1.0.0 webman casbin permission Plugin
    doctrine/annotations 1.13.2 Docblock Annotations Parser
    doctrine/inflector 2.0.4 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
    doctrine/lexer 1.2.3 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
    firebase/php-jwt v6.1.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
    graham-campbell/result-type v1.0.4 An Implementation Of The Result Type
    guzzlehttp/guzzle 7.4.2 Guzzle is a PHP HTTP client library
    guzzlehttp/promises 1.5.1 Guzzle promises library
    guzzlehttp/psr7 2.2.1 PSR-7 message implementation that also provides common utility methods
    illuminate/bus v8.83.5 The Illuminate Bus package.
    illuminate/collections v8.83.5 The Illuminate Collections package.
    illuminate/container v8.83.5 The Illuminate Container package.
    illuminate/contracts v8.83.5 The Illuminate Contracts package.
    illuminate/database v8.83.5 The Illuminate Database package.
    illuminate/events v8.83.5 The Illuminate Events package.
    illuminate/macroable v8.83.5 The Illuminate Macroable package.
    illuminate/pagination v8.83.5 The Illuminate Pagination package.
    illuminate/pipeline v8.83.5 The Illuminate Pipeline package.
    illuminate/redis v8.83.5 The Illuminate Redis package.
    illuminate/support v8.83.5 The Illuminate Support package.
    jean85/pretty-package-versions 2.0.5 A library to get pretty versions strings of installed dependencies
    jenssegers/mongodb 3.8.4 A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
    lizhichao/one-sm 1.10 国密sm3
    mongodb/mongodb 1.11.0 MongoDB driver library
    monolog/monolog 2.4.0 Sends your logs to files, sockets, inboxes, databases and various web services
    nesbot/carbon 2.57.0 An API extension for DateTime that supports 281 different languages.
    nikic/fast-route v1.3.0 Fast request router for PHP
    opis/closure 3.6.3 A library that can be used to serialize closures (anonymous functions) and arbitrary objects.
    php-di/invoker 2.3.3 Generic and extensible callable invoker
    php-di/php-di 6.3.5 The dependency injection container for humans
    php-di/phpdoc-reader 2.2.1 PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)
    phpoption/phpoption 1.8.1 Option Type for PHP
    psr/cache 1.0.1 Common interface for caching libraries
    psr/container 1.1.2 Common Container Interface (PHP FIG PSR-11)
    psr/http-client 1.0.1 Common interface for HTTP clients
    symfony/translation v5.4.6 Provides tools to internationalize your application
    symfony/translation-contracts v2.5.0 Generic abstractions related to translation
    symfony/var-exporter v5.4.6 Allows exporting any serializable PHP data structure to plain PHP code
    tinywan/captcha v0.0.1
    tinywan/jwt v1.2.2 JSON Web Token (JWT) for webman plugin
    topthink/think-helper v3.1.6 The ThinkPHP6 Helper Package
    topthink/think-orm v2.0.53 think orm
    vlucas/phpdotenv v5.4.1 Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.
    voku/portable-ascii 1.6.1 Portable ASCII library - performance optimized (ascii) string functions for php.
    webman/console v1.0.24 Webman console
    webman/think-orm v1.0.1
    workerman/rabbitmq v1.0.3 Asynchronous rabbitmq client for PHP based on workerman.
    workerman/redis v1.0.7
    workerman/validation v3.0.1 The most awesome validation engine ever created for PHP. Respect/Validation 汉化版本
    workerman/webman-framework v1.3.6 High performance HTTP Service Framework.
    workerman/workerman v4.0.31 An asynchronous event driven PHP framework for easily building fast, scalable network applications.

  • Tinywan 2022-03-29

    DI都配置了?

    configure config/container.php,Its final content is as follows:

    $builder = new \DI\ContainerBuilder();
    $builder->addDefinitions(config('dependence', []));
    $builder->useAutowiring(true);
    return $builder->build();
  • sunsgne 2022-03-29

    还有就是比如编辑了var_dump代码 webman的reloading后没有去var_dump,要重启才可以

  • sunsgne 2022-03-29

    配了

  • sunsgne 2022-03-29

    use DI\ContainerBuilder;

    $builder = new ContainerBuilder();
    $builder->addDefinitions(config('dependence', []));
    $builder->useAutowiring(true);
    $builder->useAnnotations(true);
    return $builder->build();

  • Tinywan 2022-03-29

    好像是你的webman代码不合适造成的

  • sunsgne 2022-03-29

    嗯,另外拉新的webman就没有问题

  • Tinywan 2022-03-29

    我这边由于没有低版本的webman版本,也不好给你测试,哈哈!随便问一下 https://www.workerman.net/a/1313 这个是分享的是吧!有没有测试通过?

  • sunsgne 2022-03-29

    周末在本地跑没问题。

  • sunsgne 2022-03-29

    我是抄的

  • Tinywan 2022-03-29

    很好!我等会发布到dev-main你帮我测试一下,我没用过 Laravel 的数据,可以的话就可以兼容ThinkORM和Laravel了

  • sunsgne 2022-03-29

    ok

  • Tinywan 2022-03-29

    发你QQ了

年代过于久远,无法发表回答
×
🔝