These are chat archives for PHPixie/Hotline

17th
May 2016
Roman Tsiupa
@dracony
May 17 2016 07:53
@/all so I'm adding support for parameter files to the config module
e.g. you can specify some parameters in a separate config file and use them in cinfig files as %somekey%
This has the advantage that you don't need to change the config files when deploying to a different server
only this one single parameters file
like .env file in laravel
and parameters.yml in symfony
the question is, wwhere should the file be?
/assets/parameters.yml ?
or
/parameters.yml
or
/parameters.local.yml /parameters.prod.yml etc
Generous Tidal
@TidalCharm_twitter
May 17 2016 07:55
I don't feel qualified enough to comment on location of files :D
If its consistent with other config files, I think it will be fine
Roman Tsiupa
@dracony
May 17 2016 07:56
well it doesn't really matter ultimately))
Generous Tidal
@TidalCharm_twitter
May 17 2016 07:56
I like ansible, it has defaults but also lets you write your own locations if you dont like them.
Roman Tsiupa
@dracony
May 17 2016 07:56
you'd be ofc able to change the location anyway if you like))
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:16
I like to have a conf/ or settings/ directory
for stuff like that
sobolevna
@sobolevna
May 17 2016 08:19
We already have /assets directory for configuration, so it wouldn't be necessary to make another one as default. But I can't understand the feature. We have global configuration and bundle configuration, why not to use them?
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:20
Yeah, then /assets makes sense to me
I'm not largely familiar with the project skeleton yet, I didnt get time to play enough.
Roman Tsiupa
@dracony
May 17 2016 08:20
@sobolevna imagine you have your database.php configuration file
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:20
I got hooked on trying to make a perfect ansible + 3 vagrant box setup :D
Roman Tsiupa
@dracony
May 17 2016 08:21
and you have 3 servers you dpeloy to: local, staging and production
the problem is all of them have different database passwords
and database users
you could:
1) have separate config files for each server
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:22

vagrant up now makes:

Web server

  • xenial
  • php7
  • lighttpd
  • config
  • compiles php7-memcached extensions

Db server

  • xenial
  • mysqld
  • config
  • runs migrations

Cache server

  • xenial
  • memcached
  • config

All

  • zsh
  • oh-my-zsh
  • emacs
  • emacs config
Roman Tsiupa
@dracony
May 17 2016 08:22
but then if you change something irrelevant, like add a new connection to a remote database or smth, you need to modify all 3 files to achieve that
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:22
It took time to config
Roman Tsiupa
@dracony
May 17 2016 08:22
nice =)
did you ever try puphpet?
it has a nice ui for this
TidalCharm_twitter @TidalCharm_twitter is a secret devops
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:22
No :D
Roman Tsiupa
@dracony
May 17 2016 08:23
@sobolevna so instead you can do this:
//database.php

<?php
return array(
    'default' => array(
        'driver' => 'pdo',
        'connection' => 'mysql:host=localhost;dbname=quickstart',
        'user'     => '%database.user%',
        'password' => '%database.password%'
    )
);
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:24
@dracony I always pull things like DB password from HashiCorp Vault instance. Saves me from needing different config files & from needing to check credentials into git.
Just set creds in vault, pull in the config .php files.
Roman Tsiupa
@dracony
May 17 2016 08:25
and in your let's say /config/parameters.php have:
<?php
return array(
     'database' => array(
             'user' => 'pixie',
             'password' => 'pixie'
      )
);
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:25
But I can see how this is useful when people don't have CI setups
Roman Tsiupa
@dracony
May 17 2016 08:26
looks nice
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:27
So config.php would be like
Roman Tsiupa
@dracony
May 17 2016 08:27
well technically you could still use valut with this setup too
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:29
<?php

use Jippi\Vault\ServiceFactory;

$sf = new ServiceFactory();
$data = $sf->get('data');

