Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Prepare for zend-mvc v3 #329

Conversation

weierophinney
Copy link
Member

@weierophinney weierophinney commented Apr 18, 2016

For the v3 release, we will be pulling in a smaller set of components out-of-the-box. These are primarily defined by zend-mvc, but also include:

  • zend-config (used by the zend-modulemanager ConfigListener by default) (zend-modulemanager now defines the zend-config requirement)
  • zend-skeleton-installer for prompting for optional packages/capabilities.
  • zend-component-installer, to automate registration of components as modules.

Additionally, we plan to leverage Composer for all autoloading, which means:

  • we can register a PSR-4 entry for the Application module, and remove one directory level;
  • the Application module no longer needs to setup autoloading.

For a minimal application, we do not want or need internationalization. As such, this patch also removes all translations and calls to translate strings in templates. We can explore re-adding them later, or offering an alternative skeleton application with more default features (including i18n, forms, databases, etc.).

At the time of submission, this patch provides a working skeleton with the current zend-mvc develop branch.

Testing

If you wish to test:

  • Clone the repository locally
  • Enter the cloned repository
  • Switch to the develop branch: git checkout -b develop origin/develop
  • Apply the changes: wget https://patch-diff.githubusercontent.com/raw/zendframework/ZendSkeletonApplication/pull/329.patch && git am 329.patch (or, if you use the hub command: git merge https://github.com/zendframework/ZendSkeletonApplication/pull/329)
  • Execute composer install

If you want to use vagrant:

  • Start it: vagrant up
  • Run composer within it: vagrant ssh -c 'cd /var/www ; composer install'
  • Start testing

If you want to use docker:

  • Build and run it: docker-compose up -d --build
  • Run composer within it: docker-compose run zf composer install
  • Start testing.

Please report any issues you notice or provide constructive feedback via comments to this pull request, or issue a pull request against my branch.

TODO

Installer

  • Prompt for caching
    • will install zend-cache
  • Prompt for console
    • prompt should indicate users should migrate to zf-console
    • will install zend-mvc-console
  • Prompt for database
    • will install zend-db
  • Prompt for forms
    • will install zend-form
  • Prompt for i18n
    • will install zend-mvc-i18n
  • Prompt for JSON
    • will install zend-json
  • Prompt for logging
    • will install zend-log
  • Prompt for PSR-7 middleware dispatcher
    • will install zend-psr7bridge
  • Prompt for sessions
    • will install zend-session
  • Prompt for testing facilities
    • will install zend-test as dev requirement
  • Prompt for plugins
    • will install zend-mvc-plugin-*
  • Prompt for zend-di integration
    • will install zend-servicemanager-di

In each case, this should register the module(s) with the application, so that the user does not need to be prompted twice.

Documentation

  • ModuleRouteListener is removed from the skeleton. This won't affect existing users, but will affect experienced users who originally relied on it being active in new skeleton projects.
  • The /[:controller][/:action]] route was removed from the skeleton. Again, it will not affect existing users, but will affect experienced users who originally relied on it being active in new skeleton projects.

These items have been added to the maintainers wiki.

Updates

  • 2016-05-17: added TODO list tracking installer and documentation tasks remaining.

Close #293

- Removed configuration for non-default zend-mvc features, including
  translation, forms, etc.
- Removed translation files.
- Removed translation within templates.
- Re-organized Application module as a PSR-4 directory, and added an autoloading
  rule for it.
- Adds a `VERSION` constant to the `Application\Module` class; this is now
  consumed by the home page template.
- Updates dependencies to pick up zend-view 2.6.7 and zend-router 3.0.1.
- Updates the base application config to include the router and validator
  components.
- Simplifies the autoloader to *only* use composer.
@weierophinney weierophinney added this to the 3.0.0 milestone Apr 18, 2016
@weierophinney
Copy link
Member Author

This is a WIP; do not merge until zend-mvc is tagged and/or zendframework is tagged!


