コード例 #1
0
ファイル: PreFileFilter.php プロジェクト: lohini/webloader
 /**
  * @return Cache
  */
 protected static function getCache()
 {
     if (self::$cache === NULL) {
         self::$cache = \Nette\Environment::getService('webloader.cache');
     }
     return self::$cache;
 }
コード例 #2
0
 private function validateEntity($entity)
 {
     $errors = Environment::getService("validator")->validate($entity);
     if (count($errors) > 0) {
         foreach ($errors as $violation) {
             throw new \Neuron\Model\ValidationException($violation->getMessage(), $violation->getPropertyPath());
         }
     }
 }
コード例 #3
0
ファイル: ServiceFactories.php プロジェクト: janmarek/Neuron
 public static function createHelperLoader()
 {
     $loader = new \Neuron\Helper\TemplateHelperLoader();
     $loader->setHelper('texy', 'Neuron\\Texy\\TemplateHelper::process');
     $loader->setHelper('safetexy', 'Neuron\\Texy\\TemplateHelper::safeProcess');
     $loader->setHelper('thumbnail', array(Environment::getService('ThumbnailHelper'), 'createThumbnail'));
     $loader->setHelper('gravatar', 'Neuron\\Helper\\Gravatar::getImageTag');
     $loader->setHelper('imagehtml', 'Neuron\\Helper\\ImageHtml::getHtml');
     $loader->setHelper('webpath', 'Neuron\\Helper\\WebPath::getSrc');
     $loader->setHelper('imagepath', function ($image) {
         return Environment::getService('PhotoService')->getImagePath($image);
     });
     return $loader;
 }
コード例 #4
0
ファイル: Doctrine2Panel.php プロジェクト: janmarek/Neuron
 public function getPanel()
 {
     if (count($this->queries) == 0) {
         return NULL;
     }
     $platform = get_class(\Nette\Environment::getService('Doctrine\\ORM\\EntityManager')->getConnection()->getDatabasePlatform());
     $platform = substr($platform, strrpos($platform, "\\") + 1, strrpos($platform, "Platform") - (strrpos($platform, "\\") + 1));
     $queries = $this->queries;
     $totalTime = round($this->totalTime, 3);
     $i = 0;
     ob_start();
     require_once __DIR__ . "/doctrine2.panel.phtml";
     return ob_get_clean();
 }
コード例 #5
0
 public function isValid($value, Constraint $constraint)
 {
     /* @var $context Symfony\Component\Validator\ValidationContext */
     $context = $this->context;
     $property = $context->getCurrentProperty();
     $em = \Nette\Environment::getService('Doctrine\\ORM\\EntityManager');
     $entity = $context->getRoot();
     $qb = $em->getRepository(get_class($entity))->createQueryBuilder('e');
     $qb->select('count(e.id)')->where("e.{$property} = ?1")->setParameter('1', $value);
     if ($entity->getId()) {
         $qb->andWhere('e.id <> ?2')->setParameter('2', $entity->getId());
     }
     $count = $qb->getQuery()->getSingleScalarResult();
     $valid = (int) $count === 0;
     if ($valid) {
         return true;
     } else {
         $this->setMessage($constraint->message, array('value' => $value));
         return false;
     }
 }
コード例 #6
0
	/**
	 * Maps HTTP request to a PresenterRequest object.
	 *
	 * @author   Jan Tvrdík
	 * @param    IHttpRequest
	 * @return   PresenterRequest|NULL
	 */
	public function match(IHttpRequest $httpRequest)
	{
		$path = rtrim($httpRequest->getUri()->getRelativeUri(), '/');
		$page = ($path === '' ? $this->homepage : $path);
		$templateLocator = Env::getService('TemplateLocator');
		if (!$templateLocator->existsPage($page)) {
			$page .= '/' . $this->defaultPage;
			if (!$templateLocator->existsPage($page)) {
				return NULL;
			}
		}

		return new PresenterRequest(
			$this->presenter,
			$httpRequest->getMethod(),
			array('page' => $page),
			$httpRequest->getPost(),
			$httpRequest->getFiles(),
			array('secured' => $httpRequest->isSecured())
		);
	}
コード例 #7
0
ファイル: Accounts.php プロジェクト: soundake/pd
 /**
  * Performs an authentication
  * @param  array
  * @return void
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $row = $this->fetch(array('username' => $credentials[0], 'active' => 1));
     if (!$row) {
         throw new AuthenticationException('Incorrect member name or password!', self::IDENTITY_NOT_FOUND);
     }
     if ($row['active'] == 0) {
         throw new AuthenticationException('Access denied', self::INVALID_CREDENTIAL);
     }
     if ($row['password'] !== sha1($credentials[1])) {
         throw new AuthenticationException('Incorrect member name or password!', self::INVALID_CREDENTIAL);
     }
     $acl = Nette\Environment::getService('authorizator');
     if ($row['role'] !== NULL) {
         $roles = $acl->getRoleParents($row['role']);
         $roles[] = $row['role'];
     } else {
         $roles = $row['role'];
         // or $roles = NULL
     }
     $this->setOnline($row['id']);
     unset($row['password']);
     unset($row['role']);
     return new Nette\Security\Identity($row['id'], $roles, $row);
 }
コード例 #8
0
ファイル: Configurator.php プロジェクト: JPalounek/IconStore
 /**
  * @return Nette\Loaders\RobotLoader
  */
 public static function createRobotLoader($options)
 {
     $loader = new Nette\Loaders\RobotLoader();
     $loader->autoRebuild = isset($options['autoRebuild']) ? $options['autoRebuild'] : !Environment::isProduction();
     $loader->setCacheStorage(Environment::getService('Nette\\Caching\\ICacheStorage'));
     if (isset($options['directory'])) {
         $loader->addDirectory($options['directory']);
     } else {
         foreach (array('appDir', 'libsDir') as $var) {
             if ($dir = Environment::getVariable($var, NULL)) {
                 $loader->addDirectory($dir);
             }
         }
     }
     $loader->register();
     return $loader;
 }
コード例 #9
0
ファイル: FileStorage.php プロジェクト: vrana/ORM-benchmark
 /**
  * Returns the ICacheJournal
  * @return ICacheJournal
  */
 protected function getJournal()
 {
     if ($this->journal === NULL) {
         $this->journal = Nette\Environment::getService('Nette\\Caching\\ICacheJournal');
     }
     return $this->journal;
 }
コード例 #10
0
ファイル: Captcha.php プロジェクト: vbuilder/framework
 /**
  * Register CaptchaControl to FormContainer, start session and set $defaultFontFile (if not set)
  * @return void
  * @throws \Nette\InvalidStateException
  */
 public static function register()
 {
     if (self::$registered) {
         throw new \Nette\InvalidStateException(__CLASS__ . " is already registered");
     }
     $session = Environment::getService('session');
     if (!$session->isStarted()) {
         $session->start();
     }
     self::$session = $session->getSection('PavelMaca.Captcha');
     if (!self::$defaultFontFile) {
         self::$defaultFontFile = __DIR__ . "/fonts/Vera.ttf";
     }
     FormContainer::extensionMethod('addCaptcha', callback(__CLASS__, 'addCaptcha'));
     self::$registered = TRUE;
 }
コード例 #11
0
ファイル: MenuServiceTest.php プロジェクト: janmarek/Neuron
 protected function setUp()
 {
     $em = Environment::getService("Doctrine\\ORM\\EntityManager");
     $this->object = new Service($em);
 }
コード例 #12
0
ファイル: cli.php プロジェクト: janmarek/Neuron
<?php

use Nette\Environment;
use Symfony\Component\Console;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\Command as DoctrineCommand;
use Doctrine\DBAL\Tools\Console\Command as DoctrineDBALCommand;
use Neuron\Console\Command as NeuronCommand;
require __DIR__ . '/../../../index.php';
$em = Environment::getService('Doctrine\\ORM\\EntityManager');
$helperSet = new Console\Helper\HelperSet();
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
$cli = new Console\Application('Doctrine & Neuron Command Line Interface', Doctrine\ORM\Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
$cli->addCommands(array(new DoctrineDBALCommand\RunSqlCommand(), new DoctrineDBALCommand\ImportCommand(), new DoctrineCommand\ClearCache\MetadataCommand(), new DoctrineCommand\ClearCache\ResultCommand(), new DoctrineCommand\ClearCache\QueryCommand(), new DoctrineCommand\SchemaTool\CreateCommand(), new DoctrineCommand\SchemaTool\UpdateCommand(), new DoctrineCommand\SchemaTool\DropCommand(), new DoctrineCommand\EnsureProductionSettingsCommand(), new DoctrineCommand\ConvertDoctrine1SchemaCommand(), new DoctrineCommand\GenerateRepositoriesCommand(), new DoctrineCommand\GenerateEntitiesCommand(), new DoctrineCommand\GenerateProxiesCommand(), new DoctrineCommand\ConvertMappingCommand(), new DoctrineCommand\RunDqlCommand(), new DoctrineCommand\ValidateSchemaCommand(), new NeuronCommand\GenerateForm(), new NeuronCommand\GenerateModel(), new NeuronCommand\GenerateCrud(), new NeuronCommand\GenerateFrontPresenter()));
$cli->run();
コード例 #13
0
ファイル: shortcuts.php プロジェクト: vbuilder/framework
/**
 * Translates the given string with plural and vsprintf.
 *
 * @deprecated
 * @param string
 * @param string
 * @param int plural form (positive number)
 * @param array for vsprintf
 * @return string
 */
function _nx($single, $plural, $number, array $args)
{
    // trigger_error(__FUNCTION__ . '() is deprecated; use __(array(\$single, \$plural), array(\$number, $args[0], $args[1], ...) instead.', E_USER_DEPRECATED);
    return Nette\Environment::getService('translator')->translate(array($single, $plural), array_merge(array($number), $args));
}
コード例 #14
0
ファイル: TexylaPresenter.php プロジェクト: janmarek/Neuron
 /**
  * Texyla preview
  */
 public function actionPreview()
 {
     $texy = Environment::getService("Texy");
     $html = $texy->process(Environment::getHttpRequest()->getPost("texy"));
     $this->sendResponse(new RenderResponse($html));
 }
コード例 #15
0
ファイル: TemplateHelper.php プロジェクト: JanTvrdik/Neuron
	/**
	 * @param string texy source
	 * @return string html code
	 */
	public static function process($text)
	{
		return Environment::getService("Texy")->process($text);
	}
コード例 #16
0
ファイル: User.php プロジェクト: jakubkulhan/nette
 /**
  * Returns current authorization handler.
  * @return Nette\Security\IAuthorizator
  */
 public final function getAuthorizationHandler()
 {
     if ($this->authorizationHandler === NULL) {
         $this->authorizationHandler = Environment::getService('Nette\\Security\\IAuthorizator');
     }
     return $this->authorizationHandler;
 }
コード例 #17
0
	/**
	 * Returns TemplateLocator.
	 *
	 * @author   Jan Tvrdík
	 * @return   TemplateLocator
	 */
	protected function getTemplateLocator()
	{
		return Env::getService('TemplateLocator');
	}