Joomla Plugin onAfterRender - events

How do I make the onAfterRender to be called last?
The problem is I wan't to make changes to the JResponse:getBody() when everything is all done.
But sadly to say the custom plugin that I created is not being called in last, so after I do my changes to the content there is another plugin that will do its changes, which is not good on my side.
Is there any other way or setup to do, in order my onAfterRender get call in last?
[update]
Found and answer from Joomla Forum, but still not working that changing the ordering of plugin to the last, this might work but for some other reason the other plugin is still not following the order.
As of now, I guess the sequence of constructing the plugin is fine but the event is a bit odd.
My theory is Custom Plugin might have a less process which will call the onAfterRender than the Other Plugin instead of being in a sequence of Other Plugin __construct ()Custom Plugin __construct ()Other Plugin onAfterRender ()Custom Plugin onAfterRender ()

I manage to fix the issue by detaching and attaching it on JEventDispatcher::getInstance();
/**
* [onAfterInitialise description]
* #return [type] [description]
*/
public function onAfterInitialise()
{
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->detach($this);
$dispatcher->attach($this);
}
/**
* [onBeforeRender description]
* #return [type] [description]
*/
public function onBeforeRender()
{
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->detach($this);
$dispatcher->attach($this);
}
Still I'm in question, hope someone could explain it to me :)

Related

Problem with logging in (Laravel Jetstream)

I have the following problem: Always when I try to log in, on the first attempt the page is just reloading without performing any action like showing up a message for wrong credentials or something like this. On the second attempt everything works fine. Any ideas?
Laravel version: 8
After many, many researches for this kind of problem I think I found my specific solution. I've actually built a route long time ago for logging out which had the following code:
Auth::logout();
return redirect()->route('site.home');
I have no idea why I've created and used this route at all. According to jetstream's core code and my understandings that's not how you fully logout a user and destroy session. But here's how:
/**
* Destroy an authenticated session.
*
* #param \Illuminate\Http\Request $request
* #return \Laravel\Fortify\Contracts\LogoutResponse
*/
public function destroy(Request $request): LogoutResponse
{
$this->guard->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return app(LogoutResponse::class);
}
I've tested it right now and everything works fine.

How to replace phpdocs with new attributes in php 8

I am using laravel. I need to know how phpdoc can be written in php 8 with attibutes.
/**
* Transform the resource into an array.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function toArray($request)
{
//Some code
return [];
}
Can someone please explain how the above code can be written with attributes.
I believe you have misunderstood what Attributes are for, and how they related to doc blocks. There are two common uses of doc blocks (comments marked with /** ... */):
To document the code (hence the name "doc block"), in a mostly-standardised way which can be read by various tools, including documentation generators and IDEs.
To add machine-readable annotations to the code, for use with libraries and frameworks that can automatically generate behaviour based on those. For instance, an ORM might use an annotation of #TableName('Foo') to link a class to a particular database table, and generate appropriate SQL.
The example you've shown is of the first usage. What you have written is still the correct way of writing documentation.
PHP 8's native Attributes replace the second usage. It's up to the library what Attributes to look for, but an ORM that previously looked for #TableName('Foo') in a docblock might now look for #[TableName('Foo')] as a native Attribute instead.
There is a great automatic refractoring tool called rector. It will make your life so much easier. Install it, then create a rector.php file at the root directory that should look like something like this:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Symfony\Set\SensiolabsSetList;
use Rector\Symfony\Set\SymfonySetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests'
]);
$rectorConfig->sets([
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
SensiolabsSetList::FRAMEWORK_EXTRA_61,
]);
};
There are plenty of configuration options that you can find in the docs.
When you are done, just run the refractoring tool:
vendor/bin/rector process src

What is Symfony 2's #Assert\Email validation criteria for a valid email?

I'm running into a problem where the following email aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanom#domaine.com is not valid according to this assertion on the Doctrine Entity using #Assert\Email for the email property.
I don't see any documentation detailing what the checks are for passing or failing this validation.
Curious to know where the code is or where I can find more documentation on what this assertion is doing...
Update, my whole assertions on that Entity property are:
/**
* #ORM\Column(type="string", length=511)
* #Filter\Trim()
* #Filter\StripNewlines()
* #Assert\NotBlank(message="email.error")
* #Assert\Email(message="email.error")
* #Assert\Length(min="6", max="150", minMessage="email.error", maxMessage="email.error")
* #Encrypted
*/
private $email;
Using Symfony 2.3
I believe Symfony\Component\Validator\Constraints\EmailValidator class is what you're looking for. Check source code
Symfony 2.3 Email validator uses the PHP var filter method
$valid = filter_var($value, FILTER_VALIDATE_EMAIL);
Which the internet leads em to believe uses similar to the following (ridiculous) regex (broken into multiple lines for readability)
^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?
\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}#)(?:(?:[\x21\x23-\x27\x2A\x2B\
x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\
x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\
x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:
\x5C[\x00-\x7F]))*\x22)))*#(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]
+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[
(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(
?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)
))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(
?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?
)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])
|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$
So make of that what you will.
In short, the local part of the email address is too long.
I'm not sure which part of regex decides that though.

How to enable Auto Complete in PHPStorm for CodeIgniter framework

In CodeIgniter Project, I've normally use following commands to execute sql.
$res = $this->db->select('*')
->from('customer')
->where('customer.id', $id)
->get();
But unfortunatly my PHP Storm(5.0) didn't support multiple autocomplete(I don't know how to say this)
For example in netbeans If I typed
$res = $this->db->select('*')->
It will auto pop up the rest of the function. But In PHPStorm It didn't wokring.
Its working first level auto complete only.
download https://github.com/topdown/phpStorm-CC-Helpers/releases
Mark as Plain Text
/system/core/Controller.php
/system/core/Model.php
/system/database/DB_active_rec.php
Then Extract the downloaded archive, copy it to your project root
That's all
Mifas links do the same too though
Answering to a very old but still pertinent question -
I found a better solution herein - http://validwebs.com/346/code-completion-for-codeigniter-in-phpstorm/ and coincidentally it is from the same author/project owner Jeff Behnke.
Quoting from therein which should be read in continuation of the answer by Sabir -
Mark as Plain Text
/system/core/Controller.php
/system/core/Model.php
/system/database/DB_active_rec.php
Marking those files as plain text stops phpStorm from indexing them as
sources.
I consider the solution in the link better because it explains the rationale behind the steps performed.
It additionally explains how we can achieve code completion in views and fix for undefined vars.
Quoting once again from the original source for easy reference and preservation herein :
Code Completion in Views and fixing undefined vars.
Example controller code.
public function index()
{
// Example view vars
$data['test'] = 'Testing vars in CodeIgniter! This is from $data["test"].';
$this->load->view('welcome_message', $data);
}
We added a data array to the view the CI way. Each index in the array
is another variable.
The view…
In phpStorm $test will be highlighted as an undefined var. To fix this
we use phpDoc annotations.
<p style="font-weight: bold;">
<?php
/**
* $data array holds the $test value
*
* #see Welcome::index()
* #var Welcome $test
*/
echo $test;
?>
</p>
Documenting this way not only fixes the phpStorm error/warning but
also gives us documentation popup for $test. Also the #see will link
to the location it was created, in this case index method in the
Welcome class.
The var is now defined and shows it is.
Ctrl+ Click on this method link will bring you right to the method
where $test is defined.
Herein are a few discoveries of my own while adding customisations to my project:
If you want your custom application libraries from CI to be available for auto-completion as well then there are these 2 scenarios which may be helpful :
1. For custom extended libraries such as MY_Upload extending the CI_Upload class
Replace #property CI_Upload $upload with #property MY_Upload $upload in CI_phpstorm.php
This shall make all the class variable and function names of MY_Upload available for auto-completion in addition to that of CI_Upload.
2. For completely custom libraries written from scratch within the CI application -
For e.g. to enable auto-completion from Custom_Library.php residing in the application/libraries folder, you need to add to the php doc in CI_phpstorm.php #property Custom_Library $custom_library

Code completion for CodeIgniter with zend studio not working

Ok so i tried doing what this post says about adding code completion to zend studio, even with the libraries added code hinting/completion still fails to show. As my libraries are growing it's becoming more important to have this feature as i'm starting to forget what my methods were actually designed for or what there called. from within a controller, model maybe even view i would like to have it show after typing $this->router->(show completion) as an example. I have also added application/libraries path for my custom made libraries and they too wont show.
I have done a bit off google searching but most just say to do what the above post says. I attempted to try /* #var $var Class */ but wasnt able to assign it with a property eg. /* #var $this->router CI_Router */ only a standard variable..
This was solved simply by doing comment as such
/**
* #var CI_Loader
*/
$load
and not just doing
/* #var ........ */

Resources