<commit_before><?php namespace Permit\CurrentUser;

use Permit\User\UserInterface;
use Permit\User\GenericUser;

use BadMethodCallException;

class SystemDetector{
    public function isSystem(){
        return (php_sapi_name() == 'cli');
    }
}

class FallbackContainer implements ContainerInterface{

    protected $_guestUser;

    protected $_systemUser;

    protected $systemDetector;

    /**
     * @brief Retrieve the current user.
     *
     * @return Permit\User\UserInterface
     **/
    public function user(){

        if($this->isConsole()){
            return $this->getSystem();
        }
        return $this->getGuest();
    }

    protected function isConsole(){
        return $this->getSystemDetector()->isSystem();
    }

    protected function getSystemDetector(){
        if(!$this->systemDetector){
            $this->systemDetector = new SystemDetector();
        }
        return $this->systemDetector;
    }

    protected function setSystemDetector(SystemDetector $detector){
        $this->systemDetector = $detector;
    }

    public function getGuest(){

        if(!$this->_guestUser){
            $this->_guestUser = new GenericUser();
            $this->_guestUser->setAuthId('guest');
            $this->_guestUser->setIsGuest(true);
        }

        return $this->_guestUser;

    }

    public function getSystem(){

        if(!$this->_systemUser){
            $this->_systemUser = new GenericUser();
            $this->_systemUser->setAuthId('system');
            $this->_systemUser->setIsSystem(true);
        }

        return $this->_systemUser;

    }

    /**
     * @brief Set the current user. If a user should be logged in as a
     *        different user you shoul simply set a user a second time
     *
     * @param Permit\User\UserInterface $user
     * @param bool $persist Persists the user (in session)
     * @return Permit\User\UserInterface
     **/
    public function setUser(UserInterface $user, $persist=true){
        throw new BadMethodCallException('You cannot write into an readonly container');
    }
<commit_msg>Added support to inject your own guest/system users<commit_after><?php namespace Permit\CurrentUser;

use Permit\User\UserInterface;
use Permit\User\GenericUser;

use BadMethodCallException;

class SystemDetector{
    public function isSystem(){
        return (php_sapi_name() == 'cli');
    }
}

class FallbackContainer implements ContainerInterface{

    protected $_guestUser;

    protected $_systemUser;

    protected $systemDetector;

    protected $systemUserProvider;

    protected $guestUserProvider;

    /**
     * @brief Retrieve the current user.
     *
     * @return Permit\User\UserInterface
     **/
    public function user(){

        if($this->isConsole()){
            return $this->getSystem();
        }
        return $this->getGuest();
    }

    protected function isConsole(){
        return $this->getSystemDetector()->isSystem();
    }

    protected function getSystemDetector(){
        if(!$this->systemDetector){
            $this->systemDetector = new SystemDetector();
        }
        return $this->systemDetector;
    }

    protected function setSystemDetector(SystemDetector $detector){
        $this->systemDetector = $detector;
    }

    public function getGuest(){

        if (!$this->_guestUser) {
            $this->_guestUser = $this->createGuestUser();
        }

        return $this->_guestUser;

    }

    public function getSystem(){

        if(!$this->_systemUser){
            $this->_systemUser = $this->createSystemUser();
        }

        return $this->_systemUser;

    }

    public function provideSystem(callable $provider)
    {
        $this->systemUserProvider = $provider;
        return $this;
    }

    public function provideGuest(callable $provider)
    {
        $this->guestUserProvider = $provider;
        return $this;
    }

    protected function createSystemUser()
    {
        if ($this->systemUserProvider) {
            return call_user_func($this->systemUserProvider);
        }

        $systemUser = new GenericUser();
        $systemUser->setAuthId('system');
        $systemUser->setIsSystem(true);
        return $systemUser;

    }

    protected function createGuestUser()
    {
        if ($this->guestUserProvider) {
            return call_user_func($this->guestUserProvider);
        }

        $guestUser = new GenericUser();
        $guestUser->setAuthId('guest');
        $guestUser->setIsGuest(true);
        return $guestUser;

    }

    /**
     * @brief Set the current user. If a user should be logged in as a
     *        different user you shoul simply set a user a second time
     *
     * @param Permit\User\UserInterface $user
     * @param bool $persist Persists the user (in session)
     * @return Permit\User\UserInterface
     **/
    public function setUser(UserInterface $user, $persist=true){
        throw new BadMethodCallException('You cannot write into an readonly container');
    }

{'fraction_non_alphanumeric': 0.11253248051169298, 'fraction_numerical': 0.0, 'mean_word_length': 2.477414871438499, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360639', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1360, 'n_words': 324}