I want to add my own oauth provider. After reading this, I added a PhabricatorFoobarAuthProvider.php in phabricator/src/applications/auth/provider/ and added a PhutilFoobarAuthAdapter.php in libphutil/src/auth/ and then executed arc liberate seprately. I expected to see Foobar provider to show in this page: localhost/auth/config/new but I didn't. What need I do to reach the goal? Am I forgetting some steps? Thanks.
I use `install_ubuntu.sh` to install phabricator. The layout is like this:
phab
....install_ubunut.sh
....arcanist/
....libphutil/
....phabricator/
So the english is a tiny bit broken but i'll answer this the best that I can. What I assume you are trying to do is figure out is "how can I add my own Oauth provider?". In doing so you came across this magical function that seems to be doing something but your not sure what.
The PhutilClassMapQuery is essential to understanding phabricator and arcanist. If you grep -R "PhutilClassMapQuery" . you will find around 100 different places that it is used. Every place that this is used you as the user are able to load in your own classes that integrate seamlessly with the Phabricator application.
I'll use PhabricatorAuthProvider as an example. If you look here you will notice that this is an abstract class. What the that function does is say load in every class that extends the current class of PhabricatorAuthProvider. So as an example if you look here you can see that this class provides Persona authentication and it does that simply by implementing the needed functions.
I am not going to go through the rest of this but you should be able to figure out the rest based on the above and using this link which shows you how to load your classes into Phabricator.
Hope you enjoy. Phabricator is some of the nicest PHP code that you will find.
Related
How to create router file for a component of joomla. I am using Sef
url in particular
I was having the same issue and after trawling through the internet and only ever coming across answers like the one seen here ("see the documentation") which is really unhelpful in my opinion and of all the documentation that page is the most unhelpful.
Anyway I firstly ended up giving up on the "component router", I could get it to easily work to build routes but found that it wouldn't parse anything and without having both working, it was pointless continuing.
In the end I decided going down the plugin path was the answer and found this really good plugin here from Daniel Calviño Sánchez.
I then ended up finally coming across some joomla documentation here that IS perfect and will get you exactly where you need to go.
I personally think that the joomla router needs alot of work and saw there are lots of ideas from people wanting it upgraded. I found using a plugin in the end was the easiest path and was the better solution all round.
I would be happy to discuss with anyone as to why my component router wouldn't call its parse method as if that actually worked, it would've been my first choice.
Hope this helps.
Unfortunately documentation didn't provide a way to register my router so I found an alternative solution.
The router.php is actually a Joomla\CMS\Router\SiteRouter
You can use the $this variable, even if you think you're not within a class.
This can be checked by performing var_dump($this)
There are two methods that can be used.
$this->attachBuildRule(function(){
// build rule code
});
$this->attachParseRule(function(){
// parse rule code
});
If you are using an object implementing RouterInterface the callbacks are the following
$this->attachBuildRule([$myRouter, 'build']);
$this->attachParseRule([$myRouter, 'parse']);
The methods expect a callable and a STAGE, see Router::PROCESS_* constants in namespace Joomla\CMS\Router
If you are using PHPStorm you can write the following code for assistance:
/**
* #var $this Joomla\CMS\Router\SiteRouter
*/
Check out this documentation .
It describes very precisely how to create a Route and how the Routing works in Joomla.
Also check out com_content/router.php as an example
In this stackoverflow post,
Get the query executed in Laravel 3/4
Ricardo Rossi provided a great answer about using Kint and a custom class to easily output information about a Laravel query created using the query builder.
I was able to setup Kent using composer but am new to Laravel and haven't used PHP since version 4.
Could someone please provide an example describing how to create a class which can then be called from anywhere. In his example, Ricardo says he uses "DBH::q()".
At the moment, I'm stuck requiring common files just like in good old PHP4 days.
Thanks
You likely want to use psr-0 auto loading with a namespaced class. Here's a post on setting up laravel which says how to do that.
If I understand your question correctly you are asking how to go about using the following syntax DB::q() using your own custom class...
Laravel uses Facades throughout its design which enables you to access classes from anywhere in your app using static style syntax (e.g. Input::get() or Route::get()). I note Fideloper has also provided an answer to your question... He has an excellent tutorial about how to wrap your own custom class in a Facade so you can use this syntax for your own classes and also sidestep the need to inject the dependency in any class that uses it (i.e. once set up correctly it can be called upon anywhere in your app).
Fideloper tutorial is here...
Hope that helps - Good luck
I've been creating WordPress plug-ins for some months now and I have developed a set of "base classes" (most are abstract classes but not all of them) that I use with the plug-ins (some are used with all plug-ins, others are used when a plug-in needs the specific thing the class provides - maybe an admin screen or a button on the visual editor or whatever).
This, of course, works great BUT if I update one or more base classes to add some new functionality then if someone has more than one of my plug-ins installed it is very possible for one or more of those plug-ins to crash.
This is because if a plug-in using an older version of the updated class(es) loads earlier then it "reserves" that name and the others that require the updated class don't have the functionality/fix/etc.
I've tried "nice" solutions but the only thing I can get to work reliably is to change the actual base class names for each plug-in, which is far from ideal.
Namespaces obviously work but can't be used because so many popular hosting companies are using 5.2x versions of PHP (probably why WordPress doesn't require 5.3 either)
I tried to dynamically create the class names and to use class factories but they didn't work or didn't overcome the need to rename all the base classes. I even tried (although I didn't expect it to work but you never know with PHP):
class childClassName extends $parentClassName
This situation can't be that unusual (do people really rewrite everything from scratch everytime and/or use distinct class names) but I can't find a solution and I can't think of an elegant one. It isn't even a WordPress issue, multiple applications using common base classes within a company would have the same problem.
I also can't just force everyone to upgrade all their plug-ins every time because it may crash before they can and I'm not sure it's reasonable for me require that of them or even that I can personally update and re-test, every time, every one of the what's now almost 10 plug-ins with more in the future.
My currect best solution is to use factories to create all base classes and to put tokens in my base classes that I can do a global search and replace on so that the class names are unique for each plug-in; note the replaceable tokens alone would work.
Is there some PHP code that will allow me to achieve a simple, easy solution to this common class name conflict issue?
========================================
It doesn't look like anyone knows how to do this in PHP, maybe it can't be done, so I went with the way I mentioned above.
I thought I'd put it here because this is what I ended up with that works well, if not what I had hoped, and maybe it can help others:
I added tokens to the base class names, for example:
class someBaseClass[TokenNameGoesHere] (I used [ReplaceWithVersionNumber])
also
class someChildClass extends someBaseClass[TokenNameGoesHere]
I created a method called createNewClass and passed the class name (as a string) and any parameters to pass to the new class (in an array).
I also passed information like the token value being used in the application (version number in my case) and the namespace (to be used instead of the token value if I can use PHP 5.3 and above).
I then used reflection to create the class. While reflection is obviously slower I found that I didn't have that many times when I needed to use createNewClass so the trade off of ease of remembering and increased clarity won out.
$reflectionOfClass = new \ReflectionClass($desiredClassName);
$newObject = $reflectionOfClass->newInstanceArgs($ParametersToPass);
Where $desiredClassName is built from the class name and the other parameters: version and namespace in my case.
Then, everywhere I wanted to create a base class object I'd use:
$myNewObject = $this->createNewObject("someBaseClass", other parameters);
When I copied the class library over for a new application I just did a massive search and replace of the token with what I wanted to replace it with in all the files. It could be version number or even an empty string if I don't have to worry about clashing with other versions of my class library like I do with WordPress plug-ins.
It was pretty easy to do and works great although going back through and inserting the tokens in was tedious.
It all could, of course, be done with just tokens but I didn't want to have to remember to do put suffixes on the names and which token name I was using and whatnot.
I hope that helps someone and if anyone has a better way (which to me means less code modification and more code clarity) I'd love to hear about it.
Not sure if you've found a proper solution to your question yet. I'm dealing with the same problem and my approach (not perfect, but does what I need) would be this one:
Create a class alias of your reusable class from a variable, like this:
$aliasclass = $really_unique_prefix."_Prefix_MyPlugin_Class";
class_alias("Prefix_MyPlugin_Class", $aliasclass);
new $aliasclass();
Hope it helps!
Yes namespace is perfect solution.
If php could have provided way to unload / load classes problem could have be easily addressed. But again you need to relink / instantiate your other depended active plugins so as to used object of new classes, this involves deactivation and activation of existing plugins.
With same thought I can think of this solution, you very well know you have 1,2,3 .. n plugins using X class. 1 & 2 plugins are using older version of X and you are about to install / update plugin 3 with newer version of X. Deactivate all your plugins & first activate plugin (3) which has your latest features/version of class X, later activate all others.
$all_plugins = array(
ABSPATH.'wp-content/plugins/plugin_1/index.php',
ABSPATH.'wp-content/plugins/plugin_2/index.php'
......
ABSPATH.'wp-content/plugins/plugin_n/index.php'
);
if (class_exists('X') && X::version < currentXVersion) {
deactivate_plugins($all_plugins);
$plugin_3_lastest_class_X = ABSPATH.'wp-content/plugins/plugin_3/index.php';
array_unshift($all_plugins, $plugin_3_lastest_class_X);
activate_plugins($all_plugins);
}
*provided if its ok to deactivate / activate your plugins & you don't modify signature of existing functions of class X, you can add new functions though.
Has anyone implemented something similar?
The problem I have is the fact that we're not using REST. The current plan is the following:
Create a controller called sync($modelName, $action) and throw all requests at that.
Create an interface called "syncable" and force models to implement it.
How it works:
GET http://localhost/sync?modelName=User&action=update&first_name=Peeter
This will look for a model named UserModel that implements the syncable interface. If found, update its parameters and update(); to db.
The syncable interface is to enable per-record actions. E.g. "Only record owner can update this record" or "Only admin can delete this record".
I wrote a fully function REST API framework into symfony 1.4. It supports JSON and JSONP. I've open sourced it, so you're welcome to use it. We're using it in production with a lot of traffic, so it's pretty stable and we've had great feedback from the consumers. It's really flexible and very fast to write API methods. We also have a documentation page that allows you to make test queries. It's one of the best API docs I've seen.
https://github.com/homer6/blank_altumo
See this (below) for an example of an API controller. This contoller only shows GET, but PUT, POST and DELETE are fully implemented.
https://github.com/homer6/blank_altumo/blob/master/htdocs/project/apps/api/modules/system_event/actions/actions.class.php
If you need help getting it going, I'm willing to spend a few minutes to explain its design or get it working for you.
Hope that helps...
I had the same issue with an app I'm working on, so I implemented a ChangeTracker that subscribes to my observable properties, and tracks any changes made. Then, at any later point, I can call something like:
viewModel.changeTracker.commit();
which is responsible for massaging my change objects into a format that the server understands, and ships it off for processing.
Here is a little fiddle demonstrating the idea. http://jsfiddle.net/ggoforth/pCX8c/2/
Note: I've had a string of days where I've been working till 3am so there may be a better way of doing this, and I'm just to exhausted to realize it :)
I have a controller that extends Zend_Controller_Action. It contains some actions that I need to give people access to via a RESTful MVC web service.
I've seen some articles that have told me to extend using a different class (Zend_Rest_Controller) but this seems to mean I need to override certain abstract methods and really I no use for most of them (I have my own functions that are quite specific!).
I've seen some code that I've meant to copy into my bootstrap.php and makes use of the FrontController. However, everything I've seen is awfully documented.
Can anybody give me an example that will just work for a controller called, say 'catalog' that contains two actions 'getRoot' and 'checkLatest'? (It should be simple yet I can't get anything to work and have a deadline tomorrow!)
Or else, perhaps point me in the right direction... (I've no idea how to troubleshoot this and see, for example, what URL I should be using to test or where the route I have setup is directing this... I've been looking at this, btw: http://techchorus.net/create-restful-applications-using-zend-framework)
Thanks a lot! :)
In the article that you mention you have a class:
class ArticleController extends Zend_Rest_Controller
Just like that example you should create a CatalogController. The different methods that you require should be sent as parameters HTTP GET parameters. The getAction should perform the operations (depending on your request) and return a collection of of results in the response depending on different possibilities such as "getRoot" or "checkLatest" as you mention.