本文整理匯總了PHP中Inflector::get_namespace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::get_namespace方法的具體用法?PHP Inflector::get_namespace怎麽用?PHP Inflector::get_namespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::get_namespace方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: normalize_driver_types
function normalize_driver_types()
{
// get the drivers configured
\Config::load('auth', true);
$drivers = \Config::get('auth.driver', array());
is_array($drivers) or $drivers = array($drivers);
$results = array();
foreach ($drivers as $driver) {
// determine the driver classname
$class = \Inflector::get_namespace($driver) . 'Auth_Login_' . \Str::ucwords(\Inflector::denamespace($driver));
// Auth's Simpleauth
if ($class == 'Auth_Login_Simpleauth' or $class == 'Auth\\Auth_Login_Simpleauth') {
$driver = 'Simpleauth';
} elseif ($class == 'Auth_Login_Ormauth' or $class == 'Auth\\Auth_Login_Ormauth') {
$driver = 'Ormauth';
} elseif (class_exists($class)) {
// Extended fromm Auth's Simpleauth
if (get_parent_class($class) == 'Auth\\Auth_Login_Simpleauth') {
$driver = 'Simpleauth';
} elseif (get_parent_class($class) == 'Auth\\Auth_Login_Ormauth') {
$driver = 'Ormauth';
}
}
// store the normalized driver name
in_array($driver, $results) or $results[] = $driver;
}
return $results;
}
示例2: __construct
public function __construct($from, $name, array $config)
{
$this->name = $name;
$this->model_from = $from;
$this->model_to = array_key_exists('model_to', $config) ? $config['model_to'] : \Inflector::get_namespace($from) . 'Model_' . \Inflector::classify($name);
$this->key_from = array_key_exists('key_from', $config) ? (array) $config['key_from'] : $this->key_from;
$this->key_to = array_key_exists('key_to', $config) ? (array) $config['key_to'] : $this->key_to;
$this->conditions = array_key_exists('conditions', $config) ? (array) $config['conditions'] : array();
if (!empty($config['table_through'])) {
$this->table_through = $config['table_through'];
} else {
$table_name = array($this->model_from, $this->model_to);
natcasesort($table_name);
$table_name = array_merge($table_name);
$this->table_through = \Inflector::tableize($table_name[0]) . '_' . \Inflector::tableize($table_name[1]);
}
$this->key_through_from = !empty($config['key_through_from']) ? (array) $config['key_through_from'] : (array) \Inflector::foreign_key($this->model_from);
$this->key_through_to = !empty($config['key_through_to']) ? (array) $config['key_through_to'] : (array) \Inflector::foreign_key($this->model_to);
$this->cascade_save = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_save;
$this->cascade_delete = array_key_exists('cascade_delete', $config) ? $config['cascade_delete'] : $this->cascade_delete;
if (!class_exists($this->model_to)) {
throw new \FuelException('Related model not found by Many_Many relation "' . $this->name . '": ' . $this->model_to);
}
$this->model_to = get_real_class($this->model_to);
}
示例3: __construct
public function __construct($from, $name, array $config)
{
$this->name = $name;
$this->model_from = $from;
$this->model_to = array_key_exists('model_to', $config) ? $config['model_to'] : \Inflector::get_namespace($from) . 'Model_' . \Inflector::classify($name);
$this->key_from = array_key_exists('key_from', $config) ? (array) $config['key_from'] : $this->key_from;
$this->key_to = array_key_exists('key_to', $config) ? (array) $config['key_to'] : (array) \Inflector::foreign_key($this->model_from);
$this->cascade_save = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_save;
$this->cascade_delete = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_delete;
if (!class_exists($this->model_to)) {
throw new Exception('Related model not found by Has_Many relation "' . $this->name . '": ' . $this->model_to);
}
}
示例4: factory
public static function factory(array $config = array())
{
// default driver id to driver name when not given
!array_key_exists('id', $config) && ($config['id'] = $config['driver']);
$class = \Inflector::get_namespace($config['driver']) . 'Auth_Login_' . ucfirst(\Inflector::denamespace($config['driver']));
$driver = new $class($config);
static::$_instances[$driver->get_id()] = $driver;
foreach ($driver->get_config('drivers', array()) as $type => $drivers) {
foreach ($drivers as $d => $custom) {
$custom = is_int($d) ? array('driver' => $custom) : array_merge($custom, array('driver' => $d));
$class = 'Auth_' . ucfirst($type) . '_Driver';
$class::factory($custom);
}
}
return $driver;
}
示例5: test_get_namespace
/**
* Test for Inflector::get_namespace()
*
* @test
* @dataProvider get_namespace_provider
*/
public function test_get_namespace($class, $namespace)
{
$this->assertEquals(Inflector::get_namespace($class), $namespace);
}
示例6: process
/**
* Takes an entity and works out whether it has a relation to CMF's URL Model. If so,
* it updates the properties of the associated URL object.
*
* @param object $entity
* @param \Doctrine\ORM\EntityManager $em
* @param \Doctrine\ORM\UnitOfWork|null $uow
* @return void
*/
protected function process(&$entity, &$em, &$uow)
{
$entity_class = get_class($entity);
$entity_namespace = trim(\CMF::slug(str_replace('\\', '/', \Inflector::get_namespace($entity_class))), '/');
$metadata = $em->getClassMetadata($entity_class);
// Ignore URL entities themselves
if ($metadata->name == 'CMF\\Model\\URL') {
return;
}
$url_associations = $metadata->getAssociationsByTargetClass('CMF\\Model\\URL');
if (!empty($url_associations)) {
// A bit hacky, but if this is a root tree item don't bother
if (property_exists($entity, 'is_root') && $entity->is_root === true) {
return;
}
$url_field = null;
foreach ($url_associations as $key => $association) {
if ($association['type'] == ClassMetadataInfo::ONE_TO_ONE && $association['orphanRemoval']) {
$url_field = $key;
break;
}
}
if ($url_field == null) {
return;
}
$settings = $entity->settings();
$url_settings = isset($settings[$url_field]) ? $settings[$url_field] : array();
$url_item = $entity->get($url_field);
if ($new_url = is_null($url_item)) {
$url_item = new \CMF\Model\URL();
}
// Don't run if this is an alias...
$alias = $url_item->alias;
if (!is_null($alias) && !empty($alias)) {
return;
}
// Don't run if this is an external link...
if ($url_item->isExternal()) {
return;
}
$prefix = $this->getPrefix($entity);
$slug = '';
if (isset($url_settings['keep_updated']) && !$url_settings['keep_updated']) {
$slug = \CMF::slug($url_item->slug);
} else {
$slug = $entity->urlSlug();
}
$url = $prefix . $slug;
if ($url != '/') {
$url = rtrim($url, '/');
}
$current_url = $url_item->url;
$entity_id = $entity->id;
$url_id = $url_item->get('id');
// Check for duplicates, only if this is an already existing item
if (!empty($entity_id) && !is_null($entity_id)) {
// Set data from the entity if the prefix is null
if (is_null($prefix)) {
$prefix = $this->getPrefix($entity);
$url = $prefix . $slug;
}
// Set data from the entity if the slug is null
if (is_null($slug)) {
$slug = $entity->urlSlug();
$url = $prefix . $slug;
}
// Set it to the item's ID if empty
if (is_null($slug)) {
$slug = $entity_id . "";
$url = $prefix . $slug;
}
$slug_orig = $slug;
$unique = $this->checkUnique($url, $entity_id, $url_id);
$counter = 2;
while (!$unique) {
$slug = $slug_orig . '-' . $counter;
$url = $prefix . $slug;
$unique = $this->checkUnique($url, $entity_id, $url_id);
$counter++;
}
// Add it to the list of saved URLs
$this->savedUrls[$url] = $entity_id;
}
$url_item->set('item_id', $entity->get('id'));
$url_item->set('prefix', $prefix);
$url_item->set('slug', $slug);
$url_item->set('url', $url);
$url_item->set('type', $metadata->name);
$entity->set($url_field, $url_item);
$em->persist($url_item);
// Skip this if the url hasn't changed
//.........這裏部分代碼省略.........
示例7: observe
/**
* Calls all observers for the current event
*
* @param string
*/
public function observe($event)
{
foreach ($this->observers() as $observer => $events) {
if (empty($events) or in_array($event, $events)) {
if (!class_exists($observer)) {
$observer_class = \Inflector::get_namespace($observer) . 'Observer_' . \Inflector::denamespace($observer);
if (!class_exists($observer_class)) {
throw new \UnexpectedValueException($observer);
}
// Add the observer with the full classname for next usage
unset(static::$_observers_cached[$observer]);
static::$_observers_cached[$observer_class] = $events;
$observer = $observer_class;
}
try {
call_user_func(array($observer, 'orm_notify'), $this, $event);
} catch (\Exception $e) {
// Unfreeze before failing
$this->unfreeze();
throw $e;
}
}
}
}
示例8: getModule
/**
* Returns the name of the module the model belongs to. By default, this is the class namespace
* @return string
*/
public static function getModule()
{
$called_class = get_called_class();
if ($called_class::$_module != null) {
return $called_class::$_module;
}
return trim(\Inflector::underscore(str_replace('\\', '/', \Inflector::get_namespace($called_class))), '/');
}