return array(
  'database' => array(
    'user' => $data->get('database.username'),
    'password' => $data->get('database.password')
  )
);
Something like that
(there is a little more to it, I use a dependency injection container to create the vault object in a form I like)
I hate the PHP library for it
sobolevna
@sobolevna
May 17 2016 08:32
@dracony
You know, you can just write many drivers there, specifying them for your purposes just like routing
I also like the way @TidalCharm_twitter proposed, but generating configuration dynamically is quite dangerous
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:33
@sobolevna tbh I do it in CI but I was giving an example
My CI server has my vault instance on
It fills in config files when it does a build
Roman Tsiupa
@dracony
May 17 2016 08:34
@sobolevna also things like twitter api tokens etc
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:34
So ordinary people with git access can't see live creds
Roman Tsiupa
@dracony
May 17 2016 08:34
well and ofc, if you dont need it you can always not use it =)
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:34
Only people with build access :)
Roman Tsiupa
@dracony
May 17 2016 08:34
))
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:35
@dracony Should add the ability to do those Get & Post prefixes :D would be a really nice config option & would help Pixie become a great choice for API devs.
(and most devs I know, when they try a new framework the #1 thing they make is a CRUD service)
Roman Tsiupa
@dracony
May 17 2016 08:36
you mean the method ones?
I think somebody actually did a rest bundle for this
@KokaUA I think
but I could also add it to core I guess
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:38
Hm, REST bundle would be nice
I will see if I can find it :)
Roman Tsiupa
@dracony
May 17 2016 08:39
it can be done with pretty much that single line of code I posted earlier))
TidalCharm_twitter @TidalCharm_twitter still didnt check out the ACL capabilities, is it RBAC?
Roman Tsiupa
@dracony
May 17 2016 08:43
well not really
it's just the authentication part, not authorization
but all you need is an ORM many to many relationship with a role table
and bam you have rbac))
Generous Tidal
@TidalCharm_twitter
May 17 2016 08:45
Uses password_hash & password_verify?
(existing users have bcrypt passwords already :P)
Vadim Meling
@Linfuby
May 17 2016 08:46

@dracony Добрый день.
Не пойму как сделать выборку с обязательным условием вхождения нескольких условий. На примере будет понятнее
Есть таблица фильтров. Есть связанные таблицы, например категории.
Фильтр №1 имеет связь с одной категорией №10
Фильтр №2 имеет связь с двумя категориями №10 и №20
Я хочу получить фильтры, которые имею связь с двумя категориями №10 и №20

$filters = $orm->filter->relatedTo('categories', array(10, 20))->find();

В результате $filters имеет две сущности №1 и №2 хотя нужно только №2