if (!class_exists('Zend\Loader\AutoloaderFactory')) {
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
if (! class_exists('Zend\Mvc\Application')) {
Copy link
Member

Choose a reason for hiding this comment

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

::class

Copy link

Choose a reason for hiding this comment

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

Why not move that code in index.php? Imo it will simplify things a little more.

@Ocramius
Copy link
Member

A few notes here:

  • not sure about translations, although they did make the skeleton MUCH fatter for very little gain. Including a translation module would be sufficient. Keeping the ->translate() calls would also be sufficient, for now.
  • I can't find direct references to Zend\Config in this code. Is the zend-modulemanager using class_exists()? If so, we should probably make this particular dependency usage explicit.
  • zend-component-installer I'm trying that nao \o/

@Ocramius
Copy link
Member

A few other notes:

@Ocramius
Copy link
Member

Confirmed: adding them to application.config.php is probably not needed, and it would expose the users to the process of configuring modules (possibly good):

ecf53c

@back-2-95
Copy link

Very nice, it looks very clear and I like the way other zend-components are registered as modules. Removing one directory level is also very nice. We developers are lazy and like every small thing which makes our lives easier.

For the skeleton, I would convert all array(...) to use short array syntax. Old arrays exists on config files and in the layout.phtml.

Thanks for good work guys!

</div>
<div class="panel-body">
<p><?php echo sprintf($this->translate('If you need any help or support while developing with ZF2, you may reach us via IRC: %s#zftalk on Freenode%s. We\'d love to hear any questions or feedback you may have regarding the beta releases. Alternatively, you may subscribe and post questions to the %smailing lists%s.'), '<a href="irc://irc.freenode.net/zftalk">', '</a>', '<a href="http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists">', '</a>') ?></p>
<p><a class="btn btn-success pull-right" href="http://webchat.freenode.net?channels=zftalk" target="_blank"><?php echo $this->translate('Ping us on IRC') ?> &raquo;</a></p>
<p><?php echo sprintf('If you need any help or support while developing with ZF2, you may reach us via IRC: %s#zftalk on Freenode%s. We\'d love to hear any questions or feedback you may have regarding the beta releases. Alternatively, you may subscribe and post questions to the %smailing lists%s.', '<a href="irc://irc.freenode.net/zftalk">', '</a>', '<a href="http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists">', '</a>') ?></p>
Copy link
Contributor

Choose a reason for hiding this comment

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

s/beta release/this release

Copy link
Contributor

@samsonasik samsonasik Apr 19, 2016

Choose a reason for hiding this comment

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

s/the beta releases/this release

));
}
}
include 'vendor/autoload.php';
Copy link
Contributor

Choose a reason for hiding this comment

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

as no file_exists check, I think @ prefix ( @include usage ) should be provided as the error needs to be shown to user is the RuntimeException error

Copy link
Member Author

Choose a reason for hiding this comment

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

PHP will barf all over the place at this point anyways, and you'll get both an E_WARNING and the following RuntimeException. Essentially, I don't want to suppress errors or do additional error checking for something that represents a fundamentally broken install anyways.

@samsonasik
Copy link
Contributor

@weierophinney I created PR weierophinney#3 to your branch for some feedbacks above ( wording, ::class, short array syntax )


class Module
{
const VERSION = '3.0.0dev';
Copy link
Member

Choose a reason for hiding this comment

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

This is shameless advertising, but ocramius/package-versions deals with it, eventually :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's slick!

/me goes to add that in the next push...

Copy link
Member Author

Choose a reason for hiding this comment

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

DAMMIT, @Ocramius ... PHP 7 as the minimum requirement?!?!?! (now I understand the "eventually" comment, though...)

Copy link
Member

Choose a reason for hiding this comment

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

Hah, totally forgot about that, sorry :-)

Yeah, next time then :-P

@weierophinney
Copy link
Member Author

@Ocramius — some responses:

  • not sure about translations, although they did make the skeleton MUCH fatter for very little gain. Including a translation module would be sufficient. Keeping the ->translate() calls would also be sufficient, for now.

The translate() helper is part of zend-i18n, and would thus require installing zend-mvc-i18n as a dependency (which also brings in zend-i18n). We can certainly do that, but my thought is to have:

  • a base, minimal skeleton, with only the bare minimum necessary to create an MVC application, and then potentially add skeletons with more features.
  • an installer, ala zend-expressive, that allows you to opt-in to features:
    • "Do you want the console integration?"
    • "Do you want i18n integration?"
    • "Do you want to use zend-db?"
    • "Do you need caching?"
    • etc.

