Пример #1
0
 public function testDelete()
 {
     $company = new Company();
     $this->objectManagerMock->shouldReceive('remove')->once()->with($company)->andReturn(true);
     $this->objectManagerMock->shouldReceive('flush')->once();
     $this->companyManager->delete($company);
 }
Пример #2
0
 public function testDelete()
 {
     $timeCategory = new TimeCategory();
     $this->objectManagerMock->shouldReceive('remove')->once()->with($timeCategory)->andReturn(true);
     $this->objectManagerMock->shouldReceive('flush')->once();
     $this->timeCategoryManager->delete($timeCategory);
 }
Пример #3
0
 public function testGetNodeTypes()
 {
     $nodetypes = $this->om->getNodeTypes();
     $this->assertInstanceOf('DOMDocument', $nodetypes);
     $nodetypes = $this->om->getNodeTypes(array('nt:folder', 'nt:file'));
     $this->assertInstanceOf('DOMDocument', $nodetypes);
 }
Пример #4
0
 /**
  * @dataProvider provideArrayAccess
  */
 public function testArrayAccess($paths, $batchSize, $options)
 {
     $options = array_merge(array('nb_fetches' => null, 'target' => null, 'iterate_result' => null), $options);
     $nbFetches = $options['nb_fetches'];
     $targets = (array) $options['target'];
     $iterateResult = $options['iterate_result'];
     $nodes = array();
     foreach ($paths as $path) {
         $node = $this->getNodeMock();
         $nodes[$path] = $node;
     }
     $this->objectManager->expects($this->exactly($nbFetches))->method('getNodesByPathAsArray')->will($this->returnCallback(function ($paths) use($nodes) {
         $ret = array();
         foreach ($paths as $path) {
             $ret[$path] = $nodes[$path];
         }
         return $ret;
     }));
     $nodes = new NodePathIterator($this->objectManager, $paths, null, null, $batchSize);
     if ($iterateResult) {
         for ($i = 0; $i < $iterateResult; $i++) {
             // if its not valid its at the end of the stack ... probably
             if (false === $nodes->valid()) {
                 continue;
             }
             $nodes->current($nodes);
             $nodes->next($nodes);
         }
     }
     $res = array();
     foreach ($targets as $target) {
         $res[$target] = $nodes[$target];
     }
 }