Roman Tsiupa
@dracony
May 17 2016 08:47
$orm->filter->relatedTo('categories', 10)->relatedTo('categories', 20)->find();
->relatedTo('categories', [10,20]) // OR
в SQL relatedTо работает через IN() (так проще понять)
Vadim Meling
@Linfuby
May 17 2016 08:49
@dracony То есть через ОРМ это невозможно?
IN делает выборку записей, даже содержащей 1 из условий
Roman Tsiupa
@dracony
May 17 2016 08:51
так почему неврзможно?
я же написал
$orm->filter->relatedTo('categories', 10)->relatedTo('categories', 20)->find();
будет через AND
Crow
@2x2studio
May 17 2016 08:52
@Linfuby имхо аналог FIND_IN_SET ?
Roman Tsiupa
@dracony
May 17 2016 08:52
читабельнее:
Vadim Meling
@Linfuby
May 17 2016 08:52
@2x2studio Да, точно... Я забыл про FIND_IN_SET
Crow
@2x2studio
May 17 2016 08:52
FIND_IN_SET(’10,20', categories) > 0
Roman Tsiupa
@dracony
May 17 2016 08:53
$orm->filter->relatedTo('categories', 10)->andRelatedTo('categories', 20)->find();
Crow
@2x2studio
May 17 2016 08:53
@Linfuby я так и не понял как через ORM и сделал через датабейс
Roman Tsiupa
@dracony
May 17 2016 08:53
так я же добавил как раз уйму методов типа
->andNotRelatedTo()
->orRelatedTo()
Vadim Meling
@Linfuby
May 17 2016 08:54
@2x2studio Да я уже почти весь фильтр на database сделал, так как ORM очень тяжело тянет большие данные
Roman Tsiupa
@dracony
May 17 2016 08:54
itd
Vadim Meling
@Linfuby
May 17 2016 08:54
@dracony relatedTo не подходит
Crow
@2x2studio
May 17 2016 08:54
@dracony уха а как его отстоить то динамически ? (тупо в форейче докидывать >andRelatedTo ) ?
Roman Tsiupa
@dracony
May 17 2016 08:54
ну да
Crow
@2x2studio
May 17 2016 08:55
@Linfuby это все потому что ты не стандартно айдишники хранишь ))) Я тоже так люблю )))
Vadim Meling
@Linfuby
May 17 2016 08:56
У одного мальчика есть Апельсин и Лимон. у другого только Лимон. RelatedTo зовет мальчиков с апельсином и лимном и подходят оба.
А нужно чтобы подошел только Мальчик у которого и апельсин и лимон.
Да нет, айдишники стандартно (по схеме PHPixie)
Crow
@2x2studio
May 17 2016 08:57
@Linfuby шучу )
Roman Tsiupa
@dracony
May 17 2016 08:57
$orm->filter->relatedTo('categories', 'Apelsin')->andRelatedTo('categories', 'Limon')->find();
@Linfuby
Crow
@2x2studio
May 17 2016 08:57
@dracony ))))) Мы делили апельсин, много наших полягло )))
Roman Tsiupa
@dracony
May 17 2016 08:58
)))
Vadim Meling
@Linfuby
May 17 2016 08:59
Да, если для каждого значения делать relatedTo то работает. Хотя запрос от этого увеличивается значительно
Crow
@2x2studio
May 17 2016 08:59
господа а как посомтреть что ORM у базы спрашивает после отстроения запроса ?
Vadim Meling
@Linfuby
May 17 2016 09:00
Я в OpenServer смотрю запросы
Crow
@2x2studio
May 17 2016 09:00
ну может метода какой есть ? Типа покажи отстоенные запросы
да на субд и я вижу
ну мало ли ? )
Vadim Meling
@Linfuby
May 17 2016 09:02
Ну есть извращенный вариант:
var_dump(current($orm->query('filter')->planFind()->steps())->query()->parse());
Roman Tsiupa
@dracony
May 17 2016 09:03
надо б логер добавить кстати
Vadim Meling
@Linfuby
May 17 2016 09:03
Однако там не полный запрос, а разбитый на запрос и параметры этого запроса
Roman Tsiupa
@dracony
May 17 2016 09:03
видели что я писал о параметрах в конфиге?
сегодня будет уже
Crow
@2x2studio
May 17 2016 09:04
@dracony угу, ждемс
Vadim Meling
@Linfuby
May 17 2016 09:07
Не понял зачем это... Ну да ладно...
Roman Tsiupa
@dracony
May 17 2016 09:08
ну чтобы отделить сам конфиг
от параметров которые меняются в зависимости от окружения
например апи токен твиттера для тестов
против апи токена для продакшна
итд
Crow
@2x2studio
May 17 2016 09:09
@dracony ну или продакшен с тестовым , в моем случае это и конфиг отсылка e-mail
Roman Tsiupa
@dracony
May 17 2016 09:10
к тому же таким образом можно спрятать настройки сервера и например выложить код в опенсорс
Crow
@2x2studio
May 17 2016 09:10
ну и субд конфиг наскоко понял )
Roman Tsiupa
@dracony
May 17 2016 09:10
чтобы не было вот так:
иногда так можно найти пароль к AWS
Vadim Meling
@Linfuby
May 17 2016 09:30
Жесть. Ясно. Тогда поддерживаю
sobolevna
@sobolevna
May 17 2016 09:34
@dracony Вот так бы сразу :-)
Crow
@2x2studio
May 17 2016 13:12
Коллеги, сорри не могу вспомнить если такое. Как полуить список полей модели в ОРМ ?
Roman Tsiupa
@dracony
May 17 2016 13:17
array_keys((array) $entity->data()->data());
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:20
@dracony What are you casting to array?
Roman Tsiupa
@dracony
May 17 2016 13:24
data object from an orm entity
he wants to get all field names
from an entity
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:25
Ah
I'd probably do get_object_vars instead of the array cast but otherwise the same :)
Roman Tsiupa
@dracony
May 17 2016 13:27
yeah
forgot about that
btw
since im doing parameters
I also noticed I might as well do layered configs
so you'd have your base config
and production config that would be applied on top of the default one
would that work better than parameters
@Linfuby @2x2studio @sobolevna
?
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:28
Well the array cast would show private & protected vars, which may or may not be desirable depending on his use case
Roman Tsiupa
@dracony
May 17 2016 13:28
it's just a stdClass
no private/protected
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:28
Ah
Both the same then
Roman Tsiupa
@dracony
May 17 2016 13:36
@Linfuby @2x2studio @sobolevna тоесть я могу сделать так чтобы конфиг весь мерджылся с другим
типа
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:37
You mean like CSS @dracony, where the more 'specific' file overrides the lower ones?
Roman Tsiupa
@dracony
May 17 2016 13:37
//production.php