One consistent complaint I've heard is from developers who start with the skeleton, and then need to strip out a whole bunch of stuff they don't need. If we have a minimal base on which we can expand, we solve that problem.

  • I can't find direct references to Zend\Config in this code. Is the zend-modulemanager using class_exists()? If so, we should probably make this particular dependency usage explicit.

It's used by the ConfigListener of zend-modulemanager, which I discovered that when testing out the skeleton. At this point, I'm unsure if the dependency should go in:

  • zend-modulemanager (ConfigListener is technically optional, though)
  • zend-mvc (as it enables the ConfigListener by default)
  • the skeleton application

Thoughts?

  • zend-component-installer I'm trying that nao \o/

Interestingly, the Zend\Router and Zend\Validator entries in the application configuration were added by the component installer when I first did a composer install. 😄 (I'm very excited by this!)

@weierophinney
Copy link
Member Author

weierophinney commented Apr 19, 2016

@Ocramius — more responses:

  • Zend\Loader still seems to be required: what does it take to chop its head off?

It's currently required by zend-modulemanager, for autoloading modules that do not have autoloading setup. (See Zend\ModuleManager\Listener\ModuleLoaderListener.)

Since one goal is to have a clear and clean upgrade path, we currently need to keep that. What we could do, however, is deprecate the usage; the question is if we should do that in a 2.x series of zend-modulemanager, or in the v3 release.

If we do it in the 2.x series, we could emit a deprecation notice from Zend\ModuleManager\Listener\AutoloaderListener whenever it receives autoloader configuration, prompting the user to add autoloading configuration to their composer.json; we could even link to a documentation page detailing the various approaches.

Thoughts?

  • Zend\Http also required, but I see no diactoros: does that mean that PSR-7 support won't be there OOTB?

Out of the box, no, not for the minimal skeleton. zend-psr7bridge is listed as a suggested requirement for zend-mvc already, however, and the suggestion text indicates it should be installed if you plan to use PSR-7 middleware within your application.

Yes and no. zend-component-installer prompts you to add the component, but gives you the option of saying "no" (as well as saying, "remember my selection for all remaining components on this installation run). It also checks to see if the component is already listed, and, if so, will not prompt. My feeling is that components required by the base skeleton should be listed in the configuration as well, so that you only get prompted the first time you add a new component.

@weierophinney
Copy link
Member Author

For the skeleton, I would convert all array(...) to use short array syntax. Old arrays exists on config files and in the layout.phtml.

Noted; can't believe I missed that on the first pass through!

@Ocramius
Copy link
Member

The translate() helper is part of zend-i18n, and would thus require installing zend-mvc-i18n as a dependency (which also brings in zend-i18n). We can certainly do that, but my thought is to have:

  • a base, minimal skeleton, with only the bare minimum necessary to create an MVC application, and then potentially add skeletons with more features.
  • an installer, ala zend-expressive, that allows you to opt-in to features:
  • "Do you want the console integration?"
    • "Do you want i18n integration?"
    • "Do you want to use zend-db?"
    • "Do you need caching?"
    • etc.

Agreed, let's keep i18n out then.

  • I can't find direct references to Zend\Config in this code. Is the zend-modulemanager using class_exists()? If so, we should probably make this particular dependency usage explicit.

It's used by the ConfigListener of zend-modulemanager, which I discovered that when testing out the skeleton. At this point, I'm unsure if the dependency should go in:

It should probably live in the module-manager. The 95% use-case of the module manager is merging config.

Out of the box, no, not for the minimal skeleton. zend-psr7bridge is listed as a suggested requirement for zend-mvc already, however, and the suggestion text indicates it should be installed if you plan to use PSR-7 middleware within your application.

Fair enough. I feel like we should push further on this in future, but maybe not now.

Yes and no. zend-component-installer prompts you to add the component, but gives you the option of saying "no" (as well as saying, "remember my selection for all remaining components on this installation run). It also checks to see if the component is already listed, and, if so, will not prompt. My feeling is that components required by the base skeleton should be listed in the configuration as well, so that you only get prompted the first time you add a new component.

My thought here is that while the user may answer "no", he may actually learn that he will be prompted. Not having that is also fine, IMO, but we're committing post-install artifacts. Still: good for usability, let's keep it as-is, I'd say.

@Thinkscape
Copy link
Member

Out of the box, no, not for the minimal skeleton. zend-psr7bridge is listed as a suggested requirement for zend-mvc already, however, and the suggestion text indicates it should be installed if you plan to use PSR-7 middleware within your application.
Fair enough. I feel like we should push further on this in future, but maybe not now.

Would it be that crazy if the "installer" and skeleton was merged with zend-expressive-skeleton ?

If it was, there are possible cons:

  • People would still need to decide whether to go PSR7 or "legacy mvc", requires understanding what it is.
  • Increases package complexity slightly.

Pros:

  • Advertising: 3.0.0 equals the future version - expressive becomes integral part of new version.
  • Only one skeleton to maintain instead of two.
  • People actually start using PSR7 when they "default to ZF" or just want to try "the new ZF".
  • Because there's still a choice between PSR7 and "legacy mvc" in the installer, people can choose the latter and have somewhat easier migration path from ZF2.
  • Less legacy stuff. No need to wait for ZF4 or ZF3.1 or whatever else that cuts the cord.

Current blog posts and available docs do not clearly explain the PSR7 transition IMO. This would effectively solve the problem as ZF3 skeleton would give one clear choice. Through the "power of defaults" (default = expressive), the installer would be educating and promoting PSR7.

@samsonasik
Copy link
Contributor

I think for 'controllers' -> 'invokables' config, we can use factories and use Zend\ServiceManager\Factory\InvokableFactory ? and change Application\Controller\Index to Application\Controller\IndexController for the key.

@@ -0,0 +1,16 @@
FROM php:7.0-apache

RUN apt-get update \
Copy link
Member

Choose a reason for hiding this comment

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

Is this Dockerfile intended for use in production?

Copy link
Member Author

Choose a reason for hiding this comment

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

Most likely you would end up modifying it for production to include your application specific needs. The primary intent is to allow developers to start with a consistent development environment.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could split the command for make it more simple and add more things to docker cache even if it add more layers

Copy link
Member Author

Choose a reason for hiding this comment

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

This is doing exactly three things:

  • Ensuring we have the extensions necessary to run composer.
  • Ensuring the web server is configured correctly (enables mod_rewrite and changes the document root).
  • Installing composer.

I'm not sure we really need to simplify it further…

- Port 80 is already exposed by the parent container
- docker-composer defines the volume
- Per @Maks3w, added a `cd /var/www` command into the vagrant user's profile;
  simplifies running commands.
- Details various ways to install dependencies.
@Maks3w
Copy link
Member

Maks3w commented May 26, 2016

This is ok for me 👍

- zend-mvc is now at 3.0.0
- zend-test is now at 3.0.0
- zend-mvc-console is now at 1.1.10
- zend-mvc-i18n is now at 1.0.0
- zend-mvc-plugin-* are now at 1.0.0
- Instead of individual packages for each plugin.
@weierophinney
Copy link
Member Author

Status update

First, I've updated to stable versions of:

  • zend-mvc (3.0)
  • zend-test (3.0)
  • zend-mvc-console (1.1.10, which marks zend-mvc v2 as a conflict)
  • zend-mvc-i18n (1.0)
  • zend-mvc-plugins (1.0; see below)

This puts the pull request in a good position to be tagged once merged. However…

I've created a zend-mvc-plugins metapackage, to aggregate all official plugins, reducing the number of prompts by three. However, on experimentation, it appears that packages installed via a metapackage do not trigger plugins; instead, only the metapackage triggers the plugin.

The solution will be to allow the module and component keys to be arrays, which will allow zend-mvc-plugins to define the list of components for zend-component-installer to install. Until that is done, this PR cannot be merged.

- skeleton installer: Prefer ^1.0 or ^0.1.2
- component installer: Prefer ^1.0 or ^0.2
- organize optional packages by package name
- first package to define component installer metadata
@weierophinney
Copy link
Member Author

Status update

  • I've released zend-component-installer 0.2.0, which adds support for arrays of components, modules, and config-providers when defining packages.
  • I've released zend-skeleton-installer 0.1.1, which fixes a bug in the Uninstaller whereby the `composer.lock was not updated to reflect the removal of the skeleton installer package.
  • I've released zend-mvc-plugins 1.0.1, which updates the package to define an array of components for the component installer to inject into configuration.

At this time, this patch is finally ready to merge!

weierophinney added a commit that referenced this pull request Jun 2, 2016
@weierophinney
Copy link
Member Author

Pushed to develop for release with 3.0.0.

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.

9 participants