当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::stream方法代码示例

本文整理汇总了PHP中Silex\Application::stream方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::stream方法的具体用法?PHP Application::stream怎么用?PHP Application::stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Silex\Application的用法示例。


在下文中一共展示了Application::stream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 public function register(Application $app)
 {
     if (class_exists('\\Imagick')) {
         $app['intervention.driver'] = 'imagick';
     } else {
         $app['intervention.driver'] = 'gd';
     }
     $app['intervention.image'] = $app->share(function (Application $app) {
         return new ImageManager(array('driver' => $app['intervention.driver']));
     });
     /**
      * For calling like:
      * return $app['intervention.response']($image);
      */
     $app['intervention.response'] = $app->protect(function (Image $image) use($app) {
         return $app->stream(function () use($image) {
             echo $image->response();
         }, 200);
     });
 }
开发者ID:microstudi,项目名称:silex-intervention-image,代码行数:20,代码来源:InterventionImageServiceProvider.php

示例2: testAction

 public function testAction(Application $app)
 {
     $method = __METHOD__;
     return $app->stream(function () use($method, $app) {
         var_dump($method, $app['module']);
     });
 }
开发者ID:vonalbert,项目名称:silext,代码行数:7,代码来源:BarController.php

示例3: thumbnailAction

 /**
  * @param  Application $app
  * @param  Request     $request
  * @param  Photo       $photo
  * @param  int         $width
  * @param  int         $height
  * @param  string      $algorithm
  * @return Response
  */
 public function thumbnailAction(Application $app, Request $request, $photo, $width, $height = null, $algorithm = null)
 {
     if (!$photo) {
         return $app->abort(404);
     }
     $thumbnailPath = $app['photos']->getThumbnail($photo, $width, $height, $algorithm);
     $stream = function () use($thumbnailPath) {
         $resource = imagecreatefromjpeg($thumbnailPath);
         imagejpeg($resource);
     };
     return $app->stream($stream, 200, ['Content-type' => 'image/jpeg', 'Content-Disposition' => sprintf('filename="%s"', $photo->filename)]);
 }
开发者ID:astranchet,项目名称:pamplemousse,代码行数:21,代码来源:Controller.php

示例4: testStreamActuallyStreams

 public function testStreamActuallyStreams()
 {
     $i = 0;
     $stream = function () use(&$i) {
         $i++;
     };
     $app = new Application();
     $response = $app->stream($stream);
     $this->assertEquals(0, $i);
     $request = Request::create('/stream');
     $response->prepare($request);
     $response->sendContent();
     $this->assertEquals(1, $i);
 }
开发者ID:robihidayat,项目名称:silex-mongodb-parks,代码行数:14,代码来源:StreamTest.php

