Javadoc - multiline comment with annotation (# sign) - annotations

Based on the answer: Multiple line code example in Javadoc comment I'd like to write following javadoc (on class level).
/**
* Whatever txt1 ...
* <pre>
* {#code
* #Lob
* private byte[] foo;
* }
* </pre>
* Whatever txt2 ...
*
* #author $Author: $
*/
public class Foo {
However it renders like this (in eclipse preview):
Whatever txt1 ...
Author:
$Author: $
#Lob
private byte[] foo;
}
Whatever txt2 ...
Please note the messed up order of the author annotation
Any idea what is the appropriate format/how to properly escate # sign?
As once going for:
/**
* Whatever txt1 ...
* <pre>
* {#code
* Lob
* private byte[] foo;
* }
* </pre>
* Whatever txt2 ...
*
* #author $Author: $
*/
public class Foo {
it's rendered correctly:
Whatever txt1 ...
Lob
private byte[] foo;
Whatever txt2 ...
Author:
$Author: $

OK, I've found answer elsewhere: https://stackoverflow.com/questions/2290757/how-can-you-escape-the-character-in-javadoc
the thing is to go for {#literal #}
So then:
/**
* Whatever txt1 ...
* <pre>
* {#code
* {#literal #}Lob
* private byte[] foo;
* }
* </pre>
* Whatever txt2 ...
*
* #author $Author: $
*/
public class Foo {
renders correctly to:
Whatever txt1 ...
{#Lob
private byte[] foo;
}
Whatever txt2 ...
Author:
$Author: $

because you refer to the multiline - code example - thread:
The following answer in this thread has your example - escaping the "#" sign on "#Override"
https://stackoverflow.com/a/13512524
Regards
Christoph

Related

error on feuser edit: is not integer

I extend feuser with custom fields. All work good. If I type integer value it was save good. But if I type string value I get error - 1332933658: "" is no integer. You can see this on the follow screenshots.
enter image description here
ext_tables.php
#
# Table structure for table 'fe_users'
#
CREATE TABLE fe_users (
aboutmyself varchar(255) DEFAULT '' NOT NULL,
aboutmypartner varchar(255) DEFAULT '' NOT NULL,
tx_extbase_type varchar(255) DEFAULT '0' NOT NULL,
);
Model:
<?php
namespace Fhk\Feusersplus\Domain\Model;
/***************************************************************
*
* Copyright notice
*
* (c) 2017
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* User
*/
class User extends \In2code\Femanager\Domain\Model\User
{
/**
* aboutmyself
*
* #var int
*/
protected $aboutmyself = '';
/**
* aboutmypartner
*
* #var int
*/
protected $aboutmypartner = '';
/**
* Returns the aboutmyself
*
* #return int $aboutmyself
*/
public function getAboutmyself()
{
return (string)$this->aboutmyself;
}
/**
* Returns the aboutmypartner
*
* #return int $aboutmypartner
*/
public function getAboutmypartner()
{
return (string)$this->aboutmypartner;
}
/**
* Sets the aboutmyself
*
* #return void
*/
public function setAboutmyself($aboutmyself)
{
$this->aboutmyself = (string)$aboutmyself;
}
/**
* Sets the aboutmypartner
*
* #return void
*/
public function setAboutmypartner($aboutmypartner)
{
$this->aboutmypartner = (string)$aboutmypartner;
}
/**
* __construct
*/
public function __construct()
{
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* #return void
*/
protected function initStorageObjects()
{
}
}
The type hint for your fields aboutmyself and aboutmypartner is defined as
#var int
but you store a VARCHAR. Try changing the hint to
#var string
and clear all caches (also, emptying the typo3temp folder can't hurt).

EntityNotFoundException in doctrine 2 proxy class

What are the possible causes of EntityNotFoundException while accessing the proxy class properties in doctrine 2? Anyway, the following is my entities' structure:
/**
* #ORM\Table(name="comments")
*
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="comment_type", type="smallint")
* #ORM\DiscriminatorMap({
* 1 = "VisitorComment",
* 2 = "MemberComment"
* })
*/
class Comment
{
//with common properties of its subclasses
}
subclasses are as follows:
/**
* #ORM\Table(name="member_comments")
*/
class MemberComment extends Comment
{
/**
* owning side
*
* #var Member $author
*
* #ORM\ManyToOne(targetEntity="Member")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
*/
private $author;
/**
* Set author
*
* #param Member $author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Get author
*
* #return Member
*/
public function getAuthor()
{
return $this->author;
}
}
/**
* #ORM\Table(name="visitor_comments")
*/
class VisitorComment extends Comment
{
/**
* owning side
*
* #var Visitor $author
*
* #ORM\ManyToOne(targetEntity="Visitor")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
*/
private $author;
/**
* Set author
*
* #param string $author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Get author
*
* #return Visitor
*/
public function getAuthor()
{
return $this->author;
}
}
The exception occurs when I call $comment->getAuthor()->getFirstName() <assuming that author which is either a Member or Visitor entity has firstName property>. The getAuthor() in this case returns a proxy class of either VisitorProxy or MemberProxy.
Kindly help me. I'm still new to doctrine.
As Floricel found out, this can be caused by an invalid foreign key in a column that's points to the table that the Proxy class references.
#Dave Lancea is right I changed a FK to not Null and then started getting this error, manually updated a broken record, making it point to an existing entity and problem gone.

Generate merged entity class files with symfony2

I'm a little bit stuck with my poor knowledge of Symfony2 and Doctrine. Here is what I'm trying to do: I have two different files containing a class definition of the same class. I want to merge these two into a new class file.
I have an existing entity class file Foo.php:
/**
* #ORM\Entity
* #ORM\Table(name="foo")
*/
class Foo
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*
* #var int
*/
protected $id;
/**
* #ORM\Column(type="string")
*
* #var string
*/
protected $name;
/**
* #param string $name
* #return void
*/
public function setName($name)
{
$this->name = (string) $name;
}
/**
* #return string name
*/
public function getName()
{
return $this->name;
}
protected function someMagic($in) {
die('no magic happens.');
}
}
and a second entity class file with the same name Foo.php:
/**
* #ORM\Entity
* #ORM\Table(name="foo")
*/
class Foo
{
/**
* #ORM\Column(type="string")
*
* #var string
*/
protected $color;
/**
* #param string $name
* #return void
*/
public function setColor($color)
{
$this->color = $this->someColorMagic($color);
}
/**
* #return string name
*/
public function getColor()
{
return $this->color;
}
protected function someMagic($in) {
return 'magic: ' . $out;
}
}
How can I merge these two together (not at runtime, just during installation of a symfony application - could be done with a symfony console command like foobar:install) so I get a merged class Foo written to a file FooExtended.php that contains properties and methods of both classes and the doctrine annotations preserved?
Does Symfony (or the DoctrineBundle within) support stuff like this out of the box? Or can someone point me into the right direction how this can be achieved?
It now turned out with some changes in design I can solve my problem with simple class inheritance. So there is no need for a class merging at design time.

Case with doctrine2, symfony2 and postgresql entities

I have a problem with doctrine2 in symfony2 app with postgres database.
I get error:
SQLSTATE[3F000]: Invalid schema name: 7 ERROR: schema "main" does not exist
Problem is that my schema is Main not main. When I rename it, similar thing happends for table relation:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "main.brand_brandid_seq" does not exist
Problem is case sensitivity and I guess maybe it have something to do with quoting or some doctrine configuration.
Entity:
namespace MyB\Entity;
/**
* MyB\Entity\Brand
*
* #orm:Table(name="Main.Brand")
* #orm:Entity
*/
class Brand
{
/**
* #var integer $brandid
*
* #orm:Column(name="BrandId", type="integer", nullable=false)
* #orm:Id
* #orm:GeneratedValue(strategy="SEQUENCE")
* #orm:SequenceGenerator(sequenceName="Main.Brand_BrandId_seq", allocationSize="1", initialValue="1")
*/
private $brandid;
/**
* #var string $brandname
*
* #orm:Column(name="BrandName", type="string", length=32, nullable=false)
*/
private $brandname;
/**
* Set name.
*
* #param string $name
*/
public function setName($name) {
$this->brandname = $name;
}
}
Schema:
SET search_path = "Main", pg_catalog;
CREATE SEQUENCE "Brand_BrandId_seq"
START WITH 2
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
SET default_tablespace = '';
SET default_with_oids = false;
CREATE TABLE "Brand" (
"BrandId" integer DEFAULT nextval('"Brand_BrandId_seq"'::regclass) NOT NULL,
"BrandName" character varying(32) NOT NULL
);
Controller:
$reseller = new \MyB\Entity\Brand();
$reseller->setName('Sasa');
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($reseller);
$em->flush();
Any idea?
Try this
namespace MyB\Entity;
/**
* MyB\Entity\Brand
*
* #orm:Table(name="""Main"".""Brand""")
* #orm:Entity
*/
class Brand
{
/**
* #var integer $brandid
*
* #orm:Column(name="""BrandId""", type="integer", nullable=false)
* #orm:Id
* #orm:GeneratedValue(strategy="SEQUENCE")
* #orm:SequenceGenerator(sequenceName="""Main"".""Brand_BrandId_seq""", allocationSize="1", initialValue="1")
*/
private $brandid;
/**
* #var string $brandname
*
* #orm:Column(name="""BrandName""", type="string", length=32, nullable=false)
*/
private $brandname;
/**
* Set name.
*
* #param string $name
*/
public function setName($name) {
$this->brandname = $name;
}
}
In postgres every word case sensitive must be escape.
When using escaped table names take care about this "bug" : https://github.com/doctrine/doctrine2/pull/615 . Doctrine takes the first character of the table name as aliasprefix and thus a quote is used, crushing all your SQLs
I write PpSqlBundle but it isn't finished yet, but you could try, I think it should work.
It can generate form db same as in symfony. in config.yml you should have:
doctrine:
dbal:
default_connection: default
connections:
default:
driver:
dbname:
host:
user:
password:
driverClass: PgSqlBundle\Doctrine\DBAL\Driver\PDOPgSql\Driver # it's important
logging:
and you should use command
app/console doctrine:mapping:import Yourbundlename annotation
https://github.com/mstrzele/PgSqlBundle
If you are using migration files on Laravel. Change Schema::table to Schema::create. This might help someone.

Force javadoc to ignore an annotation

I'm trying to document an annotated interface and include a sample of how it's used in the javadoc. e.g.
/**
* Here's an example usage:
*
* <PRE>
* #IFaceAnnotation(value="")
* public interface IFace {
*
* #MethodAnnotation("")
* public String Method();
* }
* </PRE>
*/
However, Javadoc treats my annotations as javadoc instructions (like #param etc.) and as a result only prints:
Here's an example usage:
In the generated documentation. The only way i've been able to stop this is by adding an extra char before the annotation e.g.
/**
* Here's an example usage:
*
* <PRE>
* \#IFaceAnnotation(value="")
* public interface IFace {
*
* \#MethodAnnotation("")
* public String Method();
* }
* </PRE>
*/
but this looks a bit messy.
Just wondered if anyone had any suggestions, Thanks.
You can use '#' instead of the #, but thats even more ugly.
You could also use {#literal #}. No nasty escape characters.
/**
* Here's an example usage:
*
* <PRE>
* {#literal #}IFaceAnnotation(value="")
* public interface IFace {
*
* {#literal #}MethodAnnotation("")
* public String Method();
* }
* </PRE>
*/
Have you tried wrapping it in the {#code} notation?
For the record, the correct and complete answer is:
/**
* Here's an example usage:
*
* <pre>
* {#code}
* #IFaceAnnotation(value="")
* public interface IFace {
*
* #MethodAnnotation("")
* public String Method();
* }
* </pre>
*/
which results in