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

New Project Structure Proposal #466

Closed
kilip opened this issue Feb 18, 2018 · 5 comments
Closed

New Project Structure Proposal #466

kilip opened this issue Feb 18, 2018 · 5 comments

Comments

@kilip
Copy link
Collaborator

kilip commented Feb 18, 2018

New Installation Method

Current yawik installation method have a complex process to update, because we need to download latest yawik version and replace directory contents with a new yawik version from zip file. And we can't easily customize every yawik installation too, because every yawik installation have a same composer.json file.

By using composer and with proper project structure, we can simplify this install/update method and make every yawik installation to be fully customizable.

1. Skeleton Application

By creating a skeleton project every yawik installation can be customized easily, such as define additional requirements or library in composer.json:

// path/to/skeleton/composer.json
require: {
    "php": "^7.0",
    "ext-mongodb": "*",
    "alcaeus/mongo-php-adapter": "^1.0.0",
    "yawik/module-core": "^1.0",
    "toni/yawik-modern": "~1.0@dev"
}

Now install and update can be easily done by using composer install or update command.

2. Development Method

In order to support new installation method above, we need to make all yawik core modules (Core,Auth, Jobs, Organizations, etc.) installable from composer. Every core modules should have their own dependencies defined in composer.json file with psr4 autoload definition:

// path/to/yawik/module/Core/composer.json
{
    "name": "yawik/module-core",
    "require": {
        "zendframework/zend-mvc": "^3.0",
        "doctrine/doctrine-mongo-odm-module": "*",
        "hybridauth/hybridauth": "^2.9",
        "yawik/module-auth": ">=1.0.0",
        "yawik/module-jobs": ">=1.0.0"
    },
    "autoload": {
        "psr-4": {
            "Core\\": "src/"
        }
    }
}

