Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

first drafts of theme switcher module #158

Closed
wants to merge 25 commits into from
Closed

first drafts of theme switcher module #158

wants to merge 25 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 16, 2015

Theme switcher is working now, but you have to manually refresh the page to change th text.

TODO:

  • unit tests
  • Fix some code bugs, better cohesion and coupling
  • Move getConfig() logic to a factory class
  • Add styles for all themes
  • Simplify
  • Merge both modules into one

@@ -22,6 +23,7 @@
'LearnZF2Authentication',
'LearnZF2Captcha',
'LearnZF2AjaxImageGallery',
'LearnZF2Themes',
Copy link
Member

Choose a reason for hiding this comment

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

require two modules ? Themes and LearnZF2Themes ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Still thinking how to make it simple. Got any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

only LearnZF2Themes

@ghost
Copy link
Author

ghost commented Oct 20, 2015

@samsonasik @acelaya Would you mind doing a review?

}
?>
</div>
<p>This is where all the magic happens. The system retrives the theme name from the Config
Copy link
Member

Choose a reason for hiding this comment

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

s/retrives/retrieves

@ghost
Copy link
Author

ghost commented Oct 20, 2015

Sometimes I'm amazed by my stupidity and the code I write...

$headScript->prependFile($publicDir.$file);
}

return new self();
Copy link
Member

Choose a reason for hiding this comment

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

update this as well as code updated.

$serviceLocator->setAllowOverride(false);
}

return $serviceLocator;
Copy link
Member

Choose a reason for hiding this comment

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

imo, the zf2 factory should create another instance that may pull service from serviceLocator, not a serviceLocator instance itself, @acelaya do you have some opinion about it ? I think it can be replaced by SharedEventManager, in Module class:

use LearnZF2Themes\Service\ReloadService;

$shm->attach(ReloadService::class, 'reload',  function($e) use ($this->service) {
      $reloadService = $e->getTarget();

      // do the re-set config here..., or use attachAggregate with passed listener \
      // that handle it  
      $reloadService->getEventManager()
                              ->attachAggregate($this->service->get('ConfigChangerListener'));
});

in ConfigChangerListener, we can do:

and in the LearnZF2Themes\Service\ReloadService , we can do :

namespace LearnZF2Themes\Service;

use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\EventManagerAwareTrait;

class ReloadService implements EventManagerAwareInterface 
{
   use EventManagerAwareTrait;

   public function reload() 
   {
        $this->getEventManager()->trigger(__FUNCTION__, $this);
    }
}

So, in controller, we can do:

$this->reloadService->reload();

more clear imo ^^

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I'm a little bit disconnected on this subject. I'll take a look at
it this afternoon

Alejandro Celaya Alastrué
El 21/10/2015 10:43, "Abdul Malik Ikhsan" notifications@github.com
escribió:

