<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://prendreuncafe.com/blog/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Prendre un Café - Tag - amfphp</title>
  <link>http://prendreuncafe.com/blog/</link>
  <atom:link href="http://prendreuncafe.com/blog/feed/tag/amfphp/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>fr</language>
  <pubDate>Thu, 28 Aug 2008 04:27:09 +0200</pubDate>
  <copyright>Contenus sous licence Creative Commons BY-SA</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Partager la session utilisateur entre Flash/Flex et symfony avec AmfPHP</title>
    <link>http://prendreuncafe.com/blog/post/2008/07/25/Partager-la-session-utilisateur-entre-Flash/Flex-et-symfony-avec-AmfPHP</link>
    <guid isPermaLink="false">urn:md5:dd8eeb08fee3290129892d772067e574</guid>
    <pubDate>Fri, 25 Jul 2008 17:07:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>amfphp</category><category>flash</category><category>flex</category><category>php</category><category>symfony</category>    
    <description>    &lt;p&gt;Pour les besoins d'un projet récent, j'ai eu besoin de valider la possibilité de gérer l'authentification et l'accès à la session &lt;a href=&quot;http://www.symfony-project.com/&quot; hreflang=&quot;en&quot;&gt;symfony&lt;/a&gt; (côté serveur) depuis une interface générée par &lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/Presentation-de-Flex&quot; hreflang=&quot;fr&quot;&gt;Adobe Flex&lt;/a&gt; (en Flash, donc côté client).&lt;/p&gt;


&lt;p&gt;Pour cela, j'ai utilisé la librairie &lt;a href=&quot;http://amfphp.org/&quot; hreflang=&quot;en&quot;&gt;AmfPHP&lt;/a&gt; en version &lt;a href=&quot;https://amfphp.svn.sourceforge.net/svnroot/amfphp/tags/1.9beta2/&quot;&gt;1.9beta2&lt;/a&gt;, certes pas très récente mais suffisament fonctionnelle pour satisfaire à ce besoin précis. Voyons comment ça se passe concrètement. L'avantage de la démonstration ci-dessous est qu'elle ne nécessite pas d'installer Flex puisque AmfPHP fournit un navigateur de services (browser) qui nous suffira pour valider notre concept.&lt;/p&gt;


&lt;h3&gt;Installation du plugin sfGuard&lt;/h3&gt;


&lt;p&gt;Je pars du principe que tout le monde a une installation de symfony 1.1 nanti d'une application &lt;code&gt;main&lt;/code&gt;, ainsi qu'un projet et un virtual host apache fonctionnels pointant sur &lt;code&gt;local.mademo.org&lt;/code&gt;. Si ce n'est pas le cas, &lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/Symfony-11-beta-tour-du-proprietaire-Installation&quot; hreflang=&quot;fr&quot;&gt;voila de quoi vous mettre à jour&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;On commence par installer le plugin &lt;a href=&quot;http://trac.symfony-project.com/wiki/sfGuardPlugin&quot; hreflang=&quot;en&quot;&gt;sfGuard&lt;/a&gt;, qui se chargera de la persistance des droits et permissions utilisateurs en base de données, et fournira les utilitaires d'authentification et de manipulation de la session côté serveur :&lt;/p&gt;

&lt;pre&gt;
$ ./symfony plugin:install sfGuardPlugin
$ ./symfony propel-build-all
$ ./symfony cc
&lt;/pre&gt;


&lt;p&gt;On charge quelques données de test dans notre base de données nouvellement mise à jour :&lt;/p&gt;

&lt;pre&gt;
$ mkdir data/fixtures 
$ cp plugins/sfGuardPlugin/data/fixtures.yml.sample data/fixtures/fixtures.yml
$ ./symfony propel:data-load main
&lt;/pre&gt;


&lt;p&gt;Ce jeu de données de test nous fournit par défaut un compte &lt;code&gt;admin&lt;/code&gt; (mot de passe &lt;code&gt;admin&lt;/code&gt;) qui nous servira à tester notre service d'authentification.&lt;/p&gt;


&lt;p&gt;Ensuite, il nous faut modifier notre classe &lt;code&gt;apps/main/lib/myUser.php&lt;/code&gt; gérant la session utilisateur afin qu'elle étende désormais la classe &lt;code&gt;sfGuardSecurityUser&lt;/code&gt;, fournie par le plugin sfGuard :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Fichier apps/main/lib/myUser.php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; myUser extends sfGuardSecurityUser
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;Installation et configuration d'AmfPHP&lt;/h3&gt;


&lt;p&gt;Nous allons installer la librairie AmfPHP dans le sous-répertoire &lt;code&gt;web/&lt;/code&gt; de notre projet&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/25/Partager-la-session-utilisateur-entre-Flash/#pnote-989-1&quot; id=&quot;rev-pnote-989-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;, et aménager quelque peu notre arborescence pour accueillir les services AmfPHP :&lt;/p&gt;

&lt;pre&gt;
$ cd /path/to/project
$ svn export https://amfphp.svn.sourceforge.net/svnroot/amfphp/tags/1.9beta2 web/amfphp
$ mkdir lib/amfphp-services
$ mv web/amfphp/services/amfphp lib/amfphp-services/
&lt;/pre&gt;


&lt;p&gt;Ceci fait, nous allons éditer plusieurs fichiers d'amfphp afin de l'adapter à notre environnement symfony. Tout d'abord, commençons par éditer la valeur de la variable &lt;code&gt;$servicesPath&lt;/code&gt; dans le fichier &lt;code&gt;web/amfphp/globals.php&lt;/code&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// ...&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$servicesPath&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/dirname&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;dirname&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;'/../../lib/amfphp-services/'&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Enfin, il nous faut &amp;quot;patcher&amp;quot;&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/25/Partager-la-session-utilisateur-entre-Flash/#pnote-989-2&quot; id=&quot;rev-pnote-989-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt; le fichier &lt;code&gt;web/amfphp/core/amf/app/Filters.php&lt;/code&gt;, qui initialise la session PHP sans définir le nom de la session. Ici, nous utiliserons le nom de la session symfony par défaut, &amp;quot;&lt;code&gt;symfony&lt;/code&gt;&amp;quot; (ligne 105 du fichier) :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;102&lt;/span&gt;     &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//Fix for godaddy not allowing ini_get&lt;/span&gt;
&lt;span style=&quot;color: #cc66cc;&quot;&gt;103&lt;/span&gt;     &lt;span style=&quot;color: #0000ff;&quot;&gt;$sessionName&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;PHPSESSID&amp;quot;&lt;/span&gt;;
&lt;span style=&quot;color: #cc66cc;&quot;&gt;104&lt;/span&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #cc66cc;&quot;&gt;105&lt;/span&gt;   &lt;a href=&quot;http://www.php.net/session_name&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_name&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'symfony'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #cc66cc;&quot;&gt;106&lt;/span&gt;   &lt;a href=&quot;http://www.php.net/session_start&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_start&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #cc66cc;&quot;&gt;107&lt;/span&gt;   &lt;span style=&quot;color: #0000ff;&quot;&gt;$session_id&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/session_id&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_id&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;h3&gt;Création d'un service permettant le partage de la session utilisateur&lt;/h3&gt;


&lt;p&gt;Voila, nous pouvons maintenant créer un service de gestion de l'authentification, que nous nommerons pompeusement &lt;code&gt;UserSessionService&lt;/code&gt; et que nous enregistrerons dans le fichier &lt;code&gt;lib/amfphp-services/UserSessionService.php&lt;/code&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;require_once&lt;/span&gt; &lt;a href=&quot;http://www.php.net/dirname&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;dirname&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;'/../../config/ProjectConfiguration.class.php'&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
 * This class tests the symfony session within an AmfPHP context
 *
 */&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; UserSessionService
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Symfony context
   * @var sfContext
   */&lt;/span&gt;
  protected &lt;span style=&quot;color: #0000ff;&quot;&gt;$context&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Symfony session
   * @var sfGuardSecurityUser
   */&lt;/span&gt;
  protected &lt;span style=&quot;color: #0000ff;&quot;&gt;$user&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Public constructor
   *
   */&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; __construct&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$configuration&lt;/span&gt; = ProjectConfiguration::&lt;span style=&quot;color: #006600;&quot;&gt;getApplicationConfiguration&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'main'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'dev'&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;context&lt;/span&gt; = sfContext::&lt;span style=&quot;color: #006600;&quot;&gt;createInstance&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$configuration&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;user&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;context&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getUser&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Checks wheter user is authenticated or not
   *
   * @return boolean
   */&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; isAuthenticated&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getUser&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isAuthenticated&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Authenticates user
   *
   * @param  string  $username
   * @param  string  $password
   * @return boolean True if user has been successfully authenticated
   */&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; login&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$username&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$password&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isAuthenticated&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$user&lt;/span&gt; = sfGuardUserPeer::&lt;span style=&quot;color: #006600;&quot;&gt;retrieveByUsername&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    
    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;a href=&quot;http://www.php.net/is_null&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_null&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$user&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$user&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;checkPassword&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$password&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getUser&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;signIn&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$user&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Signs out a user 
   *
   */&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; logout&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getUser&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;signOut&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Retrieves the current symfony context
   *
   * @return sfContext
   */&lt;/span&gt;
  protected &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; getContext&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;context&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * Retrieves the current symfony user session
   *
   * @return sfGuardSecurityUser
   */&lt;/span&gt;
  protected &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; getUser&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;user&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour tester notre service, utilisons le navigateur de service proposé par AmfPHP. Pour cela, il faut lancer un navigateur sur &lt;code&gt;http://local.mademo.org/amfphp/browser/index.html&lt;/code&gt; :&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://prendreuncafe.com/blog/public/images/Dev/Flex/amfphpbrowsertest.png&quot;&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Dev/Flex/.amfphpbrowsertest_m.jpg&quot; alt=&quot;Naviagateur de services AmfPHP&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;Naviagateur de services AmfPHP, juil 2008&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Via cette interface, elle même réalisée en Flex, on peut tester les méthodes publiques définies dans notre service, manipuler les arguments, et constater que nous arrivons à nous authentifier et que nous accédons bien à la même session utilisateur que dans symfony : login, logout et test du statut d'authentification.&lt;/p&gt;


&lt;h3&gt;En conclusion&lt;/h3&gt;


&lt;p&gt;On pourrait aller beaucoup plus loin dans cet exemple, en proposant par exemple une classe proxy en ActionScript 3 représentant un utilisateur du système (dans notre cas, une instance de la classe &lt;code&gt;sfGuardUser&lt;/code&gt;), cette dernière reproduisant tout ou partie de ses méthodes et propriétés, et donc d'utiliser l'ORM Propel directement depuis Flash... Je vous laisse faire vos tests si le coeur vous en dit.&lt;/p&gt;


&lt;p&gt;D'autre part, même si la librairie AmfPHP semble un peu passée au niveau architecture, elle reste néanmoins très efficace pour publier des services PHP dans Flash au travers du protocole AMF. J'ai eu vent d'autres librairies comme &lt;a href=&quot;http://www.themidnightcoders.com/weborb/&quot; hreflang=&quot;en&quot;&gt;WebORB&lt;/a&gt; ou &lt;a href=&quot;http://www.osflash.org/sabreamf&quot; hreflang=&quot;en&quot;&gt;SabreAMF&lt;/a&gt;, mais je ne sais pas vraiment ce qu'elles valent... Des avis dans l'assistance ?&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/25/Partager-la-session-utilisateur-entre-Flash/#rev-pnote-989-1&quot; id=&quot;pnote-989-1&quot;&gt;1&lt;/a&gt;] Du coup, on expose certains scripts AmfPHP, mais la librairie n'est malheureusement que prévue pour fonctionner en ce sens...&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/25/Partager-la-session-utilisateur-entre-Flash/#rev-pnote-989-2&quot; id=&quot;pnote-989-2&quot;&gt;2&lt;/a&gt;] Oui, c'est terriblement crade, je ne comprend d'ailleurs pas qu'AmfPHP n'aie pas prévu ce cas de figure...&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Présentation de Flex</title>
    <link>http://prendreuncafe.com/blog/post/2007/08/19/Presentation-de-Flex</link>
    <guid isPermaLink="false">urn:md5:da44566c457d577a024483072a70682e</guid>
    <pubDate>Sun, 19 Aug 2007 13:04:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>actionscript</category><category>adobe</category><category>amfphp</category><category>bestpractices</category><category>flash</category><category>flex</category><category>framework</category><category>mxml</category><category>ria</category>    
    <description>    &lt;p&gt;Pour les besoins du boulot, j'ai du me mettre à &lt;a href=&quot;http://www.adobe.com/fr/products/flex/&quot; hreflang=&quot;fr&quot;&gt;Flex&lt;/a&gt;, le framework d'&lt;a href=&quot;http://adobe.fr&quot; hreflang=&quot;fr&quot;&gt;Adobe&lt;/a&gt; orienté &lt;a href=&quot;http://fr.wikipedia.org/wiki/Rich_Internet_Application&quot; hreflang=&quot;fr&quot;&gt;&lt;acronym title=&quot;Rich Internet application&quot;&gt;RIA&lt;/acronym&gt;&lt;/a&gt; en &lt;a href=&quot;http://fr.wikipedia.org/wiki/Format_Flash&quot; hreflang=&quot;fr&quot;&gt;Flash&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Je pensais que mon passé de flasheur m'aiderait à monter rapidement en compétence sur cette techno, ben non : c'est tout à fait autre chose que ce que je connaissais de l'IDE traditionnel, dont je m'étais arrêté à la version 8. Avec Flex on a affaire à un framework complet de génération d'interfaces riches basées sur l'emploi de composants décrits et paramétrés en XML et de la dernière mouture du langage &lt;a href=&quot;http://fr.wikipedia.org/wiki/ActionScript&quot; hreflang=&quot;fr&quot;&gt;ActionScript&lt;/a&gt; en version 3. Quelques &lt;a href=&quot;http://flex.org/showcase/&quot; hreflang=&quot;en&quot;&gt;exemples d'applications réalisées avec Flex&lt;/a&gt; sont disponibles, et pour certaines, ça en jette carrément.&lt;/p&gt;


&lt;h3&gt;Le langage MXML&lt;/h3&gt;


&lt;p&gt;La description des interfaces s'opère au moyen du langage MXML&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#pnote-908-1&quot; id=&quot;rev-pnote-908-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;, basé sur XML un peu comme ce que proposent &lt;a href=&quot;http://xulfr.org/&quot; hreflang=&quot;fr&quot;&gt;XUL&lt;/a&gt; ou &lt;a href=&quot;http://www.xaml.fr/&quot; hreflang=&quot;fr&quot;&gt;XAML&lt;/a&gt; ou même &lt;a href=&quot;http://fr.wikipedia.org/wiki/XHTML&quot; hreflang=&quot;fr&quot;&gt;XHTML&lt;/a&gt; (qui reste une implémentation particulière et standardisée d'XML). Deux types principaux de composants sont disponibles : les &lt;strong&gt;conteneurs&lt;/strong&gt; (boîtes, panneaux, fenêtres, etc.) et les &lt;strong&gt;éléments de contrôle&lt;/strong&gt; (champs texte, listes, datagrids, tree, etc.)&lt;/p&gt;