Пример #5
0
 /**
  * This method is executed after initialize(). It usually contains the logic
  * to execute to complete this command task.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $maxResults = $input->getOption('max-results');
     // Use ->findBy() instead of ->findAll() to allow result sorting and limiting
     $users = $this->em->getRepository('AppBundle:User')->findBy(array(), array('id' => 'DESC'), $maxResults);
     // Doctrine query returns an array of objects and we need an array of plain arrays
     $usersAsPlainArrays = array_map(function ($user) {
         return array($user->getId(), $user->getUsername(), $user->getEmail(), implode(', ', $user->getRoles()));
     }, $users);
     // In your console commands you should always use the regular output type,
     // which outputs contents directly in the console window. However, this
     // particular command uses the BufferedOutput type instead.
     // The reason is that the table displaying the list of users can be sent
     // via email if the '--send-to' option is provided. Instead of complicating
     // things, the BufferedOutput allows to get the command output and store
     // it in a variable before displaying it.
     $bufferedOutput = new BufferedOutput();
     $table = new Table($bufferedOutput);
     $table->setHeaders(array('ID', 'Username', 'Email', 'Roles'))->setRows($usersAsPlainArrays);
     $table->render();
     // instead of displaying the table of users, store it in a variable
     $tableContents = $bufferedOutput->fetch();
     if (null !== ($email = $input->getOption('send-to'))) {
         $this->sendReport($tableContents, $email);
     }
     $output->writeln($tableContents);
 }
Пример #6
0
 public function testDelete()
 {
     $projectStatus = new ProjectStatus();
     $this->objectManagerMock->shouldReceive('remove')->once()->with($projectStatus)->andReturn(true);
     $this->objectManagerMock->shouldReceive('flush')->once();
     $this->projectStatusManager->delete($projectStatus);
 }
Пример #7
0
 public function testDelete()
 {
     $employee = new Employee();
     $this->objectManagerMock->shouldReceive('remove')->once()->with($employee)->andReturn(true);
     $this->objectManagerMock->shouldReceive('flush')->once();
     $this->employeeManager->delete($employee);
 }
 /**
  * Make a remote call to freegeoip.net to detect country of current customer session and store it into session
  *
  * @return $this
  */
 public function saveVisitorData($observer)
 {
     $clientIP = $this->_request->getClientIp();
     $httpClient = new Client();
     $clientIP = $this->getRandomeIp($clientIP);
     $uri = self::URL_GEO_IP_SITE . $clientIP;
     $httpClient->setUri($uri);
     $httpClient->setOptions(array('timeout' => 30));
     try {
         $response = JsonDecoder::decode($httpClient->send()->getBody());
         $this->_customerSession->setVisitorData($response);
         //save to database
         $currenttime = date('Y-m-d H:i:s');
         $model = $this->_objectManager->create('Bluecom\\Freegeoip\\Model\\Visitor');
         $model->setData('visitor_ip', $response->ip);
         $model->setData('country_code', $response->country_code);
         $model->setData('country_name', $response->country_name);
         $model->setData('region_code', $response->region_code);
         $model->setData('region_name', $response->region_name);
         $model->setData('city', $response->city);
         $model->setData('zip_code', $response->zip_code);
         $model->setData('latitude', $response->latitude);
         $model->setData('longitude', $response->longitude);
         $model->setData('metro_code', $response->metro_code);
         $model->setData('browser', $_SERVER['HTTP_USER_AGENT']);
         $model->setData('os', php_uname());
         $model->setData('created', $currenttime);
         $model->save();
     } catch (\Exception $e) {
         $this->_logger->critical($e);
     }
     return $this;
 }
 /**
  * Initializes extension driver
  *
  * @param ObjectManager $objectManager
  * @param string $extensionNamespace
  * @param object $annotationReader
  */
 public function __construct($objectManager, $extensionNamespace, $annotationReader)
 {
     $this->objectManager = $objectManager;
     $this->annotationReader = $annotationReader;
     $this->extensionNamespace = $extensionNamespace;
     $omDriver = $objectManager->getConfiguration()->getMetadataDriverImpl();
     $this->driver = $this->getDriver($omDriver);
 }
 private function initialize()
 {
     if (!isset($this->manager)) {
         throw new Exception('No ObjectManager set');
     }
     $currencies = $this->manager->getRepository($this->currencyClass)->findAll();
     foreach ($currencies as $currency) {
         $this[$currency->getCode()] = $currency;
     }
 }
Пример #11
0
 /**
  * Load objects
  *
  * @throws RuntimeException
  * @throws Exception\InvalidRepositoryResultException
  * @return void
  */
 protected function loadObjects()
 {
     if (!empty($this->objects)) {
         return;
     }
     $findMethod = (array) $this->getFindMethod();
     if (!$findMethod) {
         $findMethodName = 'fetchAll';
         $objects = $this->tableCible->fetchAll();
     } else {
         if (!isset($findMethod['name'])) {
             throw new RuntimeException('No method name was set');
         }
         $findMethodName = $findMethod['name'];
         $findMethodParams = isset($findMethod['params']) ? array_change_key_case($findMethod['params']) : array();
         $repository = $this->serviceManager->getRepository($this->targetClass);
         if (!method_exists($repository, $findMethodName)) {
             throw new RuntimeException(sprintf('Method "%s" could not be found in repository "%s"', $findMethodName, get_class($repository)));
         }
         $r = new ReflectionMethod($repository, $findMethodName);
         $args = array();
         foreach ($r->getParameters() as $param) {
             if (array_key_exists(strtolower($param->getName()), $findMethodParams)) {
                 $args[] = $findMethodParams[strtolower($param->getName())];
             } elseif ($param->isDefaultValueAvailable()) {
                 $args[] = $param->getDefaultValue();
             } elseif (!$param->isOptional()) {
                 throw new RuntimeException(sprintf('Required parameter "%s" with no default value for method "%s" in repository "%s"' . ' was not provided', $param->getName(), $findMethodName, get_class($repository)));
             }
         }
         $objects = $r->invokeArgs($repository, $args);
     }
     GuardUtils::guardForArrayOrTraversable($objects, sprintf('%s::%s() return value', $this->targetClass, $findMethodName), 'DoctrineModule\\Form\\Element\\Exception\\InvalidRepositoryResultException');
     $this->objects = $objects;
 }
