Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public API for OC6+ (includes AppFramework) #4459

Merged
merged 106 commits into from
Sep 30, 2013
Merged

Conversation

DeepDiver1975
Copy link
Member

Public API
The basic concept of the public api is based on following criteria:

  • the API is built upon interfaces in the public namespace \OCP
  • the interface IServerContainer acts as the central factory to retrieve the implementations of the interfaces
  • no public api class is allowed to use any private interfaces (as parameter, return type, exception or base class)
  • OC::$server acts as the unique entry point to retrieve the IServerContainer implementation

The public API requires further enhancement - which is documented in #4863

AppFramework
This pull request contains an adopted sub set of the AppFramework wrapped with an public interface.
At this point in time the public access is very limited and will be extended in the upcoming days.

FYI: @karlitschek @butonic @Raydiation @bartv2 @icewind1991

@DeepDiver1975
Copy link
Member Author

@Raydiation have a look 😉

* Should you find yourself in need for more methods, simply inherit from this
* class and add your methods
*/
class API {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this be unneeded once we have the proper DI container to access to oc apis? since this is basically a wrapper around the static apis

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this be unneeded once we have the proper DI container to access to oc apis?

for sure - I'm not yet finally where I want to be - but thanks for keeping a close eye

@tanghus
Copy link
Contributor

tanghus commented Aug 26, 2013

Will this make it into oC6?

@DeepDiver1975
Copy link
Member Author

Will this make it into oC6?

thats why its named ' ... for oc6+' 😉

@tanghus
Copy link
Contributor

tanghus commented Aug 26, 2013

Will this make it into oC6?

thats why its named ' ... for oc6+' 😉

I figured that much, but now that we have official release dates, priorities
could have changed :)

Will you make a post about what needs to be changed besides the namespace once
done? It would be great to be able to port ASAP.

@DeepDiver1975
Copy link
Member Author

The fact that OC_ should not be used is pretty old. Actually it gas been announced more that a year ago as we introduced the name space OCP.

With oc6 it will be enforced to not use OC_

Anything which is in OCP today will stay there. 

Any new api will be defined as interfaces and a container/factory is to be used to retrieve the implementation. 

What comes together with this pr is the core portion of the app framework as developed by Bernhard in the past month. 

Regarding oc6: among other pieces this pr is the reason for pushing out oc6

@DeepDiver1975
Copy link
Member Author

I've made an HttpMiddleware implementation for contacts. Currently the only thing it does, is to set the proper status code after an exception, but has turned out to be quite useful https://github.com/owncloud/contacts/blob/master/lib/middleware/http.php

Thanks for the pointer - I'm currently uncertain if we shall allow public access to the middleware interfaces

@Raydiation

@tanghus
Copy link
Contributor

tanghus commented Aug 26, 2013

I'm currently uncertain if we shall allow public access to the middleware interfaces

Yes, the current implementation allows you to remove all security checks. Otherwise I find it very handy to be able to add your own middleware.

@BernhardPosselt
Copy link
Contributor

Middleware should defenitely be publicly available and changeable. We just have to make sure that people use it right by documenting it properly

@tanghus
Copy link
Contributor

tanghus commented Sep 25, 2013

Thinking about it I might had been able to get the error from the body of the ajax response. Printing an error page when in debug mode is a really stupid idea, when most of the requests are ajaxy.

OC_VCategories => OC\Tags. Public interface and getter in server container
@ghost
Copy link

ghost commented Sep 25, 2013

Test passed.
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/1220/

@ghost
Copy link

ghost commented Sep 27, 2013

Test passed.
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/1250/

@tanghus
Copy link
Contributor

tanghus commented Sep 27, 2013

@DeepDiver1975 have you had a chance to look at the Identifier "urlParams" is not defined. error?

I will look into making the server container testable. Hopefully I'll push it later today.

@tanghus
Copy link
Contributor

tanghus commented Sep 27, 2013