return array(
    'database' => [
          'default' => ...
     ]
)
yes
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:37
I would definitely be for that, that's how ansible variables work.
Roman Tsiupa
@dracony
May 17 2016 13:37
@TidalCharm_twitter
the only downside vs parameters
is that
if you just need to change one flag that's deep
you'll end up:
return [
     'bla' => [
            'foo' => [
                  'bar' => true
             ]
      ]
]
which kind of sucks
vs
return [
    'bla_foo_bar' => true
]
so idk which way to go
Generous Tidal
@TidalCharm_twitter
May 17 2016 13:39
True but I think its a small price
I'd support cascading vars
sobolevna
@sobolevna
May 17 2016 13:42
@dracony About layered configs: of course yes. For example, you can download a bundle with pre-installed configuration in /vendor folder -- and just modify needed params in config files inside /assets folder
I prefer cascading style too because it's much more difficult to learn many different simple notations than one complicated
Roman Tsiupa
@dracony
May 17 2016 13:46
That you can kind of already do))
since the bundles have 2 configs: one that comes with a bundle
and configuration passed to the bundle
but ok, I'll do it like this =)
sobolevna
@sobolevna
May 17 2016 13:50
That's the one more reason -- less for you to do ;-)
sobolevna
@sobolevna
May 17 2016 13:57
As for dynamic configuration, I have a question: am I right when I want to insert some data inside http config? (the case below occurs in Framework class)
$config = $this->builder->configuration()->httpConfig()->slice('resolver.resolvers');
        $config->set(...);

To be more precise, I've done this:

$config = $this->builder->configuration()->httpConfig()->slice('resolver.resolvers');
$config->set(
            $id, array(
                'type'     => 'pattern',
                'path'     => $pattern,
                'processor' => 'act',
                'action'    => $id
            )
 );

And I don't know, where is the mistake

