public function savePolicy($model)
    {
        if ('' == $this->filePath) {
            throw new CasbinException('invalid file path, file path cannot be empty');
        }

        $writeString = '';

        if (isset($model->model['p'])) {
            foreach ($model->model['p'] as $ptype => $ast) {
                foreach ($ast->policy as $rule) {
                    $writeString .= $ptype.', ';
                    $writeString .= Util::arrayToString($rule);
                    $writeString .= PHP_EOL;
                }
            }
        }

        if (isset($model->model['g'])) {
            foreach ($model->model['g'] as $ptype => $ast) {
                foreach ($ast->policy as $rule) {
                    $writeString .= $ptype.', ';
                    $writeString .= Util::arrayToString($rule);
                    $writeString .= PHP_EOL;
                }
            }
        }

        return $this->savePolicyFile(rtrim($writeString, PHP_EOL));
    }
public function savePolicy($model)
    {
        if ('' == $this->filePath) {
            throw new CasbinException('invalid file path, file path cannot be empty');
        }

        $writeString = '';

        if (isset($model->model['p'])) {
            foreach ($model->model['p'] as $ptype => $ast) {
                foreach ($ast->policy as $rule) {
                    $writeString .= $ptype.', ';
                    $writeString .= Util::arrayToString($rule);
                    $writeString .= PHP_EOL;
                }
            }
        }

        if (isset($model->model['g'])) {
            foreach ($model->model['g'] as $ptype => $ast) {
                foreach ($ast->policy as $rule) {
                    $writeString .= $ptype.', ';
                    $writeString .= Util::arrayToString($rule);
                    $writeString .= PHP_EOL;
                }
            }
        }

        return $this->savePolicyFile(rtrim($writeString, PHP_EOL));
    }
public function savePolicy ( $ model ) { if ( '' == $ this -> filePath ) { throw new CasbinException ( 'invalid file path, file path cannot be empty' ) ; } $ writeString = '' ; if ( isset ( $ model -> model [ 'p' ] ) ) { foreach ( $ model -> model [ 'p' ] as $ ptype => $ ast ) { foreach ( $ ast -> policy as $ rule ) { $ writeString .= $ ptype . ', ' ; $ writeString .= Util :: arrayToString ( $ rule ) ; $ writeString .= PHP_EOL ; } } } if ( isset ( $ model -> model [ 'g' ] ) ) { foreach ( $ model -> model [ 'g' ] as $ ptype => $ ast ) { foreach ( $ ast -> policy as $ rule ) { $ writeString .= $ ptype . ', ' ; $ writeString .= Util :: arrayToString ( $ rule ) ; $ writeString .= PHP_EOL ; } } } return $ this -> savePolicyFile ( rtrim ( $ writeString , PHP_EOL ) ) ; }
saves all policy rules to the storage.

@param \Casbin\Model\Model $model

@return bool|int

@throws CasbinException
saves all policy rules to the storage .