These are chat archives for ppi/framework

8th
Dec 2015
Paul Dragoonis
@dragoonis
Dec 08 2015 09:36
Good morning! :)
Roman Tsiupa
@dracony
Dec 08 2015 09:37
hey hey
hows it going with guard?
Paul Dragoonis
@dragoonis
Dec 08 2015 09:38
Well I didn’t get to it. Got moved onto some PPI work on AWS
Roman Tsiupa
@dracony
Dec 08 2015 09:39
ah
(
btw
want a phpixie sticker?)
I still have some lying around
and can ship pretty much worldwide)
Paul Dragoonis
@dragoonis
Dec 08 2015 09:43
sure!
Roman Tsiupa
@dracony
Dec 08 2015 09:43
PM me some postal address and it'll be on the way tomorrow)
Paul Dragoonis
@dragoonis
Dec 08 2015 09:44
will do
pixie templating component? how about it :)
is today the day?
Roman Tsiupa
@dracony
Dec 08 2015 09:45
sure
)
let me just finish writing a redit post real quick)
Vítor Brandão
@noisebleed
Dec 08 2015 09:45
Can you send another sticker to Paul? Going to Scotland by the end of the month and could a get a sticker myself :P
Roman Tsiupa
@dracony
Dec 08 2015 09:47
sure)
ok Im done
link me to an interface I'd need to satisfy to get this show on the road)
Paul Dragoonis
@dragoonis
Dec 08 2015 09:48
PPI team will be in Edinburgh for new years celebration
Roman Tsiupa
@dracony
Dec 08 2015 09:49
I can send a bunch if they'd like too)
Roman Tsiupa
@dracony
Dec 08 2015 10:04
What's a namefactory?
handles namespaces for templates?
Paul Dragoonis
@dragoonis
Dec 08 2015 11:38
never heard of it
Roman Tsiupa
@dracony
Dec 08 2015 11:38
its fro the plates integration repo
Paul Dragoonis
@dragoonis
Dec 08 2015 11:38
ah yes, that thing.
In the end I didn’t need to use a name factory
Roman Tsiupa
@dracony
Dec 08 2015 11:39
ah
so
what should I provide?
Paul Dragoonis
@dragoonis
Dec 08 2015 11:41
Oh, we’re talking pixie templating name
Roman Tsiupa
@dracony
Dec 08 2015 11:41
mm?
Paul Dragoonis
@dragoonis
Dec 08 2015 11:41
Roman Tsiupa
@dracony
Dec 08 2015 11:42
yup
Paul Dragoonis
@dragoonis
Dec 08 2015 11:44
I need to give it a path to the rendered file.
Roman Tsiupa
@dracony
Dec 08 2015 11:46
ah
true
well not much of a bug, just an extra statement
that is never reached
will remove
$slice = new \PHPixie\Slice();
$filesystem = new \PHPixie\Filesystem();
//Configuration
$locatorConfig = $slice->arrayData(array(
    'directory' => '/' // since you provide full path
));
$templateConfig = $slice->arrayData(array(
    // any user config options
));

//Build dependencies
$root = $filesystem->root('/');
$locator = $filesystem->buildlocator($locatorConfig, $root);

//And the Template library itself
$template = new \PHPixie\Template($slice, $locator, $templateConfig);

echo $template->render('/full/path/to/file.php', array(
    'name' => 'Stella'
));
Paul Dragoonis
@dragoonis
Dec 08 2015 11:49
Thank you.
Roman Tsiupa
@dracony
Dec 08 2015 11:49
but
are the users also required to use full paths when specifying layouts inside the template?
e.g. $this->layout('main') ?
Paul Dragoonis
@dragoonis
Dec 08 2015 11:58
@dracony with symfony you specify full path. With Plates you specify your namespace::file
Roman Tsiupa
@dracony
Dec 08 2015 11:58
I see
well
in that case
even simpler
we can skip the entire filesystem bit
e.g.:
```php
$slice = new \PHPixie\Slice();
$templateConfig = $slice->arrayData(array(
    // any user config options
));

$locator = new YourAwesomeLocator();

//And the Template library itself
$template = new \PHPixie\Template($slice, $locator, $templateConfig);

echo $template->render('/full/path/to/file.php', array(
    'name' => 'Stella'
));
```
Paul Dragoonis
@dragoonis
Dec 08 2015 12:00
I can plug in our symfony-based Locator to parse Module:folder:some/file.html.php
Roman Tsiupa
@dracony
Dec 08 2015 12:00
class YourAwesomeLocator implements \PHPixie\Filesystem\Locators\Locator
{
       public function locate($name, $isDirectory = false)
       {
               return callYourNamespaceThingy();
        }
}
and thats it
brb lunch)
function should return the full path to file (obviously)
Paul Dragoonis
@dragoonis
Dec 08 2015 12:02
That’s easy enough.
class PixieLocator implements \PHPixie\Filesystem\Locators\Locator { 
    __construct(PPIFileLocator $l) {  }

    public function locate($name, $isDir = false) { 
        return $this->locator->locate($name); 
    }

}
but what about just doing this->layout(‘somelayout’); how does it know which path this is for ?
Paul Dragoonis
@dragoonis
Dec 08 2015 12:28
@dracony
Roman Tsiupa
@dracony
Dec 08 2015 13:07
here
it calls the locator
so it will just work =)
Roman Tsiupa
@dracony
Dec 08 2015 13:18
@dragoonis
Paul Dragoonis
@dragoonis
Dec 08 2015 13:19
Okay. Few bits still unclear but I’ll get to implementing a locator later today and see what happens.
Roman Tsiupa
@dracony
Dec 08 2015 13:20
well pretty much every time it looks for a template ( layout, includes, renders) it passes the name to the locator
Paul Dragoonis
@dragoonis
Dec 08 2015 13:21
that makes sense.
plates has namespacing so you can be relative to the module you’re in.
$config[‘mymodule’] = ‘modules/mymodules/resources/view’;
Roman Tsiupa
@dracony
Dec 08 2015 13:22
pixie also has that
Paul Dragoonis
@dragoonis
Dec 08 2015 13:22
$this->layout(‘mymodule::some/file.php’);
Roman Tsiupa
@dracony
Dec 08 2015 13:22
but it's just a special locator
Paul Dragoonis
@dragoonis
Dec 08 2015 13:23
Say you have a layout file in your current module, and a layout in your global template path, in Pixie how do you specify each.
Roman Tsiupa
@dracony
Dec 08 2015 13:23
but I figured it would be easier fo you to just implement a loator that resembles ppi as much as possible
than rely on pixielocators
Paul Dragoonis
@dragoonis
Dec 08 2015 13:25
ppi isn’t a framework - it’s a framework loader.
it provides whatever native frameworks provide
as such there’s no “ppi way” - ppi is just loading pixie templating for you and you should be able to copy/paste your templates from pixie framework apps, in here.
I’m looking to emulate exactly how it works in phpixie framework.
Roman Tsiupa
@dracony
Dec 08 2015 13:27
$filesystem = new \PHPixie\Filesystem();
$root = $filesystem->root('/project/folder/');

//Configuration
$locatorConfig = $slice->arrayData([
'type' => 'prefix',
 'locators' => [
      'Site' => [
           'directory' => '/modules/site/',
        ],
        'Stuff' => [
             'directory' => '/modules/stuff/',
         ]
]);
$locator = $filesystem->buildlocator($locatorConfig, $root);
then you can Site:/some/bla.php -> /project/folder/modules/site/some/bla.php
Paul Dragoonis
@dragoonis
Dec 08 2015 13:28
$this->layout(‘Site:/some/file.php’); ??
Roman Tsiupa
@dracony
Dec 08 2015 13:28
yup
you can opit the / after : though
Paul Dragoonis
@dragoonis
Dec 08 2015 13:28
Good.
Roman Tsiupa
@dracony
Dec 08 2015 13:29
site:some/file.php
Paul Dragoonis
@dragoonis
Dec 08 2015 13:29
Got it.
Roman Tsiupa
@dracony
Dec 08 2015 13:29
the downside is you'll have to build the locators config array
and there is no 'pixie' way about it too, since the config is user specified
notreally a downside though
what im saying is you can spin it anywhich way you like)
Paul Dragoonis
@dragoonis
Dec 08 2015 13:31

If we have 2 modules: ModuleA, ModuleB

ModuleA defines its own config
$config[‘pixie’][‘prefix’][] = __DIR__ . ‘../resources/views/‘;

ModuleB defines its own config
$config[‘pixie’][‘prefix’][] = __DIR__ . ‘../resources/views/‘;
and then when we boot the pixie template, i will iterator and set the prefixes.
Thoughts?
Roman Tsiupa
@dracony
Dec 08 2015 13:32
also pixie has a mount locator
so you can have both modules return locators
and then mount them
Paul Dragoonis
@dragoonis
Dec 08 2015 13:32
Will need a code example of this.
Roman Tsiupa
@dracony
Dec 08 2015 13:33
well
actually better:
class PixieLocator   implements \PHPixie\Filesystem\Locators\Locator
{
     protected $locators = array();
     public function locate($name, $isDir = false)
     {
          list($module, $name) = explode(':', $name, 2);
          if(!isset($this->locators[$module])) {
              $moduleRoot = $filesystem->root($ppi->getModulePath($module));
              $locatorConfig = $slice->arrayData($ppi->getModulePHPixieLocatorConfig($module));
              $this->locators[$module] = $filesystem->buildLocator($locatorConfig, $moduleRoot);
         }
         return $this->locators[$module]->locate($name, $isDir);
     }
}
Roman Tsiupa
@dracony
Dec 08 2015 13:42
now you have a locator that allows per module configuration
$ppi methods I just made up )
Paul Dragoonis
@dragoonis
Dec 08 2015 13:43
Symfony already has this, we can make that work fine.
Roman Tsiupa
@dracony
Dec 08 2015 13:43
ah
well
problem solved then)