Roman Tsiupa
@dracony
May 17 2016 14:06
you need to access the
builder->assets->configStorage()->slice('http') instead
since httpConfig() is a copy of the actual data
for faster access
sobolevna
@sobolevna
May 17 2016 14:10
So the whole pass is like that?
$config = $this->builder->assets->configStorage()->slice('http.resolver.resolvers') ;
Roman Tsiupa
@dracony
May 17 2016 14:16
yes
ok I did support for merging configs
but damn it seems like overengineering =\
sobolevna
@sobolevna
May 17 2016 14:18
What do you mean?
Generous Tidal
@TidalCharm_twitter
May 17 2016 14:21
Why overengineering @dracony?
Generous Tidal
@TidalCharm_twitter
May 17 2016 14:28
Isn't it just a call_user_func_array to array_replace_recursive with an array of config files to parse?
sobolevna
@sobolevna
May 17 2016 14:33
@TidalCharm_twitter
Well, it's not: during initial actions all config files' data become a part of big set of objects with its own system of navigation, extraction and editing
Generous Tidal
@TidalCharm_twitter
May 17 2016 14:34
@sobolevna But surely would do this merge before the initial actions?
sobolevna
@sobolevna
May 17 2016 14:38
@TidalCharm_twitter
You don't understand: all the configuration is placed in that set of objects. During initial actions PHPixie looks for specified directories and includes the data which is returned by config files. If you want to merge many configurations of the same things, you should do it right there
Roman Tsiupa
@dracony
May 17 2016 14:39
I just made it support both parameters AND overlays
Generous Tidal
@TidalCharm_twitter
May 17 2016 14:39
Oh OK, so I was just looking at the return array() examples above
Roman Tsiupa
@dracony
May 17 2016 14:39
This is going to require a lot of docs =(
@TidalCharm_twitter it's just the files format, you could also have it in json if you like
but I htink I really nailed it
basically you still have the parameters.php file
where you can specify variables
but!
you can also specify a 'configOverlay' path in it
if it's specified the data under that config path
sobolevna
@sobolevna
May 17 2016 14:41
Examples, please
Roman Tsiupa
@dracony
May 17 2016 14:41
will get overlayed on top of the actual config
ok
so you have
asstes/
    parameters.php
    config/
         database.php
         env/
             prod.php
             dev.php
//parameters.php
return [
    'configOverlay' => 'env.prod',
    'dbuser' => 'someuser'
    'dbpass' => 'somesecret'
]
// database.php
return [
     'default' => [
            'connection' => 'sqlite:...'
      ]
]
Roman Tsiupa
@dracony
May 17 2016 14:47
//prod.php
return [
     'database' => [
           'default' => [
                  'connection' => "mysql:....",
                  'user' => '%dbuser%',
                 'password' => '%dbpass%'
           ]
      ]
];
so
the default config connects to some local sqlite database
but when the specified overlay is applied
it will connect to a mysql database
and use the user and password from variables
makes sense?
@Linfuby
Roman Tsiupa
@dracony
May 17 2016 14:56
...
anybody?
Vadim Meling
@Linfuby
May 17 2016 14:56
Ну вообще если говорить о подмене имени пользователя и пароля для подключения к БД, то и не помешало бы подменять и имя БД.
У себя я например добавляю параметр database в конфиг, так как без этого практически невозможно узнать в какой БД на данный момент я подключен.
Roman Tsiupa
@dracony
May 17 2016 14:57
nu vse chto hochesh mozhno podmenitj konechno
Generous Tidal
@TidalCharm_twitter
May 17 2016 14:57
Makes sense to me
Roman Tsiupa
@dracony
May 17 2016 14:57
важная часть в том что можно подменять так же конфиг целыми кусками
Vadim Meling
@Linfuby
May 17 2016 14:58
А если я не укажу configOverlay, то будет использоваться логин и парль из parameters.php?
Roman Tsiupa
@dracony
May 17 2016 14:58
ну если ты не укажешь оверлей
то оно не будет смотреть в прод.пхп
и законектится к sqlite
Vadim Meling
@Linfuby
May 17 2016 14:59
А если указать, то файл будет отсутствовать, то так же данные будут браться из parameters? Я всё правильно понимаю?
Roman Tsiupa
@dracony
May 17 2016 14:59
но если пихнуть сразу в database.php то конечно параметры будут работать
да
пареметры не зависимы от оверлея
Vadim Meling
@Linfuby
May 17 2016 14:59
Ну такой вариант меня вполне устраивает
Roman Tsiupa
@dracony
May 17 2016 14:59
кк
@TidalCharm_twitter great )
now some tests and docs
and it
'll be live today)
that was an feature born from a showerthought))
Generous Tidal
@TidalCharm_twitter
May 17 2016 15:00
Haha
We've all had those!
Roman Tsiupa
@dracony
May 17 2016 15:01
=)
KATERONLINE.RU
@kateronline_twitter
May 17 2016 15:19
Блин, у меня прям мучение. я не очень знаю ооп и у меня никак не выходить сделать расширение для шаблона, что бы можно было прямо из шаблона вызвать функцию, которая делает то что мне нужно, подскажите как. Написано то не проблема при примеру расширения HTML, а вот подключить не получилось, как сделать правильно, можно или ссылку на гайд или пример
?
sobolevna
@sobolevna
May 17 2016 15:20