In
module/LearnZF2Themes/src/LearnZF2Themes/Factory/ReloadConfigFactory.php
#158 (comment):

  • \* {@inheritdoc}
    
  • */
    
  • public function __invoke(ServiceLocatorInterface $serviceLocator)
  • {
  •    $request = $serviceLocator->get('Request');
    
  •    if ($request->isPost()) {
    
  •        $config = $serviceLocator->get('Config');
    
  •        $themeName = $request->getPost()['themeName'];
    
  •        $serviceLocator->setAllowOverride(true);
    
  •        $config['theme']['name'] = $themeName;
    
  •        $serviceLocator->setService('Config', $config);
    
  •        $serviceLocator->setAllowOverride(false);
    
  •    }
    
  •    return $serviceLocator;
    

imo, the zf2 factory should create another instance that may pull service
from serviceLocator, not a serviceLocator instance itself, @acelaya
https://github.com/acelaya do you have some opinion about it ? I think
it can be replaced by SharedEventManager, in Module class:

use LearnZF2Themes\Service\ReloadService;$shm->attach(ReloadService::class, 'reload', function($e) use ($this->service) { $reloadService = $e->getTarget(); // do the re-set config here..., or use attachAggregate with passed listener \ // that handle it $reloadService->getEventManager() ->attachAggregate($this->service->get('ConfigChangerListener'));});

in ConfigChangerListener, we can do:

and in the LearnZF2Themes\Service\ReloadService , we can do :

namespace LearnZF2Themes\Service;use Zend\EventManager\EventManager;use Zend\EventManager\EventManagerAwareInterface;use Zend\EventManager\EventManagerInterface;use Zend\EventManager\EventManagerAwareTrait;class ReloadService implements EventManagerAwareInterface { use EventManagerAwareTrait; public function reload() { $this->getEventManager()->trigger(FUNCTION, $this); }}

So, in controller, we can do:

$this->reloadService->reload();

more clear imo ^^


Reply to this email directly or view it on GitHub
https://github.com/sitrunlab/LearnZF2/pull/158/files#r42596990.

Copy link
Member

Choose a reason for hiding this comment

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

it's ok, thank you ;)

Copy link
Author

Choose a reason for hiding this comment

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

This could actually work. Gonna try and see. Thanks!

@ghost
Copy link
Author

ghost commented Oct 21, 2015

Bitbucket is down and travis has failed installing PhantomJS.

@samsonasik
Copy link
Member

usually won't take long, hopefully on your next commit, the bitbucket service back again ;)

Warm regards,

Abdul Malik Ikhsan

Pada 21 Okt 2015, pukul 17.27, Stanimir Dimitrov notifications@github.com menulis:

Bitbucket is down and travis has failed installing PhantomJS.


Reply to this email directly or view it on GitHub.

/**
* @var \Zend\getServiceManager\ServiceManager
*/
private $service = null;
Copy link
Member

Choose a reason for hiding this comment

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

no need to assign to null here.

Copy link
Author

Choose a reason for hiding this comment

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

I like having default values, althought null is not necessery, it's more clear that the property is null by default. Odd habit.

$app = $event->getApplication();
$this->service = $app->getServiceManager();
$eventManager = $app->getEventManager();
$sharedEventManager = $app->getEventManager()->getSharedManager();
Copy link
Member

Choose a reason for hiding this comment

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

can be shortcut-ed with:

$sharedEventManager = $eventManager->getSharedManager();

@ghost
Copy link
Author

ghost commented Oct 22, 2015

I implemented the module in my CMS and it took me 5 mins for the whole process. There the module loads for ~300ms. Nothing more to add. Ready for merge in no one has anything to say.

@samsonasik
Copy link
Member

@acelaya could you do final review before it got merged?

@acelaya
Copy link
Contributor

acelaya commented Oct 22, 2015

I'm not probably going to be able to review it until weekend.
Is it ok?

Alejandro Celaya Alastrué
El 22/10/2015 15:27, "Abdul Malik Ikhsan" notifications@github.com
escribió:

@acelaya https://github.com/acelaya could you do final review before it
got merged?


Reply to this email directly or view it on GitHub
#158 (comment).

@samsonasik
Copy link
Member

Ok ;), thank you ;)

Warm regards,

Abdul Malik Ikhsan

Pada 22 Okt 2015, pukul 20.28, Alejandro Celaya notifications@github.com menulis:

I'm not probably going to be able to review it until weekend.
Is it ok?

Alejandro Celaya Alastrué
El 22/10/2015 15:27, "Abdul Malik Ikhsan" notifications@github.com
escribió:

@acelaya https://github.com/acelaya could you do final review before it
got merged?


Reply to this email directly or view it on GitHub
#158 (comment).


Reply to this email directly or view it on GitHub.

@samsonasik
Copy link
Member

@stanimirdim92 you're missing migration command to add this module to sql that will be generated in data/DoctrineORMModule/Migrations

*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
Copy link
Member

Choose a reason for hiding this comment

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

need sql update here, I will do during merge

samsonasik added a commit that referenced this pull request Oct 26, 2015
samsonasik added a commit that referenced this pull request Oct 26, 2015
Forward port #158
* stanimir/theme-switcher: (25 commits)
  #158 LearnZF2Themes sql
  add migrations class
  module fix
  feedback fixes
  styleci...............
  forgot the new unit tests...
  stylceci
  stylceci
  stylceci
  added custom event listener
  fixed tutorial code
  removed phpunit phar
  styleci fixes, again
  feedback from samsonasik
  added code in index.php
  styleci
  added styles, fixed theme reloading, althought it sucks with that SM in controller :X
  added styles, fixed theme reloading, althought it sucks with that SM in controller :X
  styleci fixes, config paths fixes, added 100% code coverage.
  styleci fixes, config paths fixes, added 100% code coverage.
  ...
samsonasik added a commit that referenced this pull request Oct 26, 2015
* stanimir/theme-switcher: (25 commits)
  #158 LearnZF2Themes sql
  add migrations class
  module fix
  feedback fixes
  styleci...............
  forgot the new unit tests...
  stylceci
  stylceci
  stylceci
  added custom event listener
  fixed tutorial code
  removed phpunit phar
  styleci fixes, again
  feedback from samsonasik
  added code in index.php
  styleci
  added styles, fixed theme reloading, althought it sucks with that SM in controller :X
  added styles, fixed theme reloading, althought it sucks with that SM in controller :X
  styleci fixes, config paths fixes, added 100% code coverage.
  styleci fixes, config paths fixes, added 100% code coverage.
  ...
@samsonasik
Copy link
Member

merged after rebase at db4af03 ;)

@samsonasik samsonasik closed this Oct 26, 2015
@samsonasik
Copy link
Member

@stanimirdim92 the module is life now http://learnzf2.sitrun-tech.com/learn-zf2-themes , thanks ;)
@acelaya if you have a chance to take a look, and found any issue, feel free to PR ;), thanks ;)

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.

3 participants