#1 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\Server->OC\{closure}(Object(OC\Server))
#2 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\Server))
#3 /home/tol/owncloud/core/lib/appframework/utility/simplecontainer.php(20): Pimple->offsetGet('Request')
#4 /home/tol/owncloud/core/lib/server.php(134): OC\AppFramework\Utility\SimpleContainer->query('Request')
#5 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(65): OC\Server->getRequest()
#6 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#7 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#8 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(85): Pimple->offsetGet('Request')
#9 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#10 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#11 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(90): Pimple->offsetGet('SecurityMiddlew...')
#12 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#13 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#14 /home/tol/owncloud/core/lib/appframework/utility/simplecontainer.php(20): Pimple->offsetGet('MiddlewareDispa...')
#15 /home/tol/owncloud/contacts/lib/dispatcher.php(40): OC\AppFramework\Utility\SimpleContainer->query('MiddlewareDispa...')
#16 /home/tol/owncloud/contacts/appinfo/routes.php(35): OCA\Contacts\Dispatcher->__construct(Array)
#17 [internal function]: OC_Router->OCA\Contacts\{closure}(Array)
#18 /home/tol/owncloud/core/lib/router.php(127): call_user_func(Object(Closure), Array)
#19 /home/tol/owncloud/core/lib/base.php(650): OC_Router->match('/apps/contacts/...')
#20 /home/tol/owncloud/core/index.php(30): OC::handleRequest()
#21 {main}

@DeepDiver1975
Copy link
Member Author

@tanghus can I see the code? Is it pushed to the contacts repo?
Might be best I just debug this

@tanghus
Copy link
Contributor

tanghus commented Sep 27, 2013

@DeepDiver1975 When registering middleware in https://github.com/owncloud/contacts/blob/oc_appframework/lib/dispatcher.php#L36

Still WiP while adjusting to this PR.

And this bt is more correct I think

#0 /home/tol/owncloud/core/lib/server.php(45): Pimple->offsetGet('urlParams')
#1 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\Server->OC\{closure}(Object(OC\Server))
#2 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\Server))
#3 /home/tol/owncloud/core/lib/appframework/utility/simplecontainer.php(20): Pimple->offsetGet('Request')
#4 /home/tol/owncloud/core/lib/server.php(134): OC\AppFramework\Utility\SimpleContainer->query('Request')
#5 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(65): OC\Server->getRequest()
#6 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#7 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#8 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(85): Pimple->offsetGet('Request')
#9 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#10 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#11 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(90): Pimple->offsetGet('SecurityMiddlew...')
#12 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#13 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#14 /home/tol/owncloud/core/lib/appframework/utility/simplecontainer.php(20): Pimple->offsetGet('MiddlewareDispa...')
#15 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(129): OC\AppFramework\Utility\SimpleContainer->query('MiddlewareDispa...')
#16 /home/tol/owncloud/contacts/lib/dispatcher.php(36): OC\AppFramework\DependencyInjection\DIContainer->registerMiddleWare(Object(OCA\Contacts\Middleware\Http))
#17 /home/tol/owncloud/contacts/appinfo/routes.php(332): OCA\Contacts\Dispatcher->__construct(Array)
#18 [internal function]: OC_Router->OCA\Contacts\{closure}(Array)
#19 /home/tol/owncloud/core/lib/router.php(127): call_user_func(Object(Closure), Array)
#20 /home/tol/owncloud/core/lib/base.php(650): OC_Router->match('/apps/contacts/...')
#21 /home/tol/owncloud/core/index.php(30): OC::handleRequest()
#22 {main}

@DeepDiver1975
Copy link
Member Author

Nice finding!
While initiating the request object it tries to get the urlParams from the container
https://github.com/owncloud/core/blob/appframework-master/lib/server.php#L45

I have to double check where this parameter is coming from

@DeepDiver1975
Copy link
Member Author

There it is - looks like wrong initialization order
https://github.com/owncloud/core/blob/appframework-master/lib/appframework/app.php#L50

@DeepDiver1975
Copy link
Member Author

registerMiddleware not lazy enough

@DeepDiver1975
Copy link
Member Author

@tanghus can you please retest? THX

@tanghus
Copy link
Contributor

tanghus commented Sep 27, 2013

Now with a warning too ;)

PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php on line 136
PHP Stack trace:
PHP   1. {main}() /home/tol/owncloud/core/index.php:0
PHP   2. OC::handleRequest() /home/tol/owncloud/core/index.php:30
PHP   3. OC_Router->match() /home/tol/owncloud/core/lib/base.php:650
PHP   4. call_user_func() /home/tol/owncloud/core/lib/router.php:127
PHP   5. OC_Router->OCA\Contacts\{closure}() /home/tol/owncloud/core/lib/router.php:127
PHP   6. OCA\Contacts\Dispatcher->__construct() /home/tol/owncloud/contacts/appinfo/routes.php:332
PHP   7. OC\AppFramework\DependencyInjection\DIContainer->registerMiddleWare() /home/tol/owncloud/contacts/lib/dispatcher.php:36
PHP   8. array_push() /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php:136
 {index} Identifier "urlParams" is not defined.

And still not lazy enough ;)

#0 /home/tol/owncloud/core/lib/server.php(45): Pimple->offsetGet('urlParams')
#1 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\Server->OC\{closure}(Object(OC\Server))
#2 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\Server))
#3 /home/tol/owncloud/core/lib/appframework/utility/simplecontainer.php(20): Pimple->offsetGet('Request')
#4 /home/tol/owncloud/core/lib/server.php(134): OC\AppFramework\Utility\SimpleContainer->query('Request')
#5 /home/tol/owncloud/core/lib/appframework/dependencyinjection/dicontainer.php(69): OC\Server->getRequest()
#6 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OC\AppFramework\DependencyInjection\DIContainer->OC\AppFramework\DependencyInjection\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#7 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#8 /home/tol/owncloud/core/lib/appframework/utility/simplecontainer.php(20): Pimple->offsetGet('Request')
#9 /home/tol/owncloud/contacts/lib/controller.php(39): OC\AppFramework\Utility\SimpleContainer->query('Request')
#10 /home/tol/owncloud/contacts/lib/dispatcher.php(54): OCA\Contacts\Controller->__construct(Object(OC\AppFramework\DependencyInjection\DIContainer), Object(OCA\Contacts\App))
#11 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(122): OCA\Contacts\Dispatcher->OCA\Contacts\{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#12 /home/tol/owncloud/core/3rdparty/Pimple/Pimple.php(83): Pimple::{closure}(Object(OC\AppFramework\DependencyInjection\DIContainer))
#13 /home/tol/owncloud/core/lib/appframework/app.php(51): Pimple->offsetGet('GroupController')
#14 /home/tol/owncloud/core/lib/public/appframework/app.php(79): OC\AppFramework\App::main('GroupController', 'getGroups', Array, Object(OC\AppFramework\DependencyInjection\DIContainer))
#15 /home/tol/owncloud/contacts/appinfo/routes.php(333): OCP\AppFramework\App->dispatch('GroupController', 'getGroups', Array)
#16 [internal function]: OC_Router->OCA\Contacts\{closure}(Array)
#17 /home/tol/owncloud/core/lib/router.php(127): call_user_func(Object(Closure), Array)
#18 /home/tol/owncloud/core/lib/base.php(650): OC_Router->match('/apps/contacts/...')
#19 /home/tol/owncloud/core/index.php(30): OC::handleRequest()
#20 {main}

@karlitschek
Copy link
Contributor

👍

@ghost
Copy link

ghost commented Sep 30, 2013

Test passed.
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/1280/

@DeepDiver1975
Copy link
Member Author

We decided to merge this now into master in order to get this going regarding OC6 feature freeze.
Further api interfaces can still be added - THX

DeepDiver1975 added a commit that referenced this pull request Sep 30, 2013
Public API for OC6+ (includes AppFramework)
@DeepDiver1975 DeepDiver1975 merged commit 480aeb8 into master Sep 30, 2013
@DeepDiver1975 DeepDiver1975 deleted the appframework-master branch September 30, 2013 11:11
@tanghus tanghus mentioned this pull request Sep 30, 2013
@lock lock bot locked as resolved and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants