These are chat archives for PHPixie/Hotline

13th
May 2016
Roman Tsiupa
@dracony
May 13 2016 08:09
yup
althought it's just generic support
e.g. you still need to do aggregates etc yourself
Generous Tidal
@TidalCharm_twitter
May 13 2016 08:09
Morning
@dracony If I find it even a little useful, expect PRs to add a lot of functionality to that :P
Roman Tsiupa
@dracony
May 13 2016 08:18
))) sure)
Crow
@2x2studio
May 13 2016 12:11
Коллеги добрый день. Нид соме хелп
Vadim Meling
@Linfuby
May 13 2016 12:11
?
Crow
@2x2studio
May 13 2016 12:12
возможно ли в роутинге использование конструкции
        'service_get' => array(
            'type'     => 'pattern',
            'methods'  => ['GET'],
            'path'     => 'api/<processor>/<action>(/)',
            'defaults' => array(
                'processor' => '<processor>',
                'action'    => '<action>Get',
            )
        ),
'action' => '<action>Get',
Во тут закос
Если 'action' => '<action> то метод вызывается
но очень хочетсья добавлять перфикс в акшен в зависимости от типа запроса
Vadim Meling
@Linfuby
May 13 2016 12:18
А зачем? methods уже ограничивает только GET-запросы. То есть при выполнении POST-запроса, данный роутинг не сработает.
Следовательно достаточно называть функцию <action>
Или можно сделать промежуточную функцию в процессоре
publick function actionAction($request){
    if($request->method() === 'GET'){
        return $this->actionGetAction($request);
    }
    if($request->method() === 'POST'){
        return $this->actionPostAction($request);
    }
    return null;
}
Crow
@2x2studio
May 13 2016 12:27
да вот как раз этого хотел ихбежать
вторая такая же секция с постом вазывала бы методы пост
2 роутами и подстанновкой порешал бы вопрос со всем набором функций в процессоре
Generous Tidal
@TidalCharm_twitter
May 13 2016 12:31
Someone teach me Russian. :D
Crow
@2x2studio
May 13 2016 12:33
oops ) sorry . So I try to add a prefix to router action , like 'action' => '<action>Get',
Generous Tidal
@TidalCharm_twitter
May 13 2016 12:33
No, its fine :D I just sat back down and saw activity. :D
I'm not going to be able to help anyway, I only picked the framework up yesterday.
Crow
@2x2studio
May 13 2016 12:35
) anyway I have trouble with prefix and need a hint from @dracony )
I see )
Generous Tidal
@TidalCharm_twitter
May 13 2016 12:52
Looks like it's in Processors/src/PHPixie/Processors/Processor/Actions.php
function actionMethodName
Oh, nvm, you want actions via GET to be whateverGetAction?
and via POST to be whateverPostAction?
Crow
@2x2studio
May 13 2016 12:54
yes
exactly
Generous Tidal
@TidalCharm_twitter
May 13 2016 12:55
That seems sensible
Generous Tidal
@TidalCharm_twitter
May 13 2016 13:05
Sorry, I don't know the answer. I'll be interested in what it is when @dracony sees the question. :)
Generous Tidal
@TidalCharm_twitter
May 13 2016 13:17
@2x2studio Have you been using PHPixie for long?
Crow
@2x2studio
May 13 2016 13:21
no. seems i use it only 3-4 month . So i alsow junior . btw we just finish a small project on PHPixie ) So i have one working project )
Roman Tsiupa
@dracony
May 13 2016 13:52
im here)
the defaults array is just an array
the placeholders like <action> don't get replaced there
I could add it I guess
Crow
@2x2studio
May 13 2016 13:54
hmmm . But it works without prefix )
Roman Tsiupa
@dracony
May 13 2016 13:55
but what you really need is to override getactionNameFor($request)
Crow
@2x2studio
May 13 2016 13:55
if i use placeholder, it call tha same functions in processor
Roman Tsiupa
@dracony
May 13 2016 13:56
  protected function getActionNameFor($httpRequest) {
       $name = $httpRequest->attributes()->get('action');
       $name.= $httpRequest->method();
       return $name;
  }
inside your controller
this methods decides which method will be called
if you do it like this
it will be
updatePostAction()
is that what you need?
Crow
@2x2studio
May 13 2016 13:58
not exactly
just a moment
so now i have route
        'service_post' => array(
            'type'     => 'pattern',
            'methods'  => ['POST'],
            'path'     => 'api/<processor>/<action>(/)',
            'defaults' => array(
                'processor' => '<processor>',
                'action'    => '<action>',
            )
        ),
if request is /api/services/status
it call serivice processor and action status
but i need to swith to another acton if method = GET
Roman Tsiupa
@dracony
May 13 2016 14:01
and?
I don't get it =\
or are you still typing?
Crow
@2x2studio
May 13 2016 14:01
moment
now i have public function statusGetAction(Request $request) in proc
can i use a a prefix in router ?
'action' => '<action>Get',
Roman Tsiupa
@dracony
May 13 2016 14:03
no
at least not now
I can add it though
but you can add this prefix in the method I showed above
a general approach would be like so
Crow
@2x2studio
May 13 2016 14:04
if it Get request it will call statusGetAction , in case POST it will call statusPOSTAction
Roman Tsiupa
@dracony
May 13 2016 14:04
so you always want it to be Get?
or the same as the HTTP method?
alright
I think I know what you needL
route:
Crow
@2x2studio
May 13 2016 14:06
хм. Переключюсь на русский. Нет, мне не обязательно префикс менять в зависимости от типа запроса, я пытаюсь упростить написание роутинга
ща
Roman Tsiupa
@dracony
May 13 2016 14:07
понял
тогда
        'service_post' => array(
            'type'     => 'pattern',
            'methods'  => ['POST'],
            'path'     => 'api/<processor>/<action>(/)',
            'defaults' => array(
                'prefix' => 'some',
            )
        ),
Crow
@2x2studio
May 13 2016 14:07
но в данном частном случае он у меня зависит от метода
и ?
Roman Tsiupa
@dracony
May 13 2016 14:08
  protected function getActionNameFor($httpRequest) {
       $name = $httpRequest->attributes()->get('action');
       $name.= $httpRequest->attributes()->get('prefix');
       return $name;
  }
Crow
@2x2studio
May 13 2016 14:08
та да , я понял
Roman Tsiupa
@dracony
May 13 2016 14:08
так тоже нет?
Crow
@2x2studio
May 13 2016 14:09
ща попробую
доконца не понял
Roman Tsiupa
@dracony
May 13 2016 14:10
ну смотри
функция getActionNameFor в контролере получает запрос
и возвращает имя екшна который надо вызвать
по дефолту она просто берет заначение <action>
ты же хочешь добавить префикс
точнее в моем случае получился суфикс
$name.= $httpRequest->attributes()->get('prefix');
вот эта строка его добавляет
получится
updateSomeAction
вместо просто updateAction
Crow
@2x2studio
May 13 2016 14:13
логика понятна. Ща потестирую можно и так в целом
спасибки
ну минусы только в том что если у меня есть несколько процессоров в каждом нужно добавить getActionNameFor
проверил на одном - все запустилось
Roman Tsiupa
@dracony
May 13 2016 14:32
extends ;)
на самом деле мне совсем не трудно добавить замену в defaults
но это же только дефольные значения
тоесть когда будет екшн они не вступят в действие
но
я могу добавить сразу в фреймвок ети штуки с префиксом
оно ничего не поломает ведь
Generous Tidal
@TidalCharm_twitter
May 13 2016 14:41
Does PHPixie have JSON/XML action helpers?
(for creation of JSON/SOAP API)
Example is I want to be able to request https://domain.com/api/v1/endpoint.xml and get XML, and endpoint.json returns JSON.
Generous Tidal
@TidalCharm_twitter
May 13 2016 14:47
(also, how would the period translate into an action name, as an underscore or ignored?)
Crow
@2x2studio
May 13 2016 14:50
@TidalCharm_twitter as defaults it return json.
 return array('success' => true, 'data' => 1);
will return json
as i know , there is no helpers to proccess request with diffrent returned format . You need add it by himself
Roman Tsiupa
@dracony
May 13 2016 15:01
@TidalCharm_twitter if you return a string from a controller it's just a string
if you return a template object it will get rendered
arrays and objects get json_encoded
or
you can always return a HTTP response object
built with one of the http component methods:
$https->responses()->redirect('/somewhere')
etc
since all the processors are nested
you can add your own normalizations
simply:
//in HTTPProcessor.php
public function process($request) {
     $result = parent::process($request);
     if(is_array($result)) {
           $result = .... //transform to something;      
     }
     return $result;

}
so like if you got an array object you can make it into xml or smth
as for period in action name
it will raise an exception when trying to call a method
but
you can override the same function I suggested to @2x2studio
Roman Tsiupa
@dracony
May 13 2016 15:06
  protected function getActionNameFor($httpRequest) {
       $name = $httpRequest->attributes()->get('action');
       $name = ....//change it anyway you like;
       return $name;
  }
Generous Tidal
@TidalCharm_twitter
May 13 2016 19:16
@dracony Is there a simple way to do that without modifying the original, i.e. via config or extension?
Roman Tsiupa
@dracony
May 13 2016 19:29
that just goes int your controller
you don't need to ever modify anything in the /vendor folder
like in the HttpProcessors/Greet.php file
Generous Tidal
@TidalCharm_twitter
May 13 2016 19:30
Oh
So I can just make a MyApp\AbstractController extending PHPixie's controller, then make my changes there
That's cool
I was reading this as a source change
Roman Tsiupa
@dracony
May 13 2016 19:45
sure
You can override a lot of stuff since classes are only ever built using factory classes (usually named Builder)
you can override a bunch of classes so your factories load instead of the regular ones
but thats rarely needed
Generous Tidal
@TidalCharm_twitter
May 13 2016 19:47
That's what I like to hear
Roman Tsiupa
@dracony
May 13 2016 19:47
e.g. you build your controllers yourself in the HTTPProcessors file
so you can put whatever there
Generous Tidal
@TidalCharm_twitter
May 13 2016 19:47
Not like ZF2... hoooly I am never touching Zend Event again.
Roman Tsiupa
@dracony
May 13 2016 20:00
no events in pixie too)