Пример #1
0
 /**
  * @param Fiddle $fiddle
  * @return string
  */
 public function getDirectory(Fiddle $fiddle)
 {
     return '/tmp/propelsandbox/chroots/' . $fiddle->getId();
 }
Пример #2
0
 /**
  * @Put("/")
  */
 public function newFiddleAction(Request $request)
 {
     $request->getSession()->start();
     $sessionId = $request->getSession()->getId();
     $id = null;
     $c = 0;
     while (true) {
         $c++;
         $id = substr(md5(microtime() * 10000 + mt_rand()), 0, 7);
         $fiddle = FiddleQuery::create()->select('Id')->findPk($id);
         if (!$fiddle) {
             $fiddle = new Fiddle();
             $fiddle->setId($id);
             $fiddle->setSessionOwner($sessionId);
             $fiddle->setCreatedAt(time());
             $fiddle->save();
             break;
         }
         if ($c > 1000) {
             throw new \RuntimeException('Could not create a new fiddle id for your. That should not happen :-(');
         }
     }
     return $id;
 }