PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 28, 2022

[FIXED] Is there AOP for Yii 2?

 February 28, 2022     aop, php, typo3-flow, yii, yii2     No comments   

Issue

I want to know how much time is executed every action. The easiest/ correct way would be to use AOP.

I'd like to have something like this:

/**
 * @FLOW3\Before("method(.*->action.*())")
 */
 public function markFirstTimeTag() {
// Do something here.
 }

 ...

 /**
 * @FLOW3\After("method(.*->action.*())")
 */
 public function markSecondTimeTag() {
// Do something here.
 }

I read about the FLOW3 and this framework I liked. But this is a full-stack framework itself.

Is there the implementation of AOP pattern for Yii 2?


Solution

I usually use Logging to profile my code.

Yii::trace('starting some event');
foreach(..)
{
    ...
}
Yii::trace('some event done');

This traces can be found in the Logs section of the debug bar.

This could be used in combination with beforeAction() and afterAction() (not tested)

public function beforeAction($action)
{

    if (!parent::beforeAction($action)) {
        return false;
    }

    Yii::trace($action->id.' started');

    return true; // or false to not run the action
}

public function afterAction($action, $result)
{
    $result = parent::afterAction($action, $result);
    Yii::trace($action->id.' ended');
    return $result;
}

I also found Performance Profiling in the docs, but i have not tried any of the solutions.



Answered By - Jørgen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing