• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CacheInterface In view cell

#1
Question 
hello

I am trying to understand how view_cell work. I am reading view_cell doc guide and then check CI system. but I do not understand properly that how the interface can create an object?

File : System/view/cell.php

Code:
class Cell
{
    /**
     * Instance of the current Cache Instance
     *
     * @var CacheInterface
     */
    protected $cache;

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

    public function __construct(CacheInterface $cache)
    {
        $this->cache = $cache;
    }

Can anyone explain in details how cell construct work?
Reply

#2
That simply means that the constructor will accept any class that implements CacheInterface. So, you couldn't pass the actual interface to it and expect it to do anything, but you could pass either Cache\FileHandler or Cache\RedisHandler class if they both implemented that interface.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#3
view_cell basically common function that called from common.php file.
PHP Code:
// file : common.php

function view_cell(string $library$params nullint $ttl 0string $cacheName null)
    {
        return 
Services::viewcell()->render($library$params$ttl$cacheName);
    } 

in above function, Services called view cell. basically, I need to understand from start to end this function flow.
Reply

#4
Well, which parts do you not understand? You should be able to follow the code through the paths relatively easily. If there's language constructs you're not familiar with that's one thing.

Basically, the view_cell function calls the Config\Services method, viewcell(), which returns an instance of the CodeIgniter\View\Cell class. Within the services function, it passes it an instance of whatever the currently configured Cache engine is.

The relevant methods you're probably getting confused by are:

- Services::cache
- Services::viewcell
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#5
Thumbs Up 
@kilishan 

Thanks for your help, now I understand.

Thanks for your efforts.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.