Well, OK, but I think it would be better to use by default the same notation as we already use in classes:

assets/ 
    config.php 
    config/ 
        database.php 
        database/ 
            prod.php 
            dev.php

Don't you think so?

Roman Tsiupa
@dracony
May 17 2016 15:23
then the problem would be that you'd have a lot of small prod.php files
instead you can make a config/env/prod/ folder
and put the tree the same way there as inr egular /config/
@kateronline_twitter of course
here is a simple extension
<?php

namespace SomeNamespace;

class Stuff implements \PHPixie\Template\Extensions\Extension
{
    public function name()
    {
        return 'stuff';
    }

    public function methods()
    {
        return array(
            'doSomething' => 'doSomething'
        );
    }
    public function aliases()
    {
        return array();
    }

    public function doSomething()
    {
        echo 555;
    }
}
then in src/Project/Framework/Extensions.php
    public function templateExtensions()
    {
        return array_merge(parent::templateExtensions(), array(
           new SomeNamespace\Stuff()
        ));
    }
then use it in template
$this->doSomething();
KATERONLINE.RU
@kateronline_twitter
May 17 2016 15:32
^_^ спасибо
sobolevna
@sobolevna
May 17 2016 15:36
@dracony
Well, that's not a problem -- ./prod.php file with overlay and default rules and ./prod/ folder with many files :-)
Or is this too difficult to handle with current model of configuration storage?
Roman Tsiupa
@dracony
May 17 2016 15:38
well technically I can make it any which way possible))
but what you seem to want is to be able to have
database/prod.php and database/dev.php
in that case it's hard to distinguish
and where the actual data is
where the overlay is
since remember that all the config folder can also be written into a single config.php file
which would then look like
return [
    'database' => [
          'default' => .....
          'prod' => ...
          'dev' => ...

    ]
]
and to the frmeworjk it would seem that prod and dev are just new connections
ofc
you could always define two connections
call one prod
the other one dev
and use a single parameter in orm.php
to tell it which connection to use
this way you wont need an overlay at all
sobolevna
@sobolevna
May 17 2016 15:43
I think all of us know this :-)
The question was how to use overlay to hide the real username and password if needed
Roman Tsiupa
@dracony
May 17 2016 15:45
hide it with parameters
overlay is more for changing config
e.g.
let's say you are configuring a logger
and on production it should log to kibana or logstache
and on local it should log to some file
in that case you could use an overlay
since the configs are different
Generous Tidal
@TidalCharm_twitter
May 17 2016 19:37
Hey @dracony, got an nginx conf template for a pixie app?
Roman Tsiupa
@dracony
May 17 2016 20:04
Not atm
But there is nothing special
Just copy from any other framework
Generous Tidal
@TidalCharm_twitter
May 17 2016 20:08
rewrite all reqs to index.php?
Roman Tsiupa
@dracony
May 17 2016 20:38
yes
and set web/ as document root
Generous Tidal
@TidalCharm_twitter
May 17 2016 20:39
I will symlink /var/www/html to web/
Roman Tsiupa
@dracony
May 17 2016 21:31
if that works, sure
Generous Tidal
@TidalCharm_twitter
May 17 2016 21:51
- name: Create a hard link to TWI     
  shell: "{{ item }}"                 
  with_items:                         
    - rm -rf /var/www/html            
    - ln -s /vagrant/web /var/www/html
:D