File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -254,4 +254,16 @@ public static function getNodeName($path)
254254 {
255255 return substr ($ path , strrpos ($ path , '/ ' ) + 1 );
256256 }
257+
258+ /**
259+ * Get the depth of the path, ignore trailing slashes, root starts counting at 0
260+ *
261+ * @param string $path a valid absolute path, like /content/jobs/data
262+ *
263+ * @return integer with the path depth
264+ */
265+ public static function getPathDepth ($ path )
266+ {
267+ return substr_count (rtrim ($ path , '/ ' ), '/ ' );
268+ }
257269}
Original file line number Diff line number Diff line change @@ -236,4 +236,11 @@ public function testGetNodeNameRoot()
236236 $ this ->assertEquals ('' , PathHelper::getNodeName ('/ ' ));
237237 }
238238
239+ public function testGetPathDepth ()
240+ {
241+ $ this ->assertEquals (0 , PathHelper::getPathDepth ('/ ' ));
242+ $ this ->assertEquals (1 , PathHelper::getPathDepth ('/foo ' ));
243+ $ this ->assertEquals (2 , PathHelper::getPathDepth ('/foo/bar ' ));
244+ $ this ->assertEquals (2 , PathHelper::getPathDepth ('/foo/bar/ ' ));
245+ }
239246}
You can’t perform that action at this time.
0 commit comments