Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • ll-api-test
  • php84
  • detached3
  • detached4
  • detached
  • detached2
  • 5.x
  • trydeps
  • 4.x
  • 6.1.0
  • 6.0.2
  • 6.0.1
  • 6.0
  • 5.0.0
  • 4.0.1
  • 4.0.0
  • 3.0.0
18 results

AbstractAdapter.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AbstractAdapter.php 1.53 KiB
    <?php
    
    namespace ZfcUser\Authentication\Adapter;
    
    use Laminas\Authentication\Storage;
    
    abstract class AbstractAdapter implements ChainableAdapter
    {
        /**
         * @var Storage\StorageInterface
         */
        protected $storage;
    
        /**
         * Returns the persistent storage handler
         *
         * Session storage is used by default unless a different storage adapter has been set.
         *
         * @return Storage\StorageInterface
         */
        public function getStorage()
        {
            if (null === $this->storage) {
                $this->setStorage(new Storage\Session(get_class($this)));
            }
    
            return $this->storage;
        }
    
        /**
         * Sets the persistent storage handler
         *
         * @param  Storage\StorageInterface $storage
         * @return AbstractAdapter Provides a fluent interface
         */
        public function setStorage(Storage\StorageInterface $storage)
        {
            $this->storage = $storage;
            return $this;
        }
    
        /**
         * Check if this adapter is satisfied or not
         *
         * @return bool
         */
        public function isSatisfied()
        {
            $storage = $this->getStorage()->read();
            return (isset($storage['is_satisfied']) && true === $storage['is_satisfied']);
        }
    
        /**
         * Set if this adapter is satisfied or not
         *
         * @param bool $bool
         * @return AbstractAdapter
         */
        public function setSatisfied($bool = true)
        {
            $storage = $this->getStorage()->read() ?: array();
            $storage['is_satisfied'] = $bool;
            $this->getStorage()->write($storage);
            return $this;
        }
    }