code igniter extend show_error - codeigniter

I implemented a rollback mechanism for my php execution so if an error occurs it will pop a stack and undo actions. How can I add this hook so my function is called anytime show_error is used?

Actually there is no such hook available.You need to hack it.
Modify the function "show_error()" in CI_Exceptions class (File: system/libraries/Exceptions.php) as per your Requirement.
This should be a reference to start with.
Update:
You should extent CI_Exceptions rather then modifying in-place.

Related

Create custom RxJs Subject

Question
Is there an official recommended way to create a custom RxJs Subject?
Use Case
I have a need for a QueueSubject, i.e. a Subject that queues all values passed to its next method until there is a subscriber. This is different from the built-in ReplaySubject because the ReplaySubject does not clear its buffer upon a subscription.
What I have learned so far
An exact implementation of what I need is available in this GitHub project by James Pike. The reason for my question despite this perfectly available solution is that the _subscribe method is an internal method. It is even marked as #deprecated, therefore if a linter is used, a linter rule exception needs to be added to the class to suppress the deprecation warning.
I did not find anything in the documentation about how to create a custom Subject.
You can use any Subject implementation as a reference for your own custom one, for example this one on Github.
Concerning _subscribe: You can override it with your custom class, but never call it directly from an outside consumer class (this is why it is annotated with #deprecated). The function is called by the Subject class internally following the Template Method Pattern.
In summary: Your linked implementation looks valid to me.

Avoid function duplication of dump function by psysh

I am developer of imi-conrun and have a problem: We use the psySh package we would like not to drop and defines the global scope function "dump" and have to initialize the Contao core which defines the global scope function "dump" as well without checking if the function is registered and then crashes.
Is there any possibility to only remove the dump function from psySh without making a fork?
I think there is no real solution for this.
In the end it turn's out I do not need PsySH - so I removed it - problem solved.
Might make the suggestion to Contao to not blindly defined the dump function without a function_exists() call
On the other hand I could ensure that Contao is loaded first, then PsySH and thus would not define the dump() function again which would mean to run the composer autoload before the Contao init.
TL;DR: global name space functions are bad.

Any way to dispatch a closure in laravel 5?

In laravel 4, I could push a closure onto the queue with queue::push(function...), but this no longer works in laravel 5. Instead, it appears that I have to make a custom Job class for every function that I want to push onto the queue.
Since the functions I want to be pushing are only a couple of lines long, and are only ever used in exactly one place, it really seems like a waste of time and space to be writing up a full class for every case.
The best "solutions" I can currently think of, are to either have a helper function that uses PHP's reflection methods to dynamically generate a new class when called, or to have generic job that accepts a closure as parameter, i.e. dispatch(new ClosureJob(function(){...}));
These seem less than ideal to me. Is there another way to do this? Or am I going to have to implement one of these?
As of Laravel v5.7 you can queue an closure like this:
$podcast = App\Podcast::find(1);
dispatch(function () use ($podcast) {
$podcast->publish();
});
Docs:
https://laravel.com/docs/7.x/queues#queueing-closures
However it is strongly recommended to use a dedicated job class to improve your code quality and for the sake of a better maintenance of your application. Think of you want to check what tasks are left in queue, or want to control on which queue/connection the particular code should run at.
Therefore you need a dedicated job class:
https://laravel.com/docs/5.7/queues#creating-jobs
I'd say that writing a dedicated class is pretty much the Laravel standard and this is what you should align to.
I've accomplished this by relying on the OpisClosure library. Extend the class as so:
class QueueableClosure extends SerializableClosure
{
public function handle() {
call_user_func_array($this->closure, func_get_args());
}
}
Then use it like this:
Queue::push(new QueueableClosure(function(){
Log::debug("this is the QueueableClosure in action.");
}));
N.B. See the comment below from #Quezler about possible limitations!
https://laravel.com/docs/5.0/queues#queueing-closures says:
You may also push a Closure onto the queue. This is very convenient for quick, simple tasks that need to be queued:
Pushing A Closure Onto The Queue
Queue::push(function($job) use ($id)
{
Account::delete($id);
$job->delete();
});
However, my guess is that you're using Laravel 5.3+, because https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0 says:
Queueing Closures is no longer supported. If you are queueing a Closure in your application, you should convert the Closure to a class and queue an instance of the class.

Joomla - How to override component controller?

I want to override a controller inside a component
ie;
File path : components/com_test/controllers/test.php
how to override test.php ?
As Pritesh mentioned, you can't*.
I can see a couple of ways to achieve the result:
You can create a new controller which extends your test.php controller, and invoke that instead; in order to achieve this, the controller must never use JPATH_COMPONENT and you'll have to override the view as well to point to the right component.
Add a special task to your view, and intercept it with a system plugin in OnAfterRoute(). You won't be touching the original controller, but your plugin will fire before the original controller, so it can take action, manipulate input and output, and eventually avoid invoking the original controller altogether.
--
if editing the original controller could seem like an option, please disregard it: the original component will be updated from time to time and you'd be entering a maintenance nightmare.
Very often I have to achieve just this result. And 90% of the time I achieve this in a system plugin. In case of improvements, I contribute the code back to the original developer, who usually integrates the features in their next release. Don't forget to let the original developers know, you'll help improve their products and save yourself time.
Actually you can override quite a large part of the core, by loading the class before Joomla does; this limits to non-core classes but it is feasible. That's what I was referring to in n.2
we can not override the controller and model in joomla we will override only views of the component.

codeigniter: accessing a callback from config/form_validation.php config file

Callback functions are not executing from my form_validation config file when called upon. Am I correct when assuming the reason for the non-execution is due to the location of the callback function? For the callback to execute, it will have to be placed inside the config file or have the $config array placed into the controller file? If that is the case, what avenue do you suggest I take or do something completely different to accomplish this?
The more I learn about CI the more I want to use its clean structure.
-Thank You,
Rich
Callback functions are placed within the same controllers or models from which they are called in form validation. Maybe in this case you need to put your callback function into a global controller liker MY_controller.php.

Resources