示例5: connect

 /**
  * @see ControllerProviderInterface::connect
  */
 public function connect(Application $app)
 {
     // Global layout
     $app->before(function () use($app) {
         $app['twig']->addGlobal('layout', $app['twig']->loadTemplate('layout.twig'));
     });
     // Error management
     if (!$app['debug']) {
         $app->error(function (\Exception $e, $code) use($app) {
             if ($code >= 400 && $code < 500) {
                 $message = $e->getMessage();
             } else {
                 $message = 'Whoops, looks like something went wrong.';
             }
             // In case twig goes wrong, exemple: no route found means the
             // $app->before() wont be executed
             try {
                 $app['user'] = false;
                 $app['twig']->addGlobal('layout', $app['twig']->loadTemplate('layout.twig'));
                 return $app['twig']->render('error.twig', array('message' => $message, 'code' => $code));
             } catch (\Exception $e) {
                 return new Response('Whoops, looks like something went very wrong.', $code);
             }
         });
     }
     // creates a new controller based on the default route
     $controllers = $app['controllers_factory'];
     // Homepage + form handler
     $controllers->get('/', function (Request $request) use($app) {
         return $app['twig']->render('index.twig', array('form' => $app['short_url.form']->createView(), 'last' => $app['short_url']->getLastShorten(10)));
     })->bind('short_url_homepage');
     // Handle the form submission
     $controllers->post('/', function (Request $request) use($app) {
         $form = $app['short_url.form'];
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $email = $app['user']['email'] ? $app['user']['email'] : null;
             $id = $app['short_url']->add($data['url'], $email);
             $url_details = $app['short_url']->getById($id);
             $r_url = $app['url_generator']->generate('short_url_details', array('short_code' => $url_details['short_code']));
             return $app->redirect($r_url);
         } else {
             return $app['twig']->render('index.twig', array('form' => $form->createView(), 'last' => $app['short_url']->getLastShorten(10)));
         }
         $app->abort(404, "Nothing found!");
     });
     // Details
     $controllers->get('/{short_code}/details', function ($short_code) use($app) {
         $url_details = $app['short_url']->getByShortCode($short_code);
         $last_redirects = $app['short_url']->getLastRedirects($url_details['id']);
         $redirects_counter = $app['short_url']->getRedirectCounter($url_details['id']);
         return $app['twig']->render('details.twig', array('long_url' => $url_details['url'], 'short_code' => $short_code, 'last_redirects' => $last_redirects, 'redirects_counter' => $redirects_counter));
     })->bind('short_url_details');
     // QRCode
     $controllers->get('/{short_code}.png', function ($short_code) use($app) {
         $url_details = $app['short_url']->getByShortCode($short_code);
         if ($url_details) {
             $short_url = $app['url_generator']->generate('short_url_redirect', array('short_code' => $short_code), true);
             $file = $_SERVER['DOCUMENT_ROOT'] . "/qr/{$short_code}.png";
             if (!file_exists($file)) {
                 QRcode::png($short_url, $file, 'L', 4, 2);
             }
             $stream = function () use($file) {
                 readfile($file);
             };
             return $app->stream($stream, 200, array('Content-Type' => 'image/png'));
         }
         $app->abort(404, "That shorten url does not exist!");
     })->bind('short_url_qrcode');
     // Shorten the url in the query string (?url=)
     $controllers->get('/shorten/', function (Request $request) use($app) {
         $url = rawurldecode($request->get('url'));
         $errors = $app['validator']->validateValue($url, new Assert\Url());
         if ($url && !$errors->has(0)) {
             $id = $app['short_url']->add($url);
             $url_details = $app['short_url']->getById($id);
             $r_url = $app['url_generator']->generate('short_url_details', array('short_code' => $url_details['short_code']));
             return $app->redirect($r_url);
         } else {
             $app->abort(404, $errors->get(0)->getMessage());
         }
         $app->abort(404, "The url query string parameter is required.");
     })->bind('short_url_shorten');
     // Redirects to the last shorten url
     $controllers->get('/last/', function () use($app) {
         $urls = $app['short_url']->getLastShorten(1);
         if ($urls[0]['id']) {
             $app['short_url']->incrementCounter($urls[0]['id']);
             return $app->redirect($urls[0]['url']);
         }
         $app->abort(404, "Nothing found!");
     })->bind('short_url_last');
     // Redirects to the corresponding url
     $controllers->get('/{short_code}', function ($short_code) use($app) {
         $url = $app['short_url']->getByShortCode($short_code);
         if ($url) {
//.........这里部分代码省略.........
开发者ID:chocopoche,项目名称:short_url,代码行数:101,代码来源:ShortUrlProvider.php

示例6: streamImage

 private function streamImage(Application $app, Image $image)
 {
     $image->encode(null, $this->default_quality);
     $mime = self::getMimeFromData($image->getEncoded());
     return $app->stream(function () use($image) {
         // echo $image->response();
         echo $image->getEncoded();
     }, 200, array('Content-Type' => $mime));
 }
开发者ID:microstudi,项目名称:silex-image-controller,代码行数:9,代码来源:ImageController.php

示例7: function

        }
        return $this->finish(true, $new_build_path);
    }
}
$app->post('/deploy/{service}', function (Application $app, Request $request, $service) {
    if (isset($app['config'][$service])) {
        $config = $app['config'][$service];
        $secret = $request->get("secret");
        if ($secret != $config['secret']) {
            return new Response("Forbidden", 403, array('Content-Type' => 'text/plain'));
        }
        $deployer = new Deployer($service, $config);
        $stream = function () use($deployer, $request) {
            $deployer->deploy($request);
        };
        return $app->stream($stream, 200, array('Content-Type' => 'text/plain'));
    }
    return "ERROR: missing service: " . $service;
});
$app->post('/rollback/{service}', function (Application $app, Request $request, $service) {
    if (isset($app['config'][$service])) {
        $config = $app['config'][$service];
        $secret = $request->get("secret");
        if ($secret != $config['secret']) {
            return new Response("Forbidden", 403, array('Content-Type' => 'text/plain'));
        }
        $deployer = new Deployer($service, $config);
        $deployer->recursive_unlink($config['current_path']);
        if (!@rename($config['old_path'], $config['current_path'])) {
            $deployer->recurse_copy($config['old_path'], $config['current_path']);
        }
开发者ID:aorcsik,项目名称:php-deployer,代码行数:31,代码来源:index.php

示例8: Finder

    $finder = new Finder();
    $finder->files()->in($basePath)->name('*.js')->sort(function (SplFileInfo $first, SplFileInfo $second) {
        return !strcmp($first->getRealPath(), $second->getRealPath());
    });
    foreach ($finder as $file) {
        $files[str_replace('v', 'version ', $file->getRelativePath())][] = $file;
    }
    return $app['twig']->render('/pages/download.html.twig', array('relativeBaseFolder' => $relativeBaseFolder, 'files' => $files));
})->bind('download');
$app->get('/get/{filename}', function ($filename) use($app, $relativeBaseFolder) {
    $filename = __DIR__ . '/' . $relativeBaseFolder . '/' . $filename;
    if ($app['filesystem']->exists($filename)) {
        $file = new File($filename, true);
        $fileInfos = new SplFileInfo($filename);
        return $app->stream(function () use($fileInfos) {
            readfile($fileInfos->getRealPath());
        }, 200, array('Content-Type' => $file->getMimeType(), 'Content-Length' => $fileInfos->getSize(), 'Content-Disposition' => 'attachment; filename="' . $fileInfos->getFilename() . '"'));
    } else {
        $app->abort(404, 'The file you are looking for cannot be found !');
    }
})->bind('get')->assert('filename', '[a-zA-Z0-9-_/.]*');
// Demonstrations
$app->get('/demonstrations', function () use($app) {
    return $app['twig']->render('/pages/demonstrations.html.twig');
})->bind('demonstrations');
// Prices
$app->get('/prices', function () use($app) {
    return $app['twig']->render('/pages/prices.html.twig');
})->bind('prices');
// Errors
$app->error(function (Exception $exception, $code) use($app) {
开发者ID:pendechosen,项目名称:colormix,代码行数:31,代码来源:index.php


注:本文中的Silex\Application::stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。