The document discusses Doctrine2, an ORM (object-relational mapper) for PHP. It describes how Doctrine2 allows transparent persistence of PHP objects to a database without restrictions on classes or properties. It provides several examples of how to map PHP classes to database tables using annotations, YAML, XML or PHP code. The document also covers common Doctrine2 practices like using protected properties with getter/setter methods.
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
در این جلسه به بررسی بحث برنامه نویسی شی گرا و کلاس ها در پایتون پرداختیم
PySec101 Fall 2013 J7E1 By Mohammad Reza Kamalifard
Talk About:
Object oriented programming and Classes in Python
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
در این جلسه به بررسی بحث برنامه نویسی شی گرا و کلاس ها در پایتون پرداختیم
PySec101 Fall 2013 J7E1 By Mohammad Reza Kamalifard
Talk About:
Object oriented programming and Classes in Python
In the publication I briefly describe what metaclasses are in Python. The writeup is a living item and will be extended with more detail shortly.
Please enjoy and comment.
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
Classes extend the built-in capabilities of C++ able you in representing and solving complex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data
object or simply an object.
Class is a group of data member and member functions. Another word class is a collection of objects of similar type.
To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names.
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
Defining Simple Classes
Using Own Classes and Objects
Access Modifiers
Constructors and Initializers
Defining Fields
Defining Properties, Getters and Setters
Defining Methods
Exercises: Defining and Using Own Classes
In the publication I briefly describe what metaclasses are in Python. The writeup is a living item and will be extended with more detail shortly.
Please enjoy and comment.
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
Classes extend the built-in capabilities of C++ able you in representing and solving complex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data
object or simply an object.
Class is a group of data member and member functions. Another word class is a collection of objects of similar type.
To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names.
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
Defining Simple Classes
Using Own Classes and Objects
Access Modifiers
Constructors and Initializers
Defining Fields
Defining Properties, Getters and Setters
Defining Methods
Exercises: Defining and Using Own Classes
Presentation for intermediate sculpture students. This Powerpoint will cover the basics of "Warm Glass" or "Fused Glass", including tool identification, firing, and cutting.
Write a program that asks the user for the name of a file. The progr.pdfarri2009av
Write a class named testscores. The class constructor should accept an array of rest scores as its
argument., The class should have a member function that returns the average of the test scores. If
any test score in the array is negative or greater than 100, the class should throw an exception.
Demonstrate the class in a program.
Solution
#include
#include
using namespace std;
class TestScores{
private:
float total = 0; //intiialising total marks
int length; //declaring variable for the size of scores array
bool invalid = false;
public:
TestScores(vector scores){
length = scores.size(); //length of vector of scores
for(int i = 0; i100){
cout<<\"Error! Invalid test score!\"; //error for invalid input
total = 0;
invalid = true;
}
else{
total+=scores[i];
}
}
}
float average(){
if(invalid==true){
return 0;
}
return this->total/this->length;
}
};
int main(){
vector scores;
scores.push_back(20);
scores.push_back(25);
scores.push_back(30);
scores.push_back(35);
scores.push_back(40);
scores.push_back(455);
scores.push_back(50);
TestScores testScores = TestScores(scores);
cout<<\"Average: \"<.
I've been using mongodb for 2 years and many times I've faced myself asking "why should I use it for this?" or "when should I really use Mongodb?" and many other times "What did I do wrong?".
Experiences, examples and real use cases many times say things that benchmarks or technical documentation don't, that for, I'll be presenting the When, Why and What of mongodb. For real, that's what really matters.
Demystifying Object-Oriented Programming - Lone Star PHPAlena Holligan
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
4. Use the AM for posting within scientific collaboration networks (SCNs). For a detailed description of our policy on posting to SCNs, please see our Web Posting Guidelines (https://publishing.aip.org/authors/web-posting-guidelines).
5. Reprint the Version of Record (VOR) in print collections written by the Author, or in the Author’s thesis or dissertation. It is understood and agreed that the thesis or dissertation may be made available electronically on the university’s site or in its repository and that copies may be offered for sale on demand.
6. Reproduce copies of the VOR for courses taught by the Author or offered at the institution where the Author is employed, provided no fee is charged for access to the Work.
7. Use the VOR for internal training and noncommercial business purposes by the Author’s employer.
8. Use the VOR in oral presentations made by the Author, such as at conferences, meetings, seminars, etc., provided those receiving copies are informed that they may not further copy or distribute the Work.
9. Distribute the VOR to colleagues for noncommercial scholarly use, provided those receiving copies are informed that they may not further copy or distribute the Work.
10. Post the VOR to their personal web page or their employer’s web page 12 months after publication by AIP Publishing.
11. Deposit the VOR in an institutional or funder-designated repository 12 months after publication by AIP Publishing.
12. Update a prior posting with the VOR on a noncommercial server such as arXiv, 12 months after publication by AIP Publishing.
Author Warranties
Each Author and Copyright Owner represents and warrants to AIP Publishing the following:
1. The Work is the original independent creation of each Author and does not infringe any copyright or violate any other right of any third party.
2. The Work has not been previously published and is not being considered for publication elsewhere in any form, except as a preprint on a noncommercial server such as arXiv, or in a thesis or dissertation.
3. Written permission has been obtained for any material used from other sources and copies of the permission grants have been supplied to AIP Publishing to be included in the manuscript file.
4. All third-party material for which permission has been obtained has been properly credited within the manuscript.
5. In the event that the Author is subject to university open access policies or other institutional restrictions that conflict with any of the rights or provisions of this License, such Author has obtained the necessary waiver from his or her university or institution.
This License must be signed by the Author(s) and, in the case of a Work Made for Hire, also by the Copyright Owners. One Author/Copyright Owner may sign on behalf of all the contributors/owners only if they all have authorized the signing, approved of the License, and agreed to be bound by it. The signing Author and, in the case of a Work Made for Hire, the signing Copyright Owne
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
Doctrator Symfony Live 2011 Paris
1. Doctrator
Pablo Díez
Symfony Live 2011 - Paris
viernes 4 de marzo de 2011
2. Pablo Díez
Creator of Mondongo
ODM for MongoDB and PHP
http://mondongo.es (in English :)
Creator of Mondator
Class generator for PHP
Creator of Doctrator
http://twitter.com/pablodip
http://github.com/pablodip
viernes 4 de marzo de 2011
11. How does Doctrine2 work?
“Doctrine2 provides transparent persistence for PHP objects.”
http://www.doctrine-project.org/docs/orm/2.0/en/reference/introduction.html
viernes 4 de marzo de 2011
12. That is, persist PHP objects without restrictions of a base class,
properties, methods.
namespace Model;
class User
{
public $id;
public $username;
public $email;
}
viernes 4 de marzo de 2011
13. You only have to tell Doctrine2 (map) what you want to persist.
viernes 4 de marzo de 2011
14. You only have to tell Doctrine2 (map) what you want to persist.
With Docblock Annotations
/**
* @Entity
*/
class User
{
/**
* @Id
* @Column(type="integer")
*/
public $id;
/**
* @Column(length=50)
*/
public $username;
/**
* @Column(length=100)
*/
public $email;
}
viernes 4 de marzo de 2011
15. You only have to tell Doctrine2 (map) what you want to persist.
With YAML
EntitiesUser:
type: entity
fields:
id: { type: integer, id: true }
username: { type: string(50) }
email: { type: string(50) }
viernes 4 de marzo de 2011
16. You only have to tell Doctrine2 (map) what you want to persist.
With XML
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="ModelUser" table="user">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="username" type="string" length="50" />
<field name="email" type="string" length="100" />
</entity>
</doctrine-mapping>
viernes 4 de marzo de 2011
17. You only have to tell Doctrine2 (map) what you want to persist.
With PHP
$metadata->mapField(array(
'id' => true,
'fieldName' => 'id',
'type' => 'integer'
));
$metadata->mapField(array(
'fieldName' => 'username',
'type' => 'string'
));
$metadata->mapField(array(
'fieldName' => 'email',
'type' => 'string'
));
viernes 4 de marzo de 2011
18. You only have to tell Doctrine2 (map) what you want to persist.
Then you are able to persist those objects.
viernes 4 de marzo de 2011
19. Then you are able to persist those objects.
$user = new User();
$user->username = 'pablodip';
$user->password = 'pa$$word';
$user->email = 'pablodip@gmail.com';
$entityManager->persist($user);
$entityManager->flush();
viernes 4 de marzo de 2011
20. A Doctrine2 good practice is to use non public
properties in the entities.
class User
{
protected $id;
protected $username;
protected $password;
protected $email;
}
viernes 4 de marzo de 2011
21. You have to create methods to access to the properties.
Setters & Getters
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
viernes 4 de marzo de 2011
22. What do you need to work with this simple table?
user
id integer
username string
password string
email string
viernes 4 de marzo de 2011
23. namespace Model;
class User
{
}
Class
user
id integer
username string
password string
email string
viernes 4 de marzo de 2011
24. namespace Model;
protected $id; class User
protected $username; {
protected $password; }
protected $email;
Class
Properties
user
id integer
username string
password string
email string
viernes 4 de marzo de 2011
25. namespace Model;
protected $id; class User
protected $username; {
protected $password; }
protected $email;
Class
Properties
user
id integer
username string
public function setId($id)
{
}
$this->id = $id;
password string
public function getId()
{
return $this->id;
email string
}
public function setUsername($username)
{
$this->username = $username; Setters/Getters
}
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
viernes 4 de marzo de 2011
26. namespace Model;
protected $id; class User
protected $username; {
protected $password; }
protected $email;
Class
Mapping
Properties
user
id integer
/**
* @Entity
username string */
public function setId($id)
{ /**
}
$this->id = $id;
password string * @Id
* @Column(type="integer")
*/
public function getId()
{
return $this->id;
email string /**
* @Column(length=50)
}
*/
public function setUsername($username)
{
$this->username = $username; Setters/Getters /**
* @Column(length=100)
} */
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
viernes 4 de marzo de 2011
27. namespace Model;
/**
* @Entity
*/
class User
{
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/**
* @Column(length="50")
*/
protected $username;
/**
* @Column(length="40")
*/
protected $password;
/**
user * @Column(length="100")
*/
protected $email;
id integer public function setId($id)
{
$this->id = $id;
}
username string public function getId()
{
return $this->id;
password string }
public function setUsername($username)
{
email string }
$this->username = $username;
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getPassword()
{
return $this->password;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getEmail()
{
return $this->email;
}
}
viernes 4 de marzo de 2011
28. namespace Model;
/**
* @Entity
*/
class User
{
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/**
* @Column(length="50")
*/
protected $username;
/**
* @Column(length="40")
*/
protected $password;
/**
user * @Column(length="100")
*/
protected $email;
id integer public function setId($id)
{
$this->id = $id;
LORC
}
username string public function getId()
{
return $this->id;
password string }
public function setUsername($username)
{
email string }
$this->username = $username;
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getPassword()
{
return $this->password;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getEmail()
{
return $this->email;
}
}
viernes 4 de marzo de 2011
29. LORC
Lines Of Repetitive Code
viernes 4 de marzo de 2011
30. LORC
Lines Of Repetitive Code
... and we still don’t have any features! :)
viernes 4 de marzo de 2011
31. How many LORC do we need in a real database?
viernes 4 de marzo de 2011
32. How many LORC do we need in a real database?
...
viernes 4 de marzo de 2011
43. namespace Model;
class User
{
protected $username;
public function setUsername($username)
{
$this->username = $username;
}
public function getUsername()
{
return $this->username;
}
}
viernes 4 de marzo de 2011
44. namespace Model; Definition
class User
{ Properties
protected $username;
public function setUsername($username)
{
$this->username = $username;
}
public function getUsername()
{
return $this->username;
}
}
Methods
viernes 4 de marzo de 2011
46. namespace Model;
class User
{
}
Full Class Name
$definition = new Definition('ModelUser');
viernes 4 de marzo de 2011
47. protected $username;
Visibility Name
$property = new Property('protected', 'username');
$definition->addProperty($property);
viernes 4 de marzo de 2011
48. public function setUsername($username)
{
$this->username = $username;
}
Visibility Name Arguments Code
$method = new Method('public', 'setUsername', '$username', <<<EOF
$this->username = $username;
EOF
);
$definition->addMethod($method);
viernes 4 de marzo de 2011
49. You can define any PHP class.
viernes 4 de marzo de 2011
50. Parent class
$definition->setParentClass('ModelBaseUser');
Interfaces
$definition->addInterface('ArrayAccess');
Abstract
$definition->setIsAbstract(true);
viernes 4 de marzo de 2011
51. Default value
$property->setValue($defaultValue);
Static
$property->setIsStatic(true);
viernes 4 de marzo de 2011
52. Abstract
$method->setIsAbstract(true);
Static
$method->setIsStatic(true);
viernes 4 de marzo de 2011
54. $definition->setDocComment(<<<EOF
/**
* User Class.
*/
EOF
);
$method->setDocComment(<<<EOF
/**
* Set the username.
*
* @param string $username The username.
*/
EOF
);
viernes 4 de marzo de 2011
55. Then you can export them with the Dumper.
use MondongoMondatorDumper;
$dumper = new Dumper($definition);
$classCode = $dumper->dump();
echo $classCode;
viernes 4 de marzo de 2011
56. /**
* User entity.
*/
class User
{
protected $username;
/**
* Set the username.
*
* @param string $username The username.
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Returns the username.
*
* @return string The username.
*/
public function getUsername()
{
return $this->username;
}
}
viernes 4 de marzo de 2011
57. And save them in files.
file_put_contents($file, $codeClass);
viernes 4 de marzo de 2011
59. Mondator Extensions
Mondator uses extensions to generate similar classes
in a powerful and flexible way.
viernes 4 de marzo de 2011
60. The Mondator Extensions process the config classes
to define what classes will be generated.
viernes 4 de marzo de 2011
61. ModelUser:
columns:
id: { id: auto, type: integer }
username: { type: string, length: 50 }
password: { type: string, length: 40 }
email: { type: string, length: 100 }
The Mondator Extensions process the config classes
to define what classes will be generated.
MondongoMondatorDefinitionDefinition
viernes 4 de marzo de 2011
62. ModelUser:
columns:
id: { id: auto, type: integer }
username: { type: string, length: 50 }
password: { type: string, length: 40 }
email: { type: string, length: 100 }
use MondongoMondatorExtension;
class Doctrator extends Extension
{
protected function doClassProcess()
{
$this->class;
$this->configClass;
$this->definitions;
}
}
viernes 4 de marzo de 2011
63. ModelUser:
columns:
id: { id: auto, type: integer }
username: { type: string, length: 50 }
password: { type: string, length: 40 }
email: { type: string, length: 100 }
use MondongoMondatorExtension;
class Doctrator extends Extension
{
protected function doClassProcess()
{
$this->class;
$this->configClass;
$this->definitions;
}
}
viernes 4 de marzo de 2011
64. ModelUser:
columns:
id: { id: auto, type: integer }
username: { type: string, length: 50 }
password: { type: string, length: 40 }
email: { type: string, length: 100 }
use MondongoMondatorExtension;
class Doctrator extends Extension
{
protected function doClassProcess()
{
$this->class;
$this->configClass;
$this->definitions;
}
}
viernes 4 de marzo de 2011
65. ModelUser:
columns:
id: { id: auto, type: integer }
username: { type: string, length: 50 }
password: { type: string, length: 40 }
email: { type: string, length: 100 }
use MondongoMondatorExtension;
class Doctrator extends Extension
{
protected function doClassProcess()
{
$this->class;
$this->configClass;
$this->definitions;
}
} Definitions to generate
viernes 4 de marzo de 2011
66. An extension can generate any definition.
viernes 4 de marzo de 2011
67. use MondongoMondatorExtension;
use MondongoMondatorDefinitionDefinition;
class Doctrator extends Extension
{
protected function doClassProcess()
{
$definition = new Definition($this->class);
$this->definitions['entity'] = $definition;
$definition = new Definition($this->class.'Repository');
$this->definitions['repository'] = $definition;
}
}
viernes 4 de marzo de 2011
68. foreach ($this->configClass['columns'] as $name => $column) {
$property = new Property('protected', $name);
$this->definitions['entity']->addProperty($property);
}
viernes 4 de marzo de 2011
69. foreach ($this->configClass['columns'] as $name => $column) {
$setterName = 'set'.Inflector::camelize($name);
$setter = new Method('public', $setterName, '$value', <<<EOF
$this->$name = $value;
EOF
);
$this->definitions['entity']->addMethod($setter);
}
viernes 4 de marzo de 2011
73. class Doctrator extends Extension
{
protected function setUp()
{
$this->addOptions(array(
'columns' => true,
'array_access' => true,
));
}
protected function doClassProcess()
{
if ($this->getOption('columns')) {
$this->processColumns();
}
if ($this->getOption('array_access')) {
$this->processArrayAccess();
}
}
}
viernes 4 de marzo de 2011
74. You can process the extensions that you want.
viernes 4 de marzo de 2011
75. $mondator = new MondongoMondatorMondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(
new DoctratorExtensionCore($options),
new DoctratorExtensionArrayAccess(),
));
$mondator->process();
$article['title'] = 'Doctrator';
echo $article['title']; // Doctrator
viernes 4 de marzo de 2011
76. $mondator = new MondongoMondatorMondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(
new DoctratorExtensionCore($options),
//new DoctratorExtensionArrayAccess(),
));
$mondator->process();
$article['title'] = 'Doctrator';
echo $article['title']; // Doctrator
viernes 4 de marzo de 2011
77. An extension can change the config class to extend
another extension.
viernes 4 de marzo de 2011
78. class Doctrator extends Extension
{
protected function doClassProcess()
{
foreach ($this->configClass['columns'] as $name => $column) {
// ...
}
}
}
class DateColumn extends Extension
{
protected function doConfigClassProcess()
{
$this->configClass['columns']['date'] = array(
'type' => 'date',
)
}
}
viernes 4 de marzo de 2011
79. You can even use extensions in the config classes.
viernes 4 de marzo de 2011
80. ModelArticle:
columns:
id: { id: auto, type: integer }
title: { type: string, length: 100 }
behaviors:
-
class: DoctratorBehaviorTimestampable
options: { }
viernes 4 de marzo de 2011
81. And you can combine all these things to do what you
want.
viernes 4 de marzo de 2011
82. Generated code is not necessarily magic code.
viernes 4 de marzo de 2011
84. Doctrator Extensions
Core
ArrayAccess PropertyOverloading ActiveRecord Behaviors
viernes 4 de marzo de 2011
85. Core
Generates and maps objects with Doctrine2.
viernes 4 de marzo de 2011
86. Doctrator uses base classes to separate generated
code from your code.
viernes 4 de marzo de 2011
87. ModelUser
namespace Model;
class User extends ModelBaseUser
{
// your code
}
namespace ModelBase;
class User
{
// generated code
}
viernes 4 de marzo de 2011
91. $category = new ModelCategory();
$category->setName('Class Generator');
$entityManager->persist($category);
$article = new ModelArticle();
$article->setTitle('Doctrator');
$article->setDate(new DateTime('now'));
$article->setCategory($category);
$entityManager->persist($article);
$entityManager->flush();
viernes 4 de marzo de 2011
92. Core
Useful methods.
viernes 4 de marzo de 2011
93. Set & Get by string
$article->set('title', 'Doctrator');
echo $article->get('title'); // Doctrator
viernes 4 de marzo de 2011
94. fromArray & toArray
$article->fromArray(array(
'title' => 'Doctrator',
'date' => new DateTime('now')
));
$array = $article->toArray();
viernes 4 de marzo de 2011
95. ArrayAccess
Implements the ArrayAccess interface in the entities.
viernes 4 de marzo de 2011
96. $article = new ModelArticle();
$article['title'] = 'Doctrator';
echo $article['title']; // Doctrator
viernes 4 de marzo de 2011
97. PropertyOverloading
Allows you access to entity data like properties.
viernes 4 de marzo de 2011
98. $article = new ModelArticle();
$article->title = 'Doctrator';
echo $article->title; // Doctrator
viernes 4 de marzo de 2011
99. ActiveRecord
Implements the ActiveRecord pattern in your entities.
viernes 4 de marzo de 2011
100. $article = new ModelArticle();
$article->setTitle('Doctrator');
$article->save();
$article->refresh();
$article->delete();
viernes 4 de marzo de 2011
102. print_r($article);
ModelArticle Object
(
[id:protected] => 1
[title:protected] => Doctrator
[content:protected] => Rocks!
)
Doctrator entities are clean even with ActiveRecord!
viernes 4 de marzo de 2011
103. $em = ModelArticle::entityManager();
$articleRepository = ModelArticle::repository();
$queryBuilder = ModelArticle::queryBuilder();
viernes 4 de marzo de 2011
104. $articles = $entityManager->getRepository('Model
Article')->findAll();
$article = $entityManager->getRepository('Model
Article')->find($id);
$articles = ModelArticle::repository()->findAll();
$article = ModelArticle::repository()->find($id);
viernes 4 de marzo de 2011
106. Behaviors
Reuse features.
viernes 4 de marzo de 2011
107. A behavior is simply a Mondator extension.
viernes 4 de marzo de 2011
108. A behavior can
Have options
Change config classes:
• Columns
• Associations
• Indexes
• Events
• ...
Add new generated classes
Add properties and methods
• Entities
• Repositories
• ...
viernes 4 de marzo de 2011
109. Timestampable
Saves the created and updated date.
created TRUE
created_column created_at
updated TRUE
updated_column updated_at
viernes 4 de marzo de 2011
110. ModelArticle:
columns:
id: { id: auto, type: integer }
title: { type: name, length: 100 }
behaviors:
- DoctratorBehaviorTimestampable
viernes 4 de marzo de 2011
111. $article = new ModelArticle();
$article->setTitle('Doctrator');
$article->save();
echo $article->getCreatedAt(); // now
echo $article->getUpdatedAt(); // null
$article->setContent('Rocks!');
$article->save();
echo $article->getCreatedAt(); // before
echo $article->getUpdatedAt(); // now
viernes 4 de marzo de 2011
112. Ipable
Saves the created and updated ip.
created TRUE
created_column created_from
updated TRUE
updated_column updated_from
viernes 4 de marzo de 2011
113. Hashable
Ipable
Saves a unique hash in each entity.
column hash
viernes 4 de marzo de 2011
114. ModelArticle:
columns:
id: { id: auto, type: integer }
title: { type: name, length: 100 }
behaviors:
- DoctratorBehaviorHashable
viernes 4 de marzo de 2011
115. $article = new Article();
$article->setTitle('Doctrator');
$entityManager->persist();
$entityManager->flush();
echo $article->getHash();
// da39a3ee5e6b4b0d3255bfef95601890afd80709
viernes 4 de marzo de 2011
116. Timestampable
Sluggable
Saves a slug from a field.
from_column *
slug_column slug
unique TRUE
update FALSE
viernes 4 de marzo de 2011
117. ModelArticle:
columns:
id: { id: auto, type: integer }
title: { type: name, length: 100 }
behaviors:
-
class: DoctratorBehaviorSluggable
options: { from_column: title }
viernes 4 de marzo de 2011
118. $article = new ModelArticle();
$article->setTitle('Doctrator Rocks!');
$article->save();
echo $article->getSlug(); // doctrator-rocks
viernes 4 de marzo de 2011
119. Sortable
Allows you to sort your entities.
column position
new_position bottom
viernes 4 de marzo de 2011
120. $articles = array();
for ($i = 0; $i <= 10; $i++) {
$articles[$i] = $a = new ModelArticle();
$a->setTitle('Article '.$i);
$a->save();
}
echo $articles[3]->getPosition(); // 3
echo $articles[6]->getPosition(); // 6
viernes 4 de marzo de 2011
121. // some methods
$articles[1]->isFirst();
$articles[1]->isLast();
$articles[1]->getNext();
$articles[1]->getPrevious();
$articles[1]->swapWith($articles[2]);
$articles[1]->moveUp();
$articles[1]->moveDown();
$repository->getMinPosition();
$repository->getMaxPosition();
viernes 4 de marzo de 2011
122. Taggable
Sortable
Allows you to save tags in the entities.
viernes 4 de marzo de 2011
123. $article = new ModelArticle();
$article->setTitle('My Title');
$article->save();
// methods
$article->addTags('foobar, barfoo');
$article->removeTags('foobar');
$article->removeAllTags(); // saved and not saved
$article->getSavedTags();
$article->getTags(); // saved and not saved
$article->setTags(array('foo', 'bar'));
$article->saveTags();
$repository->getTags();
$repository->getTagsWithCount();
viernes 4 de marzo de 2011
124. Translatable
Taggable
Sortable
Allows you to translate entity columns.
columns *
viernes 4 de marzo de 2011
126. $article = new ModelArticle();
$article->setDate(new DateTime());
// en
$article->translation('en')->setTitle('My Title');
$article->translation('en')->setContent('My Content');
// es
$article->translation('es')->setTitle('Mi Título');
$article->translation('es')->setContent('Mi Contenido');
$article->save();
viernes 4 de marzo de 2011
135. Questions?
http://mondongo.es (English :)
You can contact me for Mondongo, Doctrator, consulting, development
pablodip@gmail.com
viernes 4 de marzo de 2011