camelsSnake() public static méthode

Converts a camel cased string to a snake cased string.
public static camelsSnake ( string $camel ) : string
$camel string camelCased string to converty to snake case
Résultat string
Exemple #1
0
 /**
  * Registers a association renaming globally.
  *
  * @param string $via type you wish to use for shared lists
  *
  * @return OODBBean
  */
 public function via($via)
 {
     $this->via = AQueryWriter::camelsSnake($via);
     return $this;
 }
Exemple #2
0
 /**
  * Counts the number of beans of type $type.
  * This method accepts a second argument to modify the count-query.
  * A third argument can be used to provide bindings for the SQL snippet.
  *
  * @param string $type     type of bean we are looking for
  * @param string $addSQL   additional SQL snippet
  * @param array  $bindings parameters to bind to SQL
  *
  * @return integer
  *
  * @throws SQLException
  */
 public function count($type, $addSQL = '', $bindings = array())
 {
     $type = AQueryWriter::camelsSnake($type);
     if (count(explode('_', $type)) > 2) {
         throw new RedException('Invalid type for count.');
     }
     try {
         return (int) $this->writer->queryRecordCount($type, array(), $addSQL, $bindings);
     } catch (SQLException $exception) {
         if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN))) {
             throw $exception;
         }
     }
     return 0;
 }
Exemple #3
0
 /**
  * Creates a N-M relation by linking an intermediate bean.
  * This method can be used to quickly connect beans using indirect
  * relations. For instance, given an album and a song you can connect the two
  * using a track with a number like this:
  *
  * Usage:
  *
  * $album->link('track', array('number'=>1))->song = $song;
  *
  * or:
  *
  * $album->link($trackBean)->song = $song;
  *
  * What this method does is adding the link bean to the own-list, in this case
  * ownTrack. If the first argument is a string and the second is an array or
  * a JSON string then the linking bean gets dispensed on-the-fly as seen in
  * example #1. After preparing the linking bean, the bean is returned thus
  * allowing the chained setter: ->song = $song.
  *
  * @param string|OODBBean $type          type of bean to dispense or the full bean
  * @param string|array            $qualification JSON string or array (optional)
  *
  * @return OODBBean
  */
 public function link($typeOrBean, $qualification = array())
 {
     if (is_string($typeOrBean)) {
         $typeOrBean = AQueryWriter::camelsSnake($typeOrBean);
         $bean = $this->beanHelper->getToolBox()->getRedBean()->dispense($typeOrBean);
         if (is_string($qualification)) {
             $data = json_decode($qualification, TRUE);
         } else {
             $data = $qualification;
         }
         foreach ($data as $key => $value) {
             $bean->{$key} = $value;
         }
     } else {
         $bean = $typeOrBean;
     }
     $list = 'own' . ucfirst($bean->getMeta('type'));
     array_push($this->{$list}, $bean);
     return $bean;
 }
Exemple #4
0
 /**
  * Test camelCase to snake_case conversions.
  * 
  * @return void
  */
 public function testCamel2Snake()
 {
     asrt(AQueryWriter::camelsSnake('bookPage'), 'book_page');
     asrt(AQueryWriter::camelsSnake('FTP'), 'ftp');
     asrt(AQueryWriter::camelsSnake('ACLRules'), 'acl_rules');
     asrt(AQueryWriter::camelsSnake('SSHConnectionProxy'), 'ssh_connection_proxy');
     asrt(AQueryWriter::camelsSnake('proxyServerFacade'), 'proxy_server_facade');
     asrt(AQueryWriter::camelsSnake('proxySSHClient'), 'proxy_ssh_client');
     asrt(AQueryWriter::camelsSnake('objectACL2Factory'), 'object_acl2_factory');
     asrt(AQueryWriter::camelsSnake('bookItems4Page'), 'book_items4_page');
     asrt(AQueryWriter::camelsSnake('book☀Items4Page'), 'book☀_items4_page');
 }