Пример #12
0
 /**
  * throw new exeption
  * exeption go to logger
  */
 public static function getStaticException($exception)
 {
     /**
      * get error message
      */
     $ErrorMessage = $exception->getMessage();
     /**
      * get error number
      */
     $ErrorNumber = $exception->getCode();
     /**
      * get error file (in source)
      */
     $ErrorFile = $exception->getFile();
     /**
      * get error line (in source)
      */
     $ErrorLine = $exception->getLine();
     /**
      * object instance of objectManager
      */
     $objectManager = ObjectManager::getInstance();
     /**
      * Logger instance 
      */
     $Logger = $objectManager->getObject('Logger');
     /**
      * LogError to Logger
      */
     $Logger->LogError($ErrorNumber, $ErrorMessage, $ErrorFile, $ErrorLine);
 }
Пример #13
0
 /**
  * @public
  *
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new ObjectManager();
     }
     return self::$instance;
 }
Пример #14
0
 /**
  * Magic function GET
  *
  * @return void
  */
 public function connect()
 {
     // Instance of ObjectManager
     $this->objectManager = ObjectManager::getInstance();
     // Connect Database
     $this->DatabasePointer = $this->objectManager->getObject('DBConnectManager')->connectRouter();
     return $this;
 }
Пример #15
0
 /**
  * Get MTF Object Manager instance
  *
  * @return ObjectManager
  */
 public static function getObjectManager()
 {
     if (!($objectManager = ObjectManager::getInstance())) {
         $objectManagerFactory = new self();
         $objectManager = $objectManagerFactory->create();
     }
     return $objectManager;
 }
Пример #16
0
 public function run()
 {
     Request::parse();
     $controller = 'PY\\App\\Controllers\\' . ucfirst(Request::$controller);
     $method = Request::$method;
     $objectManager = ObjectManager::getInstance();
     echo $objectManager->invokeMethod($objectManager->get($controller), $method);
 }
Пример #17
0
 public function getProperty($propname)
 {
     $props = ObjectManager::getObjectProperties($this->uri);
     if (array_key_exists($propname, $props)) {
         return $props[$propname];
     }
     return null;
 }
Пример #18
0
 /**
  * Initialize
  */
 public function __construct()
 {
     // ObjectManager
     $this->objectManager = ObjectManager::getInstance();
     // Registry
     $this->registry = $this->objectManager->getObject('Registry');
     // FLRP protocol
     $this->flrp = $this->objectManager->getObject('flrp');
 }
 public function processObject($path, $params)
 {
     $objectManager = new ObjectManager($path);
     $response = $objectManager->prepare()->process($params);
     if (!is_bool($response)) {
         throw new \Exception("Invalid {$path} response type: must be boolean");
     }
     return $response;
 }
Пример #20
0
 /**
  * Get the object configuration
  *
  * If no identifier is passed the object config of this object will be returned. Function recursively
  * resolves identifier aliases and returns the aliased identifier.
  *
  * @param  mixed $identifier An ObjectIdentifier, identifier string or object implementing ObjectInterface
  * @return ObjectConfig
  */
 public final function getConfig($identifier = null)
 {
     if (isset($identifier)) {
         $result = $this->__object_manager->getIdentifier($identifier)->getConfig();
     } else {
         $result = $this->__object_config;
     }
     return $result;
 }
Пример #21
0
 /**
  * @public
  * destroy all objects
  */
 public static function destroyAllObjects()
 {
     $objectManager = ObjectManager::getInstance();
     self::$objects = $objectManager->getAllObjectInstances();
     foreach (self::$objects as $key => $ObjectInstance) {
         if (is_object($ObjectInstance)) {
             self::destroyObject($ObjectInstance);
         }
     }
     self::BufferEmpty();
 }
Пример #22
0
 /**
  * Initializes database table object 
  * params
  * :: Table :: Name of Database Table
  * :: Fields:: Array with Fields from Table
  *
  * @return void
  */
 public function __construct($table, $fields)
 {
     // Database Table
     $this->table = $table;
     // Init Fields of Table
     foreach ($fields as $key) {
         $this->fields[$key] = null;
     }
     // Instance of ObjectManager
     $this->objectManager = ObjectManager::getInstance();
     // Connect Database
     $this->DatabasePointer = $this->objectManager->getObject('DBConnectManager')->connectRouter();
 }
Пример #23
0
 /**
  * Get the configuration for specific object class
  * if cache driver is present it scans it also
  *
  * @param ObjectManager $objectManager
  * @param string $class
  * @return array
  */
 public function getConfiguration($objectManager, $class)
 {
     $config = array();
     if (isset($this->configurations[$class])) {
         $config = $this->configurations[$class];
     } else {
         $cacheDriver = $objectManager->getMetadataFactory()->getCacheDriver();
         $cacheId = ExtensionMetadataFactory::getCacheId($class, $this->getNamespace());
         if ($cacheDriver && ($cached = $cacheDriver->fetch($cacheId)) !== false) {
             $this->configurations[$class] = $cached;
             $config = $cached;
         }
     }
     return $config;
 }
Пример #24
0
 /**
  * @public function
  * ErrorHandling for trigger_error
  *
  */
 public static function ErrorHandling($ErrorNumber, $ErrorMessage, $ErrorFile, $ErrorLine)
 {
     /**
      * object instance of objectManager
      */
     $objectManager = ObjectManager::getInstance();
     /**
      * Logger instance 
      */
     $Logger = $objectManager->getObject('Logger');
     /**
      * LogError to Logger
      */
     $Logger->LogError($ErrorNumber, $ErrorMessage, $ErrorFile, $ErrorLine);
 }
Пример #25
0
 /**
  * Initialize
  */
 public function __construct()
 {
     // ObjectManager aufrufen
     $this->objectManager = ObjectManager::getInstance();
     // Registry
     $this->registry = $this->objectManager->getObject('Registry');
     // Request
     $this->request = $this->objectManager->getObject('Request');
     // Debug Trace
     $this->debug = $this->objectManager->getObject('Debug');
     // Database access point
     $this->database = $this->objectManager->getObject('Database');
     $this->database->connect();
     return $this;
 }
Пример #26
0
 public function testSeek()
 {
     $nodes = array();
     $nodes2 = array();
     foreach (array('p1', 'p2', 'p3') as $name) {
         $nodes[$name] = $this->getNodeMock();
     }
     foreach (array('p8', 'p9') as $name) {
         $nodes2[$name] = $this->getNodeMock();
     }
     $this->objectManager->expects($this->at(0))->method('getNodesByPathAsArray')->with(array('p1', 'p2', 'p3'))->will($this->returnValue($nodes));
     $this->objectManager->expects($this->at(1))->method('getNodesByPathAsArray')->with(array('p8', 'p9'))->will($this->returnValue($nodes2));
     $iterator = new NodePathIterator($this->objectManager, array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), null, null, 3);
     $iterator->seek(7);
     $iterator->valid();
     $this->assertEquals($nodes2['p8'], $iterator->current());
 }
Пример #27
0
 /**
  * static funtion
  * setHiddenFieldsOfRoute
  * 
  * @params NameOfUnity
  * @params NameOfScreen
  * @params NameOfAction
  *
  */
 public static function setHiddenFieldsOfRoute($NameOfUnity, $NameOfScreen, $NameOfAction)
 {
     // ObjectManager
     self::$objectManager = ObjectManager::getInstance();
     // Configuration
     self::$registry = self::$objectManager->getObject('Registry');
     // Fields of USC Routing
     $AppsFieldUnity = self::$registry->hiddenfieldsUnity;
     $AppsFieldScreen = self::$registry->hiddenfieldsScreen;
     $AppsFieldAction = self::$registry->hiddenfieldsAction;
     // Line Feed
     self::$CR = BaseHelperEscapeChars::getEscapeChar('CR');
     // set ARRAY
     self::$routing = array(self::$CR . '<input type="hidden" id="' . $AppsFieldUnity . '"  name="' . $AppsFieldUnity . '"  value="' . $NameOfUnity . '">' . self::$CR, '<input type="hidden" id="' . $AppsFieldScreen . '" name="' . $AppsFieldScreen . '" value="' . $NameOfScreen . '">' . self::$CR, '<input type="hidden" id="' . $AppsFieldAction . '" name="' . $AppsFieldAction . '" value="' . $NameOfAction . '">' . self::$CR);
     // Return of USC Routing
     return self::$routing;
 }
Пример #28
0
 /**
  * Initialize
  */
 public function __construct()
 {
     // ObjectManager aufrufen
     $this->objectManager = ObjectManager::getInstance();
     // Registry
     $this->registry = $this->objectManager->getObject('Registry');
     // Request
     $this->request = $this->objectManager->getObject('Request');
     // Debug Trace
     $this->debug = $this->objectManager->getObject('Debug');
     /*
      *  Autoconnect ?
      */
     if ($this->registry->databaseAutoconnect == true) {
         // Database objct
         $this->database = $this->objectManager->getObject('Database');
         $this->database->connect();
     }
     // back instance of object
     return $this;
 }
Пример #29
0
 /**
  * @private 
  * 
  * flow
  */
 private function flow()
 {
     #Benchmark::start('CON');
     #Benchmark::start('SYS');
     $this->debug = $this->objectManager->getObject('Debug');
     // ---------------------------------------------------------------------------------
     // Filter-/Controller chains instances
     // ---------------------------------------------------------------------------------
     $this->initChains();
     // ---------------------------------------------------------------------------------
     // Controller Rules
     // ---------------------------------------------------------------------------------
     #print_r(NameSpaces::$NSP_Application);
     $this->ControllerRulesClass = NameSpaces::getNamespaceOfClassSpecification('ControllerRules', true);
     if (is_array($this->ControllerRulesClass)) {
         $this->ControllerRules = $this->objectManager->getObject('ControllerRules')->rules();
     }
     // ---------------------------------------------------------------------------------
     // Request
     // GET,POST,FILES,SERVER,HEADER,COOKIE
     // ---------------------------------------------------------------------------------
     // Request auslösen
     $request = $this->objectManager->getObject('Request');
     // ---------------------------------------------------------------------------------
     // ActionController
     // Names from Dispatcher and Router
     //
     // $dispatcher->getControllerName();
     // $dispatcher->getActionName();
     // ---------------------------------------------------------------------------------
     // Dispatcher
     $dispatcher = $this->objectManager->getObject('Dispatcher');
     // flrp (FLOWLite Router Protocol)
     $this->flrp = $this->objectManager->getObject('flrp');
     // Dispatch Controller and Action over Routing
     $dispatcher->dispatchControllerAction($request);
     // get Controller over Protocol FLRP
     $this->controller = $this->flrp->getController();
     // get Action over Protocol FLRP
     $this->action = $this->flrp->getAction();
     // ---------------------------------------------------------------------------------
     // RequestFilters
     // ---------------------------------------------------------------------------------
     // Filter ermitteln (RequestFilter) FilterChain
     $requestFilters = NameSpaces::getNamespaceOfClassSpecification('RequestFilter');
     if (is_array($requestFilters) && count($requestFilters) > 0) {
         // Filter instanzieren
         $this->initRequestFilter($requestFilters);
         // Alle Filter ausführen (Request übergeben)
         $this->requestFilters->execute($request);
     }
     // ---------------------------------------------------------------------------------
     // RequestValidator
     // ---------------------------------------------------------------------------------
     // Validator ermitteln (RequestValidator) ValidatorChain
     $requestValidators = NameSpaces::getNamespaceOfClassSpecification('RequestValidator');
     if (is_array($requestValidators) && count($requestValidators) > 0) {
         // Validator instanzieren
         $this->initRequestValidators($requestValidators);
         // Alle Validatoren ausführen (Request übergeben)
         $this->requestValidators->execute($request);
     }
     // ---------------------------------------------------------------------------------
     // PreController
     // Before Action Controller
     // ---------------------------------------------------------------------------------
     // PreController ermitteln
     $PreControllers = NameSpaces::getNamespaceOfClassSpecification('PreController');
     if (is_array($PreControllers) && count($PreControllers) > 0) {
         // Controller instanzieren
         $this->initPreControllers($PreControllers);
         // Controller ausführen (Request übergeben)
         $this->PreControllers->execute($request);
     }
     // ---------------------------------------------------------------------------------
     // PostController
     // After Action Controller
     // ---------------------------------------------------------------------------------
     // PreController ermitteln
     $PostControllers = NameSpaces::getNamespaceOfClassSpecification('PostController');
     if (is_array($PostControllers) && count($PostControllers) > 0) {
         // Controller instanzieren
         $this->initPostControllers($PostControllers);
     }
     // ---------------------------------------------------------------------------------
     // @@@ ActionController
     // @@@ action with praefix "Action"
     // @@@ run
     // ---------------------------------------------------------------------------------
     // Init Object
     $this->debug->trace('Action Controller: ' . $this->controller, 'FrontController');
     $this->debug->trace('Action : ' . $this->action, 'FrontController');
     // Existiert eine Controller Whitelist
     $ControllerExceptions = $this->objectManager->getObject('ControllerExceptions')->getExceptions();
     // @@@ Check Controller
     // @@@
     // @@@ Ist der Controller innerhalb der Whitelist zu finden (Kann, muss nicht)
     // @@@ Der Controller muss im Namespacebereich der Application gefunden werden.
     // @@@
     #echo $this->controller; echo "<br>";
     #echo $this->action; echo "<br>";
     #Benchmark::stop('CON');
     #echo "CON ";
     #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('CON'),array(BaseHelperEscapeChars::getEscapeChar('BR')));
     #print_r(NameSpaces::$NSP_Application);
     #Benchmark::stop('SYS');
     #echo "SYS ";
     #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('SYS'),array(BaseHelperEscapeChars::getEscapeChar('BR')));
     if (in_array($this->controller, $ControllerExceptions) || NameSpaces::classExistsInApplication($this->controller)) {
         // Inizialization controller
         $controller = $this->initActionController($this->controller);
         // Action
         $action = trim($this->action) . 'Action';
         #echo $this->controller;
         #echo "<br>";
         #echo $this->action;
         #exit;
         // Call controller and action
         // Check of object
         // Check of callable
         if ($this->isValid($controller) && is_callable(array($controller, $action))) {
             $controller->{$action}();
         } else {
             // Controller nicht gefunden, kein Object oder nicht aufrufbar
             throw new Exception('Controller not callable (' . $this->controller . '->' . $action . ') !', 273562354);
         }
     } else {
         // Controller nicht gefunden
         throw new Exception('Controller or Action not found (' . $this->controller . ') ! ', 273562352);
     }
     // ---------------------------------------------------------------------------------
     // PostController
     // After Action Controller
     // ---------------------------------------------------------------------------------
     if ($this->registry->SystemFrontControllerRepeater === false) {
         if (is_array($PostControllers) && count($PostControllers) > 0) {
             $this->PostControllers->execute($request);
         }
     } else {
         # $this->deletePostControllers($PostControllers);
     }
 }
Пример #30
0
 /**
  *
  *
  */
 public function flush()
 {
     $this->dm->getSchemaManager()->ensureIndexes();
     $this->dm->flush(null, array('safe' => true));
 }