&lt;p&gt;Le nombre de conteneurs et de contrôles est impressionnant, on se prend à rêver de la même richesse en HTML &lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#pnote-908-2&quot; id=&quot;rev-pnote-908-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;. La plupart des composants sont visibles sur &lt;a href=&quot;http://examples.adobe.com/flex2/inproduct/sdk/explorer/explorer.html&quot; hreflang=&quot;en&quot;&gt;l'explorateur de composants Flex&lt;/a&gt;, sur le site d'Adobe. Et le meilleur reste sans doute à venir quand on voit le catalogue de composants supplémentaires open source comme ceux du projet &lt;a href=&quot;http://code.google.com/p/flexlib/&quot; hreflang=&quot;en&quot;&gt;FlexLib&lt;/a&gt;...&lt;/p&gt;


&lt;p&gt;Le format généré après compilation d'un ensemble de fichiers MXML constituant une application Flex est le &lt;a href=&quot;http://fr.wikipedia.org/wiki/SWF&quot; hreflang=&quot;fr&quot;&gt;SWF&lt;/a&gt;, le format natif d'Adobe Flash, lisible par tout bon &lt;a href=&quot;http://www.adobe.com/fr/products/flashplayer/&quot; hreflang=&quot;fr&quot;&gt;Flash Player 9&lt;/a&gt; qui se respecte, implanté sur plus de 80% du parc machines desktop mondial &lt;a href=&quot;http://www.adobe.com/products/player_census/flashplayer/version_penetration.html&quot; hreflang=&quot;en&quot;&gt;d'après les dernières statistiques disponibles sur le site d'Adobe&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Voila un exemple de code MXML décrivant l'interface d'une application simpliste :&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;?xml&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;encoding&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Application xmlns:&lt;span style=&quot;color: #000066;&quot;&gt;mx&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.adobe.com/2006/mxml&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;layout&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;absolute&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Panel &lt;span style=&quot;color: #000066;&quot;&gt;title&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Dire bonjour&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;x&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;y&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;layout&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;absolute&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;303&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:TextInput &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;firstname&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;x&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;y&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Button &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Dire bonjour&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;click&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;result.text='Bonjour, '+firstname.text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;x&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;178&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;y&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Label &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;result&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;x&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;y&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;40&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;265&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:Panel&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:Application&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Le code est assez parlant, mais voici quelques éléments significatifs :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Le conteneur principal de l'application déclare l'espace de noms &lt;code&gt;mx&lt;/code&gt;, ce qui nous permettra d'utiliser les composants natifs de Flex&lt;/li&gt;
&lt;li&gt;L'application déclare un conteneur sous la forme d'un &lt;code&gt;Panel&lt;/code&gt; contenant trois contrôles :
&lt;ul&gt;
&lt;li&gt;un &lt;code&gt;InputText&lt;/code&gt;, champs de saisie textuelle&lt;/li&gt;
&lt;li&gt;un &lt;code&gt;Button&lt;/code&gt;, un bouton d'action&lt;/li&gt;
&lt;li&gt;un &lt;code&gt;Label&lt;/code&gt;, un champs de texte potentiellement dynamique&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Chaque élément peut se voir nanti d'un attribut &lt;code&gt;id&lt;/code&gt; qui doit être unique si renseigné ; il permet de référencer facilement un élément de l'arbre &lt;acronym title=&quot;Document Object Model&quot;&gt;DOM&lt;/acronym&gt;&lt;/li&gt;
&lt;li&gt;La gestion des évènements peut se faire directement en MXML : ici, quand on clique sur le bouton, le contenu texte du label est modifié en fonction de la valeur textuelle du champs de saisie.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Style et mise en forme&lt;/h3&gt;


&lt;p&gt;Dans l'exemple précédent, on voit que les styles sont appliqués sous forme d'attributs XML. C'est une solution pratique à court terme mais qui peut rapidement s'avérer problématique à maintenir dès que votre application grossit. Aussi, pour séparer la couche de présentation de la description des contenus, tout comme en HTML, Flex permet l'utilisation de feuilles de styles CSS embarquées ou externalisées. Beaucoup de propriétés CSS ont du être créées ou adaptées aux spécificités du balisage MXML et des composants proposés, mais le résultat est une grande souplesse d'utilisation et une large palette de mise en forme disponible. Pour preuve, un petit tour du côté de l'&lt;a href=&quot;http://examples.adobe.com/flex2/consulting/styleexplorer/Flex2StyleExplorer.html&quot; hreflang=&quot;en&quot;&gt;explorateur de styles Flex&lt;/a&gt; s'impose.&lt;/p&gt;


&lt;h3&gt;Le langage ActionScript 3&lt;/h3&gt;


&lt;p&gt;ActionScript 3 est l'évolution logique des précédentes versions, étendant le périmètre fonctionnel et accentuant son caractère professionnel, notamment dans l'implémentation objet, les types natifs et l'organisation en packages des différents objets de programmation.&lt;/p&gt;


&lt;h3&gt;Composants personnalisés&lt;/h3&gt;


&lt;p&gt;Une des grandes forces de Flex à mes yeux est la simplicité avec laquelle on peut créer ses propres composants en héritant de composants basiques préexistants et de les manipuler via son propre espace de noms. Par exemple, la création d'un composant dérivé d'un formulaire présentant un champs de login/mot de passe donne à peu près ceci :&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;?xml&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;encoding&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Form xmlns:&lt;span style=&quot;color: #000066;&quot;&gt;mx&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.adobe.com/2006/mxml&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;width&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;280&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;height&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;105&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:FormItem &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:TextInput &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;username&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:FormItem&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:FormItem &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Mot de passe&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:TextInput &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;password&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;displayAsPassword&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:FormItem&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:FormItem&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Button &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Connexion&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:FormItem&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:Form&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Si on nomme notre fichier de composant &lt;code&gt;LoginForm.mxml&lt;/code&gt; et qu'on le stocke dans le répertoire &lt;code&gt;./components&lt;/code&gt; de notre projet Flex, on va pouvoir l'utiliser de la façon suivante dans une application :&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;?xml&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;encoding&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Application 
   xmlns:&lt;span style=&quot;color: #000066;&quot;&gt;mx&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.adobe.com/2006/mxml&amp;quot;&lt;/span&gt; 
   xmlns:&lt;span style=&quot;color: #000066;&quot;&gt;niko&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;components.*&amp;quot;&lt;/span&gt;
   &lt;span style=&quot;color: #000066;&quot;&gt;layout&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;absolute&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;mx&lt;/span&gt;:Panel &lt;span style=&quot;color: #000066;&quot;&gt;title&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Connexion&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;niko&lt;/span&gt;:LoginForm &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;loginform&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:Panel&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/mx&lt;/span&gt;:Application&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;On a déclaré un nouvel espace de noms, ici &lt;code&gt;niko&lt;/code&gt; (mais on aurait pu mettre ce qu'on veut) pointant vers les fichiers sous le répertoire &lt;code&gt;components&lt;/code&gt; du projet. Simple, non ? En tout cas, cela devient un jeu d'enfant de produire des composants réutilisables.&lt;/p&gt;


&lt;h3&gt;Le nerf de la guerre, l'accès aux données distantes&lt;/h3&gt;


&lt;p&gt;Flex propose trois modes d'accès aux données distantes, par le biais de trois composants :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;L'objet &lt;code&gt;HTTPService&lt;/code&gt;, comme son nom l'indique, permet d'effectuer des requêtes &lt;a href=&quot;http://fr.wikipedia.org/wiki/HTTP&quot; hreflang=&quot;fr&quot;&gt;HTTP&lt;/a&gt; sur une url et d'en récupérer la réponse. Un objet bien pratique quand on veut s'interfacer avec une &lt;a href=&quot;http://www.biologeek.com/journal/index.php/pour-ne-plus-etre-en-rest-comprendre-cette-architecture&quot; hreflang=&quot;fr&quot;&gt;architecture REST&lt;/a&gt;, par exemple.&lt;/li&gt;
&lt;li&gt;L'objet &lt;code&gt;WebService&lt;/code&gt; permet de s'interfacer avec un webservice au format &lt;a href=&quot;http://fr.wikipedia.org/wiki/WSDL&quot; hreflang=&quot;fr&quot;&gt;WSDL&lt;/a&gt; via &lt;a href=&quot;http://fr.wikipedia.org/wiki/SOAP&quot; hreflang=&quot;fr&quot;&gt;SOAP&lt;/a&gt;. Quand on dispose de tels service, c'est un plaisir de se baser dessus depuis Flex puisqu'on a qu'à réferencer les méthodes à utiliser et les déclencher depuis leur référence.&lt;/li&gt;
&lt;li&gt;Mais l'objet de loin le plus intéressant à mes yeux est &lt;code&gt;RemoteObject&lt;/code&gt;, implémentation du protocole &lt;a href=&quot;http://fr.wikipedia.org/wiki/Remote_procedure_call&quot; hreflang=&quot;fr&quot;&gt;RPC&lt;/a&gt; dans Flex, pendant Flash/ActionScript du &lt;a href=&quot;http://fr.wikipedia.org/wiki/Remote_method_invocation_%28Java%29&quot; hreflang=&quot;fr&quot;&gt;RMI&lt;/a&gt; en Java. Comme je fais peu de Java, j'ai tendance à plutôt utiliser &lt;a href=&quot;http://www.amfphp.org/&quot; hreflang=&quot;en&quot;&gt;AMFPHP&lt;/a&gt;&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#pnote-908-3&quot; id=&quot;rev-pnote-908-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt; pour publier mes services en utilisant &lt;a href=&quot;http://fr.php.net/&quot; hreflang=&quot;fr&quot;&gt;PHP&lt;/a&gt;. Un très bon &lt;a href=&quot;http://www.sephiroth.it/tutorials/flashPHP/flex_remoteobject/index.php&quot; hreflang=&quot;en&quot;&gt;tuto de mise en oeuvre du couple AMFPHP/Flex&lt;/a&gt; se chargera d'illustrer le concept plus efficacement que je ne le fais ici.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;FlexBuilder&lt;/h3&gt;


&lt;p&gt;Adobe propose un IDE dédié à la réalisation d'applications Flex, &lt;a href=&quot;http://www.adobe.com/fr/products/flex/flexbuilder/&quot; hreflang=&quot;fr&quot;&gt;FlexBuilder&lt;/a&gt;. Cet outil, basé sur le célebrissime &lt;a href=&quot;http://eclipse.org&quot; hreflang=&quot;fr&quot;&gt;Eclipse&lt;/a&gt;, permet de disposer d'un environnement complet de développement comprenant entre autres un éditeur de code (MXML en mode source/wysiwyg, ActionScript, CSS, etc.), un débogueur avancé &lt;em&gt;à la Java&lt;/em&gt;, un gestionnaire de projets, la compilation automatique et surtout un accès à l'immense &lt;a href=&quot;http://eclipse-plugins.2y.net/eclipse/plugins.jsp&quot; hreflang=&quot;en&quot;&gt;catalogue des plugins Eclipse&lt;/a&gt;. D'ailleurs, FlexBuilder est également disponible sous la forme d'un plugin à installer sur une instance d'Eclipse existante : de quoi travailler sur vos projets Flex/PHP de façon centralisée, par exemple.&lt;/p&gt;


&lt;p&gt;Inconvénient majeur de cet outil, il est payant. Et coûte relativement cher, puisque proposé aux alentours de 500€. Néanmoins, le SDK de Flex étant gratuit, vous pouvez tout à fait vous passer de FlexBuilder et compiler vos applications à la main. Une bonne nouvelle ne venant jamais seule, &lt;a href=&quot;http://www.adobe.com/aboutadobe/pressroom/pressreleases/200704/042607Flex.html&quot; hreflang=&quot;en&quot;&gt;Adobe a décidé de publier la prochaine mouture du framework sous licence libre&lt;/a&gt; &lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#pnote-908-4&quot; id=&quot;rev-pnote-908-4&quot;&gt;4&lt;/a&gt;]&lt;/sup&gt;, aussi nous devrions voir fleurir des alternatives à FlexBuilder et assister à un taux d'adoption plus conséquent de la technologie.&lt;/p&gt;


&lt;h3&gt;Organisation du code, frameworks&lt;/h3&gt;


&lt;p&gt;Au vu de l'étendue fonctionnelle de Flex et des différents formats de fichiers mis en oeuvre ainsi que de leurs interactions potentielles, il est clair que maintenir la moindre petite application peut vite relever du cauchemar les développements avançant. Pour faire face à cette problématique, Adobe propose un &lt;em&gt;surframework&lt;/em&gt; du nom de &lt;a href=&quot;http://labs.adobe.com/wiki/index.php/Cairngorm&quot; hreflang=&quot;en&quot;&gt;Cairngorm&lt;/a&gt; mettant en oeuvre les bonnes pratiques d'architecture logicielle en implémentant le motif de conception &lt;acronym title=&quot;Modèle Vue Controlleur&quot;&gt;MVC&lt;/acronym&gt; bien connu des utilisateurs de frameworks de développement rapide orientés web.&lt;/p&gt;


&lt;p&gt;Même si le projet semble extrêmement intéressant, je n'ai pas encore pour l'heure pu jouer avec.&lt;/p&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;


&lt;p&gt;Pour l'heure et après avoir pas mal &lt;del&gt;galéré&lt;/del&gt; tâtonné avec l'outil au début, je dois reconnaître maintenant et avec un peu de recul que c'est assez efficace. C'est relativement déstabilisant pour quelqu'un qui comme moi avait l'habitude de l'IDE Flash Authoring classique, mais au final FlexBuilder semble beaucoup plus sérieux pour tout ce qui concerne la programmation et l'organisation des fichiers (Eclipse oblige.) Même le templating y gagne à mon sens, mais par contre impossible de faire de la création graphique avancée directement dans FlexBuilder, l'outil n'est clairement pas l'ami des infographistes de vocation.&lt;/p&gt;


&lt;p&gt;Pour enfoncer le clou, j'ai pu comparer l'utilisation de Flex et de XUL, ayant enchaîné deux projets coup sur coup les mettant en oeuvre. L'excellente documentation de Flex et la richesse des outils gravitant autour de la techno font que pour l'heure Flex me semble l'un des meilleurs choix pour développer une RIA, si l'on écarte le couple HTML/Ajax qui garde une toujours une place de choix dans mon arsenal webdeuzéroesque &lt;img src=&quot;/blog/themes/Puc4/smilies/wink.gif&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#rev-pnote-908-1&quot; id=&quot;pnote-908-1&quot;&gt;1&lt;/a&gt;] Je ne sais pas à quoi correspond la lettre M de l'acronyme, &lt;em&gt;Macromedia&lt;/em&gt; sans doute.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#rev-pnote-908-2&quot; id=&quot;pnote-908-2&quot;&gt;2&lt;/a&gt;] En attendant &lt;a href=&quot;http://www.whatwg.org/specs/web-forms/current-work/&quot; hreflang=&quot;en&quot;&gt;HTML5&lt;/a&gt;, les antiflash pourront aller zieuter du côté d'&lt;a href=&quot;http://extjs.com/&quot; hreflang=&quot;en&quot;&gt;extjs&lt;/a&gt; ou de &lt;a href=&quot;http://developer.yahoo.com/yui/&quot; hreflang=&quot;en&quot;&gt;YUI&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#rev-pnote-908-3&quot; id=&quot;pnote-908-3&quot;&gt;3&lt;/a&gt;] Attention à bien utiliser la &lt;a href=&quot;http://www.5etdemi.com/blog/archives/2006/12/amfphp-19-beta-get-it-now/&quot; hreflang=&quot;en&quot;&gt;dernière version 1.9 beta&lt;/a&gt; compatible avec Flex2&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/08/19/#rev-pnote-908-4&quot; id=&quot;pnote-908-4&quot;&gt;4&lt;/a&gt;] Sous licence &lt;acronym title=&quot;Mozilla Public Licence&quot;&gt;MPL&lt;/acronym&gt; plus précisément.&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
</channel>
</rss>