Exemplo n.º 1
0
 /**
  * Create a new view instance.
  *
  * @param  string  $view
  * @param  array   $data
  * @return void
  */
 public function __construct($view, $data = array())
 {
     $this->view = $view;
     $this->data = $data;
     $this->path = $this->path($view);
     // If a session driver has been specified, we will bind an instance of
     // the validation error message container to every view. If an errors
     // instance exists in the session, we will use that instance.
     //
     // This makes the implementation of the Post/Redirect/Get pattern very
     // convenient since each view can assume it has a message container.
     if (Config::$items['session']['driver'] !== '' and IoC::core('session')->started()) {
         $this->data['errors'] = IoC::core('session')->get('errors', function () {
             return new Messages();
         });
     }
 }
 /**
  * Magic Method for passing methods to a class registered in the IoC container.
  * This provides a convenient method of accessing functions on classes that
  * could not otherwise be accessed staticly.
  *
  * Facades allow Laravel to still have a high level of dependency injection
  * and testability while still accomodating the common desire to conveniently
  * use classes via static methods.
  */
 public static function __callStatic($method, $parameters)
 {
     $class = IoC::resolve(static::$resolve);
     $count = count($parameters);
     if ($count > 5) {
         return call_user_func_array(array($class, $method), $parameters);
     } elseif ($count == 0) {
         return $class->{$method}();
     } elseif ($count == 1) {
         return $class->{$method}($parameters[0]);
     } elseif ($count == 2) {
         return $class->{$method}($parameters[0], $parameters[1]);
     } elseif ($count == 3) {
         return $class->{$method}($parameters[0], $parameters[1], $parameters[2]);
     } elseif ($count == 4) {
         return $class->{$method}($parameters[0], $parameters[1], $parameters[2], $parameters[3]);
     } elseif ($count == 5) {
         return $class->{$method}($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]);
     }
 }
Exemplo n.º 3
0
 /**
  * Generate the session table on the database.
  *
  * @param  array  $arguments
  * @return void
  */
 public function table($arguments = array())
 {
     $migrator = IoC::resolve('task: migrate');
     $key = IoC::resolve('task: key');
     // Since sessions can't work without an application key, we will go
     // ahead and set the key if one has not already been set for the
     // application so the developer doesn't need to set it.
     $key->generate();
     // To create the session table, we will actually create a database
     // migration and then run it. This allows the application to stay
     // portable through the framework's migrations system.
     $migration = $migrator->make(array('create_session_table'));
     $stub = path('sys') . 'cli/tasks/session/migration' . EXT;
     File::put($migration, File::get($stub));
     // By default no session driver is set within the configuration.
     // Since the developer is requesting that the session table be
     // created on the database, we'll set it.
     $this->driver('database');
     echo PHP_EOL;
     $migrator->run();
 }
Exemplo n.º 4
0
 /**
  * Install a bundle using a provider.
  *
  * @param  string  $bundle
  * @param  string  $path
  * @return void
  */
 protected function download($bundle, $path)
 {
     $provider = "bundle.provider: {$bundle['provider']}";
     IoC::resolve($provider)->install($bundle, $path);
 }
Exemplo n.º 5
0
 /**
  * Generate a hidden field containing the current CSRF token.
  *
  * @return string
  */
 public static function token()
 {
     return static::input('hidden', Session::csrf_token, IoC::core('session')->token());
 }
Exemplo n.º 6
0
 /**
  * Dynamically resolve items from the application IoC container.
  *
  * <code>
  *		// Retrieve an object registered in the container as "mailer"
  *		$mailer = $this->mailer;
  *
  *		// Equivalent call using the IoC container instance
  *		$mailer = IoC::resolve('mailer');
  * </code>
  */
 public function __get($key)
 {
     if (IoC::registered($key)) {
         return IoC::resolve($key);
     }
     throw new \OutOfBoundsException("Attempting to access undefined property [{$key}] on controller.");
 }
Exemplo n.º 7
0
 /**
  * Create a new HelpSpot Migration instance.
  *
  * @return void
  */
 public function __construct()
 {
     Bundle::start('doctrine');
     $this->em = IoC::resolve('doctrine::manager');
     $this->sm = $this->em->getConnection()->getSchemaManager();
 }
Exemplo n.º 8
0
 /**
  * Send a new message using a view.
  *
  * @param string|array $view
  * @param array   $data
  * @param Closure|string $callback
  * @return void
  */
 public static function send($view, array $data, $callback)
 {
     //$mailer = new static;
     $mailer = IoC::resolve('mailer');
     return $mailer->sendMessage($view, $data, $callback);
 }
Exemplo n.º 9
0
 public function testCanUnregisterRegistered()
 {
     $testClass = 'test';
     IoC::register($testClass, function () {
     });
     $this->assertTrue(IoC::registered($testClass));
     IoC::unregister($testClass);
     $this->assertFalse(IoC::registered($testClass));
 }
Exemplo n.º 10
0
}
/**
 * The bundle publisher is responsible for publishing bundle
 * assets to their correct directories within the install,
 * such as the web accessible directory.
 */
if (!IoC::registered('bundle.publisher')) {
    IoC::singleton('bundle.publisher', function () {
        return new Tasks\Bundle\Publisher();
    });
}
/**
 * The Github bundle provider installs bundles that live on
 * Github. This provider will add the bundle as a submodule
 * and will update the submodule so that the bundle is
 * installed into the bundle directory.
 */
if (!IoC::registered('bundle.provider: github')) {
    IoC::singleton('bundle.provider: github', function () {
        return new Tasks\Bundle\Providers\Github();
    });
}
/**
 * The "help" task provides information about 
 * artisan usage.
 */