Since we need to define every module as github repository in packagist, we need to git subsplit our main repository cross-solution/yawik into yawik/*:

cd path/to/yawik
git subsplit init git@github.com:cross-solution/YAWIK.git
git subsplit publish --heads="master" module/Applications:git@github.com:yawik/module-applications.git
git subsplit publish --heads="master" module/Auth:git@github.com:yawik/module-auth.git
git subsplit publish --heads="master" module/Core:git@github.com:yawik/module-core.git
git subsplit publish --heads="master" module/Organizations:git@github.com:yawik/module-organizations.git
rm -rf .subsplit/

This can be done automatically upon commit by using github web hook.

3. A Test Project

I have create a skeleton project called yawik/standard:

https://github.com/kilip/yawik-standard

To make this test project working, I need to modify cross-solution/yawik repository and create a special yawik github repository:

https://github.com/kilip/yawik-test

Here's what I modify in that yawik-test repository:

  • Move all ModuleName/Module.php file to ModuleName/src/Module.php directory, so it compatible with psr4 autoloading.
  • Move all directory in ModuleName/src/* to fit psr4 autoloading.
  • Add psr4 autoload definition for every modules in composer.json file, so can be loaded automatically in skeleton project.
  • Remove all autolad_classmap.php files because autolad already provided by composer autoload
  • Remove all ModuleName\Module::getAutoloaderConfig() method, because we already use composer psr4 autoloading

Coding Standard

All Yawik module should use psr-4 autoloading, and to prevent conflict with another external library I think we should start prefix all module with Yawik:

namespace Yawik\Core; // from Core namespace
namespace Yawik\Auth; // from Auth namespace
namespace Yawik\Jobs; // from Jobs namespace
namespace Yawik\DemoSkin; // from YawikDemoSkin namespace

I know this will make a lot of breaking changes and bugs, but with the help of phpunit and behat test we can easily detect error during prefixing module namespace.

@TiSiE
Copy link
Member

TiSiE commented Mar 16, 2018

@cbleek and me have discussed this thoroughly in the last weeks and we fully agree with this proposal. Indeed, we came to the conclusion that we should go even further:

-> 1. Skeleton application

Yes. It should be called 'yawik/yawik' and be 'installable' with composers' creat-project directive.
Contains the basic directory structure and the composer dependencies needed by YAWIK overall. (Including the application config, which must be customizable without breaking update compatibility, by using the same mechanisms used by the Zend Skeleton Application project)

-> 2. Development Method

Instead of relying on a custom git command (subsplit), we should split the current repository once.

For development, one then have to add the repositories in the composer.json to checkout the respective repository instead of simply copying files from a specific tag as it will be done for production installations.

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/yawik/yawik-jobs"
        }
    ],
"require": [
    "yawik/yawik-jobs": "dev-develop",
]

Other

  • We need a way to let yawik modules copy its static assets to the public folder (which is currently done with creating symlinks) There must be a composer plugin for that...

@kilip We highly appreciate your enthusiasm and motivation to improve YAWIK. Keep it up!

@kilip
Copy link
Collaborator Author

kilip commented Nov 3, 2018

hi @cbleek @TiSiE @sergey-galenko and all developers,

Since my pull #498 is merged, we need to do composer install command to make our assets (css, js, fonts, etc. ) working again:

$ cd /path/to/yawik
$ git pull origin develop
$ composer install

This command will execute the assets-install and npm install command. All javascripts, css, and fonts will be processed and minimized by grunt.

docker integration

I am introducing a docker into yawik development:

$ cd /path/to/yawik
$ docker-compose up

With this command we will have nginx, php, mongodb, and selenium running in docker. You can browse yawik in this address: http://localhost:8080

@cbleek
Copy link
Member

cbleek commented Nov 7, 2018

Hi Toni,

if I install yawik using:

create-project -sdev yawik/standard YAWIK-NEU

I get the the following exception:

Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Tracy" to a factory; are you certain you provided it during configuration? in /home/cbleek/Projects/YAWIK-NEU/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:687 Stack trace: #0 /home/cbleek/Projects/YAWIK-NEU/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(763): Zend\ServiceManager\ServiceManager->getFactory('Tracy') #1 /home/cbleek/Projects/YAWIK-NEU/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Tracy') #2 /home/cbleek/Projects/YAWIK-NEU/modules/Install/src/Module.php(48): Zend\ServiceManager\ServiceManager->get('Tracy') #3 /home/cbleek/Projects/YAWIK-NEU/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Install\Module->onBootstrap(Object(Zend\Mvc\MvcEvent)) #4 /home/cbleek/Projects/YAWIK-NEU/vendor/zendframework/zend-eventmanager/src/EventManager.php(171): Zend\EventManager\EventManager->triggerListe in /home/cbleek/Projects/YAWIK-NEU/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 687

auswahl_518

@kilip
Copy link
Collaborator Author

kilip commented Nov 7, 2018

Hi @cbleek ,

I have made some changes, so please try to install yawik again using create-project command. By default Yawik in production environment, copy your path/to/yawik/.env.dist file to .env and change APPLICATION_ENV value to development.

This is one of the reason why I want to make #504 pull request to disable cache in install mode also clear cache files if config is changed.

Regards,
Toni

@cbleek
Copy link
Member

cbleek commented Nov 7, 2018

Hi @kilip
I've installed it once again using and git the same error.

But I've:

yawik@php7:~$ rm -Rf YawikDemoPhp7
yawik@php7:~$ composer create-project -sdev yawik/standard YawikDemoPhp7
Installing yawik/standard (dev-master 52d9d25b120e82b2a36ce9b4378ca928415770b1)
  - Installing yawik/standard (dev-master 52d9d25): Cloning 52d9d25b12 from cache
Created project in YawikDemoPhp7
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 144 installs, 0 updates, 0 removals
  - Installing composer/installers (v1.6.0): Loading from cache
...
  - Installing zendframework/zend-test (3.2.0): Loading from cache
zendframework/zend-validator suggests installing zendframework/zend-db (Zend\Db component, required by the (No)RecordExists validator)
...
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Generating autoload files
> ./vendor/bin/yawik assets-install --relative

 --- --------------- ------------------ 
      Module          Method / Error    
 --- --------------- ------------------ 
  ✔   Applications    relative symlink  
  ✔   Auth            relative symlink  
  ✔   Core            relative symlink  
  ✔   Cv              relative symlink  
  ✔   Demo            relative symlink  
  ✔   Geo             relative symlink  
  ✔   Jobs            relative symlink  
  ✔   Organizations   relative symlink  
  ✔   Settings        relative symlink  
  ✔   YawikDemoSkin   relative symlink  
 --- --------------- ------------------ 

 [OK] All assets were successfully installed.                                   

> npm install

> yawik-standard@0.32.0 postinstall /home/yawik/YawikDemoPhp7
> grunt

Running "copy:core" (copy) task
Created 5 directories, copied 534 files

Running "less:core" (less) task
>> 1 stylesheet created.

Running "less:demo" (less) task
>> 1 stylesheet created.

Running "concat:core" (concat) task

Running "uglify:core" (uglify) task
>> 2 files created 2.18 MB → 766.58 kB

Running "cssmin:core" (cssmin) task
>> 1 file created. 333.84 kB → 279.85 kB

Running "cssmin:demo" (cssmin) task
>> 1 file created. 335.37 kB → 281.37 kB

Done.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN yawik-standard@0.32.0 No repository field.
npm WARN yawik-standard@0.32.0 No license field.

added 241 packages from 222 contributors and audited 424 packages in 12.063s
found 0 vulnerabilities

Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]? n
yawik@php7:~$ cd YawikDemoPhp7
yawik@php7:~/YawikDemoPhp7$ composer require yawik/orders:dev-develop
./composer.json has been updated
...
yawik@php7:~/YawikDemoPhp7$ composer require yawik/jobs-by-mail:dev-develop
./composer.json has been updated
...
yawik@php7:~/YawikDemoPhp7$ composer require yawik/solr:dev-develop
./composer.json has been updated
...
yawik@php7:~/YawikDemoPhp7$ cp /var/www/YAWIK/config/autoload/*.* config/autoload/
yawik@php7:~/YawikDemoPhp7$ 

And after that, I can access https://composer.yawik.org/en

I've put your ssh key on the dev mashine any you should be able to ssh yawik@php7.yawik.org if you need to reproduce.

@TiSiE TiSiE closed this as completed Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants