Browse Source

remove things that are built to stockpile

gjerokrsteski 11 years ago
parent
commit
9bac22e98b

+ 2 - 2
php-pimf/app/Vanilla/Controller/Hello.php

@@ -30,7 +30,7 @@ class Hello extends Base
 
     $worlds = array();
 
-    for ($i = 0; $i < (int)$queries; ++$i) {
+    for ($i = 0; $i < $queries; ++$i) {
       $worlds[] = Registry::get('em')->world->find(mt_rand(1, 10000));
     }
 
@@ -78,7 +78,7 @@ class Hello extends Base
 
     $em->beginTransaction();
 
-    for ($i = 0; $i < (int)$queries; ++$i) {
+    for ($i = 0; $i < $queries; ++$i) {
       $worlds[] = $em->world->find(mt_rand(1, 10000));
     }
 

+ 2 - 2
php-pimf/pimf-framework/core/Pimf/Controller/Base.php

@@ -54,7 +54,7 @@ abstract class Base
     if (Sapi::isCli() && $conf['environment'] == 'production') {
 
       $suffix = 'CliAction';
-      $action = $this->request->fromCli()->get('action') ? : 'index';
+      $action = $this->request->fromCli()->get('action', 'index');
 
     } else {
 
@@ -65,7 +65,7 @@ abstract class Base
         throw new Bomb("not supported request method=" . $requestMethod);
       }
 
-      $action = $this->request->{$bag}()->get('action') ? : 'index';
+      $action = $this->request->{$bag}()->get('action', 'index');
 
       if ($conf['app']['routeable'] === true) {
 

+ 0 - 249
php-pimf/pimf-framework/core/Pimf/Util/Ldap.php

@@ -1,249 +0,0 @@
-<?php
-/**
- * Util
- *
- * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
- * @license   http://krsteski.de/new-bsd-license New BSD License
- */
-
-namespace Pimf\Util;
-
-use Pimf\Registry;
-
-/**
- * Wrapper for Lightweight Directory Access Protocol and for a access to "Directory Servers"
- *
- * For use please add the following to the end of the config.app.php file:
- *
- * <code>
- *
- * 'ldap' => array(
- *
- *    // where in the directory tree to be started for specific objects searching (is optional)
- *    'basedn' => 'dc=example,dc=com'
- *
- *    // hostname of the domain controller
- *    'host' => 'dc',
- *
- *    // the domain name
- *    'domain' => 'example.com',
- *
- *    // optionally require users to be in this group
- *    //'group' => 'AppUsers',
- *
- *    // domain credentials the app should use to validate users
- *    // this user does not need any privileges - it's just used to connect to the DC.
- *    'user' => 'ldap-user_here',
- *    'password' => 'ldap-password-here',
- * ),
- *
- * </code>
- *
- * @link    http://www.php.net/manual/en/intro.ldap.php
- * @package Util
- * @author  Gjero Krsteski <[email protected]>
- */
-class Ldap
-{
-  /**
-   * @var resource A positive LDAP link identifier
-   */
-  protected $conn;
-
-  public function __construct()
-  {
-    if (!function_exists('ldap_connect')) {
-      throw new \RuntimeException('LDAP-auth requires the php-ldap extension to be installed');
-    }
-  }
-
-  public function __destruct()
-  {
-    if (is_resource($this->conn)) {
-      ldap_unbind($this->conn);
-    }
-  }
-
-  /**
-   * Get the current user of the application.
-   *
-   * @param $userDN
-   *
-   * @return null|Ldap\User
-   */
-  public function retrieve($userDN)
-  {
-    if (!is_resource($this->conn)) {
-      $config = Registry::get('ldap');
-      $this->connect($config['user'], $config['password']);
-    }
-
-    return $this->getUser($userDN);
-  }
-
-  /**
-   * Attempt to log a user into the application.
-   *
-   * @param $username
-   * @param $password
-   *
-   * @return Ldap\User
-   */
-  public function attempt($username, $password)
-  {
-    $config = Registry::get('ldap');
-
-    return $this->login($username, $password, $config['group']);
-  }
-
-  /**
-   * @param $user
-   * @param $password
-   *
-   * @throws \RuntimeException
-   */
-  protected function connect($user, $password)
-  {
-    $config = Registry::get('ldap');
-
-    // guess base DN from domain
-    if (!isset($config['basedn'])) {
-      $length           = strrpos($config['domain'], '.');
-      $config['basedn'] = sprintf(
-        'dc=%s,dc=%s', substr($config['domain'], 0, $length), substr($config['domain'], $length + 1)
-      );
-
-      // override the basedn
-      Registry::set('ldap', $config);
-    }
-
-    // connect to the controller
-    if (!$this->conn = ldap_connect("ldap://{$config['host']}.{$config['domain']}")) {
-      throw new \RuntimeException("could not connect to LDAP host {$config['host']}.{$config['domain']}");
-    }
-
-    // required for Windows AD
-    ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3);
-    ldap_set_option($this->conn, LDAP_OPT_REFERRALS, 0);
-
-    // try to authenticate
-    if (!@ldap_bind($this->conn, "{$user}@{$config['domain']}", $password)) {
-      throw new \RuntimeException('could not bind to AD: ' . "{$user}@{$config['domain']}");
-    }
-  }
-
-  /**
-   * @param      $user
-   * @param      $password
-   * @param null $group
-   *
-   * @return Ldap\User
-   * @throws \RuntimeException
-   */
-  protected function login($user, $password, $group = null)
-  {
-    $this->connect($user, $password);
-
-    $config      = Registry::get('ldap');
-    $groupObject = $this->getAccount($group, $config['basedn']);
-    $userObject  = $this->getAccount($user, $config['basedn']);
-
-    if ($group && !$this->checkGroup($userObject['dn'], $groupObject['dn'])) {
-      throw new \RuntimeException('user is not part of the "' . $group . '" group.');
-    }
-
-    return $this->fetch($userObject);
-  }
-
-  /**
-   * @param array $user
-   *
-   * @return Ldap\User
-   * @throws \RuntimeException
-   */
-  protected function fetch(array $user)
-  {
-    if (!isset($user['cn'][0])) {
-      throw new \RuntimeException('not a valid user object');
-    }
-
-    return Ldap\User::factory($user);
-  }
-
-  /**
-   * Searches the LDAP tree for the specified account or group
-   *
-   * @param $account
-   * @param $basedn
-   *
-   * @return null|array
-   */
-  protected function getAccount($account, $basedn)
-  {
-    $result = ldap_search(
-      $this->conn, $basedn, "(samaccountname={$account})", array('dn', 'givenname', 'sn', 'cn', 'memberof', 'objectguid')
-    );
-
-    if (!$result) {
-      return null;
-    }
-
-    $entries = ldap_get_entries($this->conn, $result);
-
-    if ($entries['count'] > 0) {
-      return $entries[0];
-    }
-  }
-
-  /**
-   * Checks group membership of the user, searching
-   * in the specified group and its children (recursively)
-   *
-   * @param $userDN
-   * @param $groupDN
-   *
-   * @return bool
-   * @throws \RuntimeException
-   */
-  public function checkGroup($userDN, $groupDN)
-  {
-    if (!$user = $this->getUser($userDN)) {
-      throw new \RuntimeException('invalid user DN');
-    }
-
-    $memberof = $user->getMemberof();
-
-    for ($i = 0; $i < $memberof['count']; $i++) {
-      if ($groupDN == $memberof[$i]) {
-        return true;
-      }
-    }
-
-    return false;
-  }
-
-  /**
-   * @param $userDN
-   *
-   * @return null|Ldap\User
-   * @throws \RuntimeException
-   */
-  public function getUser($userDN)
-  {
-    if (!is_resource($this->conn)) {
-      throw new \RuntimeException('no LDAP connection bound');
-    }
-
-    if (!$result = ldap_read($this->conn, $userDN, '(objectclass=*)')) {
-      return null;
-    }
-
-    $entries = ldap_get_entries($this->conn, $result);
-
-    if (!$entries['count']) {
-      return null;
-    }
-
-    return $this->fetch($entries[0]);
-  }
-}

+ 0 - 132
php-pimf/pimf-framework/core/Pimf/Util/Ldap/User.php

@@ -1,132 +0,0 @@
-<?php
-/**
- * Util
- *
- * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
- * @license   http://krsteski.de/new-bsd-license New BSD License
- */
-
-namespace Pimf\Util\Ldap;
-
-/**
- * Lightweight LDAP user object.
- *
- * @package Util
- * @author  Gjero Krsteski <[email protected]>
- */
-class User
-{
-  /**
-   * @var string Distinguished Name
-   */
-  protected $dname;
-
-  /**
-   * @var string Exactly the same as CN.
-   */
-  protected $name;
-
-  /**
-   * @var string
-   */
-  protected $firstname;
-
-  /**
-   * @var string
-   */
-  protected $lastname;
-
-  /**
-   * @var string Global Unique Identity Code
-   */
-  protected $objectguid;
-
-  /**
-   * @var array List of groups
-   */
-  protected $memberof;
-
-  /**
-   * @param       $dname
-   * @param       $firstname
-   * @param       $lastname
-   * @param array $memberof
-   * @param       $name
-   * @param       $objectguid
-   */
-  public function __construct($dname, $firstname, $lastname, array $memberof, $name, $objectguid)
-  {
-    $this->dname      = '' . $dname;
-    $this->firstname  = '' . $firstname;
-    $this->lastname   = '' . $lastname;
-    $this->memberof   = (array)$memberof;
-    $this->name       = '' . $name;
-    $this->objectguid = '' . $objectguid;
-  }
-
-  /**
-   * @param array $user
-   *
-   * @return \Pimf\Util\Ldap\User
-   */
-  public static function factory(array $user)
-  {
-    return new self($user['dn'], $user['givenname'][0], $user['sn'][0], isset($user['memberof']) ? $user['memberof']
-        : array('count' => 0), $user['cn'][0], $user['objectguid'][0]);
-  }
-
-  /**
-   * @codeCoverageIgnore
-   * @return string
-   */
-  public function getDname()
-  {
-    return $this->dname;
-  }
-
-  /**
-   * @codeCoverageIgnore
-   * @return string
-   */
-  public function getFirstname()
-  {
-    return $this->firstname;
-  }
-
-  /**
-   * @codeCoverageIgnore
-   * @return string
-   */
-  public function getLastname()
-  {
-    return $this->lastname;
-  }
-
-  /**
-   * @codeCoverageIgnore
-   * @return array
-   */
-  public function getMemberof()
-  {
-    return $this->memberof;
-  }
-
-  /**
-   * @codeCoverageIgnore
-   * @return string
-   */
-  public function getName()
-  {
-    return $this->name;
-  }
-
-  /**
-   * @codeCoverageIgnore
-   * @return string
-   */
-  public function getObjectguid()
-  {
-    return $this->objectguid;
-  }
-
-}

+ 0 - 81
php-pimf/pimf-framework/core/Pimf/Util/LineByLine.php

@@ -1,81 +0,0 @@
-<?php
-/**
- * Util
- *
- * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
- * @license   http://krsteski.de/new-bsd-license New BSD License
- */
-
-namespace Pimf\Util;
-
-/**
- * Process file line by line.
- *
- * This is slower than reading in the file all at once, but considerably reduces memory usage!
- *
- * <code>
- *
- * $linebyline = new LineByLine(
- *   function ($line) {
- *     // do what you want with the line.
- *    return $line;
- *   }
- * );
- *
- * $feedback = $linebyline->read('//path/to/your/file.txt');
- *
- * </code>
- *
- * @package Util
- * @author  Gjero Krsteski <[email protected]>
- */
-class LineByLine
-{
-  protected $callback;
-
-  /**
-   * @param string|array|\Closure $callback
-   *
-   * @throws \RuntimeException If no callable callback given.
-   */
-  public function __construct($callback)
-  {
-    if (!is_callable($callback)) {
-      throw new \RuntimeException('no callable given');
-    }
-
-    $this->callback = $callback;
-  }
-
-  /**
-   * @param string $file     Filename or stream
-   * @param bool   $feedback Should callback responses be collected.
-   * @param bool   $binary   Is binary file.
-   *
-   * @return array List of collected responses.
-   * @throws \RuntimeException If can not create file handle.
-   */
-  public function read($file, $feedback = false, $binary = false)
-  {
-    if (!is_resource($handle = fopen($file, ($binary === true ? 'rb' : 'r')))) {
-      throw new \RuntimeException('can not read handle');
-    }
-
-    $responses = array();
-
-    while (!feof($handle)) {
-
-      $response = call_user_func_array(
-        $this->callback, array(fgets($handle, 4096))
-      );
-
-      if ($feedback === true) {
-        $responses[] = $response;
-      }
-    }
-
-    fclose($handle);
-
-    return $responses;
-  }
-}

+ 2 - 3
php-pimf/source_code

@@ -5,6 +5,8 @@
 ./php-pimf/app/bootstrap.app.php
 ./php-pimf/app/config.app.php
 ./php-pimf/app/Vanilla/Controller/Hello.php
+./php-pimf/app/Vanilla/DataMapper/World.php
+./php-pimf/app/Vanilla/DataMapper/Fortune.php
 ./php-pimf/pimf-framework/
 ./php-pimf/pimf-framework/core/Pimf/Application.php
 ./php-pimf/pimf-framework/core/Pimf/Cache.php
@@ -77,9 +79,6 @@
 ./php-pimf/pimf-framework/core/Pimf/Util/Identifier.php
 ./php-pimf/pimf-framework/core/Pimf/Util/IdentityMap.php
 ./php-pimf/pimf-framework/core/Pimf/Util/Json.php
-./php-pimf/pimf-framework/core/Pimf/Util/Ldap.php
-./php-pimf/pimf-framework/core/Pimf/Util/Ldap/User.php
-./php-pimf/pimf-framework/core/Pimf/Util/LineByLine.php
 ./php-pimf/pimf-framework/core/Pimf/Util/Message.php
 ./php-pimf/pimf-framework/core/Pimf/Util/Serializer.php
 ./php-pimf/pimf-framework/core/Pimf/Util/String.php