if (!IoC::registered('task: help')) {
    IoC::singleton('task: help', function () {
        return new Tasks\Help();
    });
}
Exemplo n.º 11
0
/**
 * The bundle repository is responsible for communicating with
 * the Laravel bundle sources to get information regarding any
 * bundles that are requested for installation.
 */
if (!IoC::registered('bundle.repository')) {
    IoC::singleton('bundle.repository', function () {
        return new Tasks\Bundle\Repository();
    });
}
/**
 * The bundle publisher is responsible for publishing bundle
 * assets to their correct directories within the install,
 * such as the web accessible directory.
 */
if (!IoC::registered('bundle.publisher')) {
    IoC::singleton('bundle.publisher', function () {
        return new Tasks\Bundle\Publisher();
    });
}
/**
 * The Github bundle provider installs bundles that live on
 * Github. This provider will add the bundle as a submodule
 * and will update the submodule so that the bundle is
 * installed into the bundle directory.
 */
if (!IoC::registered('bundle.provider: github')) {
    IoC::singleton('bundle.provider: github', function () {
        return new Tasks\Bundle\Providers\Github();
    });
}
Exemplo n.º 12
0
 /**
  * Determine if the request has been forged.
  *
  * The session CSRF token will be compared to the CSRF token in the request input.
  *
  * @return bool
  */
 public static function forged()
 {
     return static::csrf_token() !== IoC::core('session')->token();
 }
Exemplo n.º 13
0
        $cache = IoC::resolve('doctrine::cache.provider');
    } else {
        $cache = new Doctrine\Common\Cache\ArrayCache();
    }
    /**
     * Register the cache provider with the Doctrine configuration.
     */
    $config = new Doctrine\ORM\Configuration();
    $config->setMetadataCacheImpl($cache);
    $config->setQueryCacheImpl($cache);
    /**
     * Resolve and register the meta-data driver.
     */
    if (IoC::registered('doctrine::metadata.driver')) {
        $driverImpl = IoC::resolve('doctrine::metadata.driver', array($config));
    } else {
        $driverImpl = $config->newDefaultAnnotationDriver(Config::get('doctrine::config.models'));
    }
    $config->setMetadataDriverImpl($driverImpl);
    /**
     * Register the proxy configuration with Doctrine.
     */
    $config->setProxyDir(Config::get('doctrine::config.proxy.directory'));
    $config->setProxyNamespace(Config::get('doctrine::config.proxy.namespace'));
    $config->setAutoGenerateProxyClasses(Config::get('doctrine::config.proxy.auto_generate'));
    /**
     * Register an EntityManager in the IoC container as an instance.
     */
    $em = EntityManager::create(array('pdo' => Laravel\Database::connection()->pdo), $config);
    IoC::instance('doctrine::manager', $em);
});
Exemplo n.º 14
0
 /**
  * Determine if the request has been forged.
  *
  * The session CSRF token will be compared to the CSRF token in the request input.
  *
  * @return bool
  */
 public static function forged()
 {
     return Input::get(Session::csrf_token) !== IoC::core('session')->token();
 }
Exemplo n.º 15
0
 /**
  * Resolve an instance of the given task name.
  *
  * <code>
  *		// Resolve an instance of a task
  *		$task = Command::resolve('application', 'migrate');
  *
  *		// Resolve an instance of a task wtihin a bundle
  *		$task = Command::resolve('bundle', 'foo');
  * </code>
  *
  * @param  string  $bundle
  * @param  string  $task
  * @return object
  */
 public static function resolve($bundle, $task)
 {
     $identifier = Bundle::identifier($bundle, $task);
     // First we'll check to see if the task has been registered in the
     // application IoC container. This allows all dependencies to be
     // injected into tasks for more testability.
     if (IoC::registered("task: {$identifier}")) {
         return IoC::resolve("task: {$identifier}");
     }
     // If the task file exists, we'll format the bundle and task name
     // into a task class name and resolve an instance of the so that
     // the requested method may be executed.
     if (file_exists($path = Bundle::path($bundle) . 'tasks/' . $task . EXT)) {
         require $path;
         $task = static::format($bundle, $task);
         return new $task();
     }
 }
 /**
  * Dynamically resolve items from the application IoC container.
  *
  * <code>
  *		// Retrieve an object registered in the container
  *		$mailer = $this->mailer;
  *
  *		// Equivalent call using the IoC container instance
  *		$mailer = IoC::resolve('mailer');
  * </code>
  */
 public function __get($key)
 {
     if (IoC::registered($key)) {
         return IoC::resolve($key);
     }
 }
Exemplo n.º 17
0
    return $mailer;
});
// Register a swift mailer in the IoC container
IoC::register('swift.mailer', function () {
    $transport = IoC::resolve('swift.mailer.transport');
    return Swift_Mailer::newInstance($transport);
});
// Register a transporter in the IoC container
IoC::register('swift.mailer.transport', function () {
    extract(Config::get('mail'));
    // $host = Config::get('mail.host');
    // $port = Config::get('mail.port');
    // $encryption = Config::get('mail.encryption');
    // $username = Config::get('mail.username');
    // $password = Config::get('mail.password');
    // The Swift SMTP transport instance will allow us to use any SMTP backend
    // for delivering mail such as Sendgrid, Amazon SMS, or a custom server
    // a developer has available. We will just pass this configured host.
    $transport = Swift_SmtpTransport::newInstance($host, $port);
    if (isset($encryption)) {
        $transport->setEncryption($encryption);
    }
    // Once we have the transport we will check for the presence of a username
    // and password. If we have it we will set the credentials on the Swift
    // transporter instance so that we'll properly authenticate delivery.
    if (isset($username)) {
        $transport->setUsername($username);
        $transport->setPassword($password);
    }
    return $transport;
});