Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the dm_chess_ajax_cache service
- Loading branch information
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
class dmChessAjaxCache | ||
{ | ||
protected $dispatcher; | ||
protected $dir; | ||
|
||
public function __construct(sfEventDispatcher $dispatcher) | ||
{ | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
public function connect() | ||
{ | ||
$this->dispatcher->connect('dm.chess.player_set_events', array($this, 'listenToPlayerSetEventsEvent')); | ||
|
||
$this->dispatcher->connect('dm.chess.player_clear_events', array($this, 'listenToPlayerClearEventsEvent')); | ||
} | ||
|
||
public function listenToPlayerSetEventsEvent(dmChessEvent $event) | ||
{ | ||
if(!$event->getSubject()->isAi) | ||
{ | ||
touch($this->getPlayerFile($event->getSubject())); | ||
} | ||
} | ||
|
||
public function listenToPlayerClearEventsEvent(dmChessEvent $event) | ||
{ | ||
if(!$event->getSubject()->isAi) | ||
{ | ||
unlink($this->getPlayerFile($event->getSubject())); | ||
} | ||
} | ||
|
||
public function getPlayerFile(DmChessPlayer $player) | ||
{ | ||
return $this->getDir().'/'.$player->get('code'); | ||
} | ||
|
||
public function getDir() | ||
{ | ||
$dir = sfConfig::get('sf_web_dir').'/cache/chess'; | ||
|
||
if(!is_dir($dir)) | ||
{ | ||
mkdir($dir); | ||
} | ||
|
||
return $dir; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters