erro não acha mais as classes do adianti boa noite, to testando relatórios feitos no Jasper Repoerter exemplo do nosso amigo Armando Ribeiro, está funcionando perfeito, só que apos eu usar a classe PHJasper parece que não acha mais as classes do adianti, neste exemplo abaixo tento fazer um new TMessage e fala que a classe TMessage não existe. $jasper = new PHPJasperPHPJasper; $jasper->process($input,$output,$...
RS
erro não acha mais as classes do adianti  
boa noite, to testando relatórios feitos no Jasper Repoerter exemplo do nosso amigo Armando Ribeiro, está funcionando perfeito, só que apos eu usar a classe PHJasper parece que não acha mais as classes do adianti, neste exemplo abaixo tento fazer um new TMessage e fala que a classe TMessage não existe.

$jasper = new PHPJasper\PHPJasper; $jasper->process($input,$output,$options)->execute(); new TMessage('info', 'Relatório Processado');


Erro que retorna:

Fatal error: Uncaught Error: Class 'TMessage' not found in C:wamp64wwwsgoappcontrolsgolistsProfissionalList.class.php on line 353


Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (7)


NR

Você está usando namespace?
RS

bom dia Nataniel, creio que sim, esta classe PHPJasper deve usar.
RS

Classe PHPJasper

 
  1. <?php
  2. /*
  3. * This file is part of the PHPJasper.
  4. *
  5. * (c) Daniel Rodrigues (geekcom)
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace PHPJasper;
  12. class PHPJasper
  13. {
  14. /**
  15. * @var string
  16. */
  17. protected $command;
  18. /**
  19. * @var string
  20. */
  21. protected $executable;
  22. /**
  23. * @var string
  24. */
  25. protected $pathExecutable;
  26. /**
  27. * @var bool
  28. */
  29. protected $windows;
  30. /**
  31. * @var array
  32. */
  33. protected $formats = ['pdf', 'rtf', 'xls', 'xlsx', 'docx', 'odt', 'ods', 'pptx', 'csv', 'html', 'xhtml', 'xml', 'jrprint'];
  34. /**
  35. * PHPJasper constructor
  36. */
  37. public function __construct()
  38. {
  39. $this->executable = 'jasperstarter';
  40. $this->pathExecutable = __DIR__ . '/../bin/jasperstarter/bin';
  41. $this->windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false;
  42. }
  43. /**
  44. * @return string
  45. */
  46. private function checkServer()
  47. {
  48. return $this->command = $this->windows ? $this->executable : './' . $this->executable;
  49. }
  50. /**
  51. * @param string $input
  52. * @param string $output optional
  53. * @return $this
  54. * @throws Exception\InvalidInputFile
  55. */
  56. public function compile(string $input, string $output = '')
  57. {
  58. if (!is_file($input)) {
  59. throw new \PHPJasper\Exception\InvalidInputFile();
  60. }
  61. $this->command = $this->checkServer();
  62. $this->command .= ' compile ';
  63. $this->command .= '"' . realpath($input) . '"';
  64. if (!empty($output)) {
  65. $this->command .= ' -o ' . "\"$output\"";
  66. }
  67. return $this;
  68. }
  69. /**
  70. * @param string $input
  71. * @param string $output
  72. * @param array $options
  73. * @return $this
  74. * @throws Exception\InvalidInputFile
  75. * @throws Exception\InvalidFormat
  76. */
  77. public function process(string $input, string $output, array $options = [])
  78. {
  79. $options = $this->parseProcessOptions($options);
  80. if (!$input) {
  81. throw new \PHPJasper\Exception\InvalidInputFile();
  82. }
  83. $this->validateFormat($options['format']);
  84. $this->command = $this->checkServer();
  85. if ($options['locale']) {
  86. $this->command .= " --locale {$options['locale']}";
  87. }
  88. $this->command .= ' process ';
  89. $this->command .= "\"$input\"";
  90. $this->command .= ' -o ' . "\"$output\"";
  91. $this->command .= ' -f ' . join(' ', $options['format']);
  92. if ($options['params']) {
  93. $this->command .= ' -P ';
  94. foreach ($options['params'] as $key => $value) {
  95. $this->command .= " " . $key . '="' . $value . '" ' . " ";
  96. }
  97. }
  98. if ($options['db_connection']) {
  99. $mapDbParams = [
  100. 'driver' => '-t',
  101. 'username' => '-u',
  102. 'password' => '-p',
  103. 'host' => '-H',
  104. 'database' => '-n',
  105. 'port' => '--db-port',
  106. 'jdbc_driver' => '--db-driver',
  107. 'jdbc_url' => '--db-url',
  108. 'jdbc_dir' => '--jdbc-dir',
  109. 'db_sid' => '-db-sid',
  110. 'xml_xpath' => '--xml-xpath',
  111. 'data_file' => '--data-file',
  112. 'json_query' => '--json-query'
  113. ];
  114. foreach ($options['db_connection'] as $key => $value) {
  115. $this->command .= " {$mapDbParams[$key]} {$value}";
  116. }
  117. }
  118. if ($options['resources']) {
  119. $this->command .= " -r {$options['resources']}";
  120. }
  121. return $this;
  122. }
  123. /**
  124. * @param array $options
  125. * @return array
  126. */
  127. protected function parseProcessOptions(array $options)
  128. {
  129. $defaultOptions = [
  130. 'format' => ['pdf'],
  131. 'params' => [],
  132. 'resources' => false,
  133. 'locale' => false,
  134. 'db_connection' => []
  135. ];
  136. return array_merge($defaultOptions, $options);
  137. }
  138. /**
  139. * @param $format
  140. * @throws Exception\InvalidFormat
  141. */
  142. protected function validateFormat($format)
  143. {
  144. if (!is_array($format)) {
  145. $format = [$format];
  146. }
  147. foreach ($format as $value) {
  148. if (!in_array($value, $this->formats)) {
  149. throw new \PHPJasper\Exception\InvalidFormat();
  150. }
  151. }
  152. }
  153. /**
  154. * @param string $input
  155. * @return $this
  156. * @throws \Exception
  157. */
  158. public function listParameters(string $input)
  159. {
  160. if (!is_file($input)) {
  161. throw new \PHPJasper\Exception\InvalidInputFile();
  162. }
  163. $this->command = $this->checkServer();
  164. $this->command .= ' list_parameters ';
  165. $this->command .= '"'.realpath($input).'"';
  166. return $this;
  167. }
  168. /**
  169. * @param bool $user
  170. * @return mixed
  171. * @throws Exception\InvalidCommandExecutable
  172. * @throws Exception\InvalidResourceDirectory
  173. * @throws Exception\ErrorCommandExecutable
  174. */
  175. public function execute($user = false)
  176. {
  177. $this->validateExecute();
  178. $this->addUserToCommand($user);
  179. $output = [];
  180. $returnVar = 0;
  181. chdir($this->pathExecutable);
  182. exec($this->command, $output, $returnVar);
  183. if ($returnVar !== 0) {
  184. throw new \PHPJasper\Exception\ErrorCommandExecutable();
  185. }
  186. return $output;
  187. }
  188. /**
  189. * @return string
  190. */
  191. public function output()
  192. {
  193. return $this->command;
  194. }
  195. /**
  196. * @param $user
  197. */
  198. protected function addUserToCommand($user)
  199. {
  200. if ($user && !$this->windows) {
  201. $this->command = 'su -u ' . $user . " -c \"" . $this->command . "\"";
  202. }
  203. }
  204. /**
  205. * @throws Exception\InvalidCommandExecutable
  206. * @throws Exception\InvalidResourceDirectory
  207. */
  208. protected function validateExecute()
  209. {
  210. if (!$this->command) {
  211. throw new \PHPJasper\Exception\InvalidCommandExecutable();
  212. }
  213. if (!is_dir($this->pathExecutable)) {
  214. throw new \PHPJasper\Exception\InvalidResourceDirectory();
  215. }
  216. }
  217. }
  218. </code>
NR

Adicione o código abaixo na sua classe e veja se funciona:
 
  1. <?php
  2. use Adianti\Widget\Dialog\TMessage;
  3. ?>
RS

realmente o PHPJasper usa o namespace logo no inicio da classe tem

namespace PHPJasper;


use AdiantiWidgetDialogTMessage; é para colocar no PHPJasper? bom mas coloquei na classe onde chama o PHPJasper e no PHPJasper e deu erro

Parse error: syntax error, unexpected 'use' (T_USE) in
RS

Continuo com este problema, se alguem tiver alguna luz...obrigado
NR

https://pt.stackoverflow.com/questions/51014/erro-unexpected-use-t-use-ao-usar-autoload