Ejemplo n.º 1
0
 /**
  * Build views in order to parse php files
  *
  * @param Array $viewPaths
  * @param String $domain
  *
  * @return Boolean status
  */
 public function compileViews(array $viewPaths, $domain)
 {
     // Check the output directory
     $targetDir = $this->storagePath . DIRECTORY_SEPARATOR . $this->storageContainer;
     if (!file_exists($targetDir)) {
         $this->createDirectory($targetDir);
     }
     // Domain separation
     $domainDir = $targetDir . DIRECTORY_SEPARATOR . $domain;
     $this->clearDirectory($domainDir);
     $this->createDirectory($domainDir);
     foreach ($viewPaths as $path) {
         $path = $this->basePath . DIRECTORY_SEPARATOR . $path;
         $fs = new \Illuminate\Filesystem\Filesystem($path);
         $files = $fs->allFiles(realpath($path));
         $compiler = new \Illuminate\View\Compilers\BladeCompiler($fs, $domainDir);
         foreach ($files as $file) {
             $filePath = $file->getRealPath();
             $compiler->setPath($filePath);
             $contents = $compiler->compileString($fs->get($filePath));
             $compiledPath = $compiler->getCompiledPath($compiler->getPath());
             $fs->put($compiledPath . '.php', $contents);
         }
     }
     return true;
 }
Ejemplo n.º 2
0
function eval_blade_string($content, $data)
{
    extract($data);
    $filesystem = new Illuminate\Filesystem\Filesystem();
    $cachePath = __DIR__ . '/tmp';
    $blade = new Illuminate\View\Compilers\BladeCompiler($filesystem, $cachePath);
    $compiled = $blade->compileString($content);
    ob_start();
    try {
        eval('?>' . $compiled);
    } catch (Exception $e) {
        die("\n\n<h2>" . $e->getMessage() . "</h2>Error while rendering view with content:<br><br><code>" . $content . "</code>");
    }
    return ob_get_clean();
}
 public function testViewCanBeRendered()
 {
     @unlink(__DIR__ . '/receipt.blade.php');
     $vendor = 'Taylor';
     $product = 'Laravel';
     $street = 'street';
     $location = 'location';
     $phone = 'phone';
     $url = 'url';
     $__stripeInvoice = (object) ['id' => 1, 'date' => $date = time()];
     $invoice = m::mock('Laravel\\Cashier\\Invoice', [m::mock('Laravel\\Cashier\\Contracts\\Billable'), $__stripeInvoice]);
     $invoice->shouldReceive('date')->andReturn(Carbon\Carbon::createFromTimestamp($date));
     /*
      * Invoice items...
      */
     $invoice->shouldReceive('invoiceItems')->andReturn([$invoiceItem = m::mock('StdClass')]);
     $invoiceItem->description = 'foo';
     $invoiceItem->shouldReceive('total')->andReturn('total');
     $invoiceItem->shouldReceive('dollars')->andReturn('total');
     /*
      * Subscription...
      */
     $invoice->shouldReceive('subscriptions')->andReturn([$subscription = m::mock('StdClass')]);
     $subscription->quantity = 1;
     $subscription->shouldReceive('total');
     $subscription->shouldReceive('dollars')->andReturn('dollars');
     $subscription->shouldReceive('startDateString');
     $subscription->shouldReceive('endDateString');
     /*
      * Discounts...
      */
     $invoice->shouldReceive('hasDiscount')->andReturn(true);
     $invoice->shouldReceive('discountIsPercentage')->andReturn(true);
     $invoice->shouldReceive('coupon')->andReturn('coupon');
     $invoice->shouldReceive('percentOff')->andReturn('percent-off');
     $invoice->shouldReceive('discount')->andReturn('discount');
     /*
      * Final total...
      */
     $invoice->shouldReceive('total')->andReturn('total');
     $invoice->shouldReceive('dollars')->andReturn('total');
     /*
      * Billable instance...
      */
     $billable = m::mock('StdClass');
     $billable->shouldReceive('getBillableName')->andReturn('name');
     $compiler = new Illuminate\View\Compilers\BladeCompiler(new Illuminate\Filesystem\Filesystem(), null);
     $compiled = $compiler->compileString(file_get_contents(__DIR__ . '/../src/views/receipt.blade.php'));
     file_put_contents(__DIR__ . '/receipt.blade.php', $compiled);
     ob_start();
     include __DIR__ . '/receipt.blade.php';
     $contents = ob_get_clean();
     @unlink(__DIR__ . '/receipt.